2021-02-07 18:23:24 +01:00
|
|
|
from authens.backends import ENSCASBackend as AuthENSBackend
|
|
|
|
from authens.utils import parse_entrance_year
|
2017-04-27 02:38:08 +02:00
|
|
|
|
2021-02-07 23:15:47 +01:00
|
|
|
|
2021-02-07 18:23:24 +01:00
|
|
|
class ENSCASBackend(AuthENSBackend):
|
|
|
|
# Override AuthENS backend user creation to implement the @<promo> logic
|
2021-02-07 23:15:47 +01:00
|
|
|
|
2021-02-07 18:23:24 +01:00
|
|
|
def get_free_username(self, cas_login, attributes):
|
|
|
|
entrance_year = parse_entrance_year(attributes.get("homeDirectory"))
|
|
|
|
if entrance_year is None:
|
|
|
|
return super().get_free_username(cas_login, attributes)
|
|
|
|
entrance_year %= 100
|
|
|
|
return "%s@%02d" % (cas_login, entrance_year)
|