Plus simple et utile : un signal post-connexion global

This commit is contained in:
Robin Champenois 2021-01-17 23:39:19 +01:00
parent 97f00278f9
commit 95931792a5
2 changed files with 9 additions and 5 deletions

View file

@ -3,7 +3,7 @@ from django.db import transaction
from authens.models import CASAccount, OldCASAccount
from authens.utils import get_cas_client, parse_entrance_year
from authens.signals import post_cas_create
from authens.signals import post_cas_connect
UserModel = get_user_model()
@ -88,6 +88,7 @@ class ENSCASBackend:
if entrance_year is None:
raise ENSCASError("Entrance year not available")
account_created = False
with transaction.atomic():
try:
user = UserModel.objects.get(cas_account__cas_login=cas_login)
@ -108,9 +109,12 @@ class ENSCASBackend:
CASAccount.objects.create(
user=user, entrance_year=entrance_year, cas_login=cas_login
)
post_cas_create.send(
CASAccount, cas_login=cas_login, attributes=attributes
)
account_created = True
post_cas_connect.send(
UserModel, instance=user, created=account_created, cas_login=cas_login,
attributes=attributes
)
return user
# Django boilerplate.

View file

@ -1,3 +1,3 @@
import django.dispatch
post_cas_create = django.dispatch.Signal()
post_cas_connect = django.dispatch.Signal()