Clean cas logins

This commit is contained in:
Martin Pépin 2020-05-17 21:49:32 +02:00
parent e9e8fe8d56
commit 81a6c9e5c5

View file

@ -52,14 +52,18 @@ class ENSCASBackend:
def authenticate(self, request, ticket=None):
cas_client = get_cas_client(request)
uid, attributes, _ = cas_client.verify_ticket(ticket)
cas_login, attributes, _ = cas_client.verify_ticket(ticket)
if not uid:
if cas_login is None:
# Authentication failed
return None
cas_login = self.clean_cas_login(cas_login)
year = get_entrance_year(attributes)
return self._get_or_create(uid, year)
return self._get_or_create(cas_login, year)
def clean_cas_login(self, cas_login):
return cas_login.strip().lower()
def get_free_username(self, cas_login):
"""Find an available username for a new user.