Plus simple et utile : un signal post-connexion global
This commit is contained in:
parent
97f00278f9
commit
95931792a5
2 changed files with 9 additions and 5 deletions
|
@ -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.
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import django.dispatch
|
||||
|
||||
post_cas_create = django.dispatch.Signal()
|
||||
post_cas_connect = django.dispatch.Signal()
|
||||
|
|
Loading…
Reference in a new issue