This commit is contained in:
parent
1de1cb4086
commit
b386525e0c
10 changed files with 51 additions and 15 deletions
|
|
@ -2,7 +2,9 @@
|
|||
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from allauth.account.models import EmailAddress
|
||||
from allauth.socialaccount.signals import pre_social_login
|
||||
from django.conf import settings
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
||||
|
|
@ -19,11 +21,19 @@ def sync_user_fields(sender, request, sociallogin, **kwargs):
|
|||
if email and user.email != email:
|
||||
user.email = email
|
||||
changed = True
|
||||
EmailAddress.objects.filter(user=user).update(email=email)
|
||||
|
||||
username = data.get("username")
|
||||
username = data.get("preferred_username")
|
||||
if username and user.username != username:
|
||||
user.username = username
|
||||
changed = True
|
||||
|
||||
admin_group = settings.OAUTH_ADMIN_GROUP
|
||||
if admin_group:
|
||||
is_staff = admin_group in data.get("groups", [])
|
||||
if user.is_staff != is_staff:
|
||||
user.is_staff = is_staff
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
user.save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue