Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off user social registration in django-allauth?

I noticed looking through the django-allauth templates there's a signup_closed.html users can be redirected to when user registration is closed or disabled. Does anyone who's familiar with that module know if there's a pre-configured setting that can be set in settings.py to turn off new user registration via existing social apps? Or do I need to configure that myself? I've read the full docs for allauth and I don't see any mention of it. Thanks.

like image 526
Chris B. Avatar asked Jul 29 '13 12:07

Chris B.


2 Answers

There is no pre-configured setting but it's easy to make one (this is what I do).

# settings.py

# Point to custom account adapter.
ACCOUNT_ADAPTER = 'myproject.myapp.adapter.CustomAccountAdapter'

# A custom variable we created to tell the CustomAccountAdapter whether to
# allow signups.
ACCOUNT_ALLOW_SIGNUPS = False
# myapp/adapter.py

from django.conf import settings

from allauth.account.adapter import DefaultAccountAdapter


class CustomAccountAdapter(DefaultAccountAdapter):

    def is_open_for_signup(self, request):
        """
        Whether to allow sign ups.
        """
        allow_signups = super(
            CustomAccountAdapter, self).is_open_for_signup(request)
        # Override with setting, otherwise default to super.
        return getattr(settings, 'ACCOUNT_ALLOW_SIGNUPS', allow_signups)

This is flexible, especially if you have multiple environments (e.g. staging) and want to allow user registration in staging before setting it live in production.

like image 86
getup8 Avatar answered Oct 07 '22 02:10

getup8


Looks like you need to override is_open_for_signup on your adapter.

See the code.

like image 44
meshy Avatar answered Oct 07 '22 04:10

meshy