diff --git a/authens/shortcuts.py b/authens/shortcuts.py index a4f5e1c..8a8dd97 100644 --- a/authens/shortcuts.py +++ b/authens/shortcuts.py @@ -59,7 +59,11 @@ def register_cas_account(user: User, cas_login: str) -> CASAccount: if OldCASAccount.objects.filter(user=user).exists(): raise ValueError("User '{}' has an old CAS account".format(user)) - entrance_year = fetch_cas_account(cas_login)["entrance_year"] + ldap_info = fetch_cas_account(cas_login) + if ldap_info is None: + raise ValueError("There is no LDAP user for id '{}'".format(cas_login)) + + entrance_year = ldap_info["entrance_year"] return CASAccount.objects.create( user=user, cas_login=cas_login, entrance_year=entrance_year )