Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent social account creation in allauth

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

like image 769
user1680104 Avatar asked Nov 30 '12 14:11

user1680104


1 Answers

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

like image 124
pennersr Avatar answered Nov 17 '22 22:11

pennersr