Merge branch 'kerl/clean_username' into 'master'

Normalise les logins CAS

Closes #10

See merge request klub-dev-ens/authens!7
This commit is contained in:
Ludovic Stephan 2020-05-24 22:50:46 +02:00
commit 75fd8f4581

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.