diff --git a/authens/backends.py b/authens/backends.py index 735e435..ccbb7f1 100644 --- a/authens/backends.py +++ b/authens/backends.py @@ -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. diff --git a/authens/signals.py b/authens/signals.py index 4c50aa2..05e8ee7 100644 --- a/authens/signals.py +++ b/authens/signals.py @@ -1,3 +1,3 @@ import django.dispatch -post_cas_create = django.dispatch.Signal() +post_cas_connect = django.dispatch.Signal()