Is it possible to prevent account creation under certain circumstances in allauth, preferably using the pre_social_login signal?
Asked
Active
Viewed 1,990 times
1 Answers
10
With the current development branch you can easily do this. In your settings:
SOCIALACCOUNT_ADAPTER = 'my.adapter.MySocialAccountAdapter'
Then use this adapter.py:
from django.http import HttpResponse
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from allauth.exceptions import ImmediateHttpResponse
class MySocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
raise ImmediateHttpResponse(HttpResponse('Closed for the day'))
Alternatively, raise a similar exception from your pre_social_login
signal (although I do not prefer that approach -- see documentation notes over at https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/adapter.py#L15

pennersr
- 6,306
- 1
- 30
- 37
-
But this would change the adapter for all the Social Providers, can I use some setting like ``MY_SOCIAL_ SOCIALACCOUNT_ADAPTER`` for MySocialProvider? – Kane Blueriver May 25 '16 at 04:16
-
You can inspect `sociallogin.account.provider`, and selectively raise the exception based on the type of provider. – pennersr May 26 '16 at 17:28
-
It would be cumbersome when I have a lot of providers to deal with distinctly. Configure them separately would be more neat I think. – Kane Blueriver May 27 '16 at 04:48