6

Is it possible to prevent account creation under certain circumstances in allauth, preferably using the pre_social_login signal?

pennersr
  • 6,306
  • 1
  • 30
  • 37
user1680104
  • 8,437
  • 4
  • 22
  • 27

1 Answers1

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