From 504a1e4704b96cbe492300a38f0ab44850c3849c Mon Sep 17 00:00:00 2001 From: Qwann Date: Mon, 19 Mar 2018 18:22:09 +0100 Subject: [PATCH] only clipper can autosign-up --- WikiENS/settings.py | 3 +++ shared/allauth_adapter.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 shared/allauth_adapter.py diff --git a/WikiENS/settings.py b/WikiENS/settings.py index 9c9fa74..25a083a 100644 --- a/WikiENS/settings.py +++ b/WikiENS/settings.py @@ -161,6 +161,9 @@ AUTHENTICATION_BACKENDS = [ 'allauth.account.auth_backends.AuthenticationBackend', ] +ACCOUNT_ADAPTER = 'shared.allauth_adapter.AccountAdapter' +SOCIALACCOUNT_ADAPTER = 'shared.allauth_adapter.SocialAccountAdapter' + HOME_URL = reverse_lazy('wiki:root') LOGIN_URL = '_profil/login/' diff --git a/shared/allauth_adapter.py b/shared/allauth_adapter.py new file mode 100644 index 0000000..d8c8847 --- /dev/null +++ b/shared/allauth_adapter.py @@ -0,0 +1,20 @@ +from allauth.account.adapter import DefaultAccountAdapter +from allauth.socialaccount.adapter import DefaultSocialAccountAdapter + + +class AccountAdapter(DefaultAccountAdapter): + def is_open_for_signup(self, request): + return False + + +class SocialAccountAdapter(DefaultSocialAccountAdapter): + def is_open_for_signup(self, request, sociallogin): + # sociallogin.account is a SocialAccount instance. + # See https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py + + if sociallogin.account.provider == 'clipper': + return True + + # It returns AccountAdapter.is_open_for_signup(). + # See https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/adapter.py + return super().is_open_for_signup(request, sociallogin)