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.
This commit is contained in:
Benjamin Dauvergne 2014-08-19 14:59:25 +02:00
parent 7711717ace
commit b2ee01b583
1 changed files with 3 additions and 9 deletions

View File

@ -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()