Handle non-existing users in register_cas_account

This commit is contained in:
Martin Pépin 2020-06-20 17:25:57 +02:00
parent 1fc2a04040
commit 351b084419
No known key found for this signature in database
GPG key ID: E7520278B1774448

View file

@ -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
)