29 lines
767 B
Python
29 lines
767 B
Python
# This file is part of photo21
|
|
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from allauth.socialaccount.signals import pre_social_login
|
|
from django.dispatch import receiver
|
|
|
|
|
|
@receiver(pre_social_login)
|
|
def sync_user_fields(sender, request, sociallogin, **kwargs):
|
|
if not sociallogin.is_existing:
|
|
return
|
|
|
|
user = sociallogin.user
|
|
data = sociallogin.account.extra_data
|
|
changed = False
|
|
|
|
email = data.get("email")
|
|
if email and user.email != email:
|
|
user.email = email
|
|
changed = True
|
|
|
|
username = data.get("username")
|
|
if username and user.username != username:
|
|
user.username = username
|
|
changed = True
|
|
|
|
if changed:
|
|
user.save()
|