From b2ee01b583c63b2bebc8dfea88f5e9189d8341d1 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 19 Aug 2014 14:59:25 +0200 Subject: [PATCH] Check if user should get admin role on all logins, not just the first one (fixes #5290) The user object in sociallogin.account.user is not the final user object that's gonna be logged in, so the admin flags should be set in the pre_social_login signal handler if we want them to be saved in the real user object. --- portail_citoyen2/allauth_authentic2/provider.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/portail_citoyen2/allauth_authentic2/provider.py b/portail_citoyen2/allauth_authentic2/provider.py index a99e082..a5e42fc 100644 --- a/portail_citoyen2/allauth_authentic2/provider.py +++ b/portail_citoyen2/allauth_authentic2/provider.py @@ -37,15 +37,6 @@ class Authentic2Provider(OAuth2Provider): primary=True)] return ret - def sociallogin_from_response(self, request, response): - sociallogin = super(Authentic2Provider, self).sociallogin_from_response( - request, response) - if app_settings.ADMIN_ROLE in response.get('role', []): - log.debug('giving admin role to user') - sociallogin.account.user.is_superuser = True - sociallogin.account.user.is_staff = True - return sociallogin - providers.registry.register(Authentic2Provider) @@ -61,5 +52,8 @@ def pre_social_login_populate_user(sender, request, sociallogin, **kwargs): user.first_name = data['first_name'] if 'last_name' in data: user.last_name = data['last_name'] + if app_settings.ADMIN_ROLE in data.get('role', []): + user.is_superuser = True + user.is_staff = True if user.id: user.save()