feat(dgsi/account): Update the e-mail address at login
This commit is contained in:
parent
1763b60ed5
commit
1ad35c7033
1 changed files with 7 additions and 0 deletions
|
@ -12,6 +12,7 @@ from django.urls import reverse
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from dgsi.models import Translation, User
|
||||
from shared.kanidm import sync_call
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -95,6 +96,12 @@ class SharedAccountAdapter(DefaultSocialAccountAdapter):
|
|||
u.is_superuser = u.part_of(settings.DGSI_SUPERUSER_GROUP)
|
||||
u.is_staff = u.is_superuser or u.part_of(settings.DGSI_STAFF_GROUP)
|
||||
|
||||
# Update the e-mail address if possible
|
||||
if u.kanidm is not None:
|
||||
emails = sync_call("call_get", f"/v1/person/{u.username}/_attr/mail")
|
||||
if emails != []:
|
||||
u.email = emails[0]
|
||||
|
||||
# Save the updated user if needed
|
||||
if sociallogin.is_existing:
|
||||
u.save()
|
||||
|
|
Loading…
Add table
Reference in a new issue