Merge branch 'Evarin/custom_usernames' into 'master'
Donne les attributes à get_free_username See merge request klub-dev-ens/authens!23
This commit is contained in:
commit
ef08eab248
2 changed files with 4 additions and 4 deletions
|
@ -43,7 +43,7 @@ class ENSCASBackend:
|
||||||
def clean_cas_login(self, cas_login):
|
def clean_cas_login(self, cas_login):
|
||||||
return cas_login.strip().lower()
|
return cas_login.strip().lower()
|
||||||
|
|
||||||
def get_free_username(self, cas_login):
|
def get_free_username(self, cas_login, attributes):
|
||||||
"""Find an available username for a new user.
|
"""Find an available username for a new user.
|
||||||
|
|
||||||
If you override this method, make sure it returns a username that is not taken
|
If you override this method, make sure it returns a username that is not taken
|
||||||
|
@ -102,7 +102,7 @@ class ENSCASBackend:
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
username = self.get_free_username(cas_login)
|
username = self.get_free_username(cas_login, attributes)
|
||||||
user = UserModel.objects.create_user(username=username, email=email)
|
user = UserModel.objects.create_user(username=username, email=email)
|
||||||
CASAccount.objects.create(
|
CASAccount.objects.create(
|
||||||
user=user, entrance_year=entrance_year, cas_login=cas_login
|
user=user, entrance_year=entrance_year, cas_login=cas_login
|
||||||
|
|
|
@ -16,11 +16,11 @@ class TestCASBackend(TestCase):
|
||||||
UserModel.objects.create(username="toto2")
|
UserModel.objects.create(username="toto2")
|
||||||
backend = ENSCASBackend()
|
backend = ENSCASBackend()
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
username = backend.get_free_username("toto")
|
username = backend.get_free_username("toto", None)
|
||||||
self.assertFalse(UserModel.objects.filter(username=username).exists())
|
self.assertFalse(UserModel.objects.filter(username=username).exists())
|
||||||
UserModel.objects.create(username=username)
|
UserModel.objects.create(username=username)
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
username = backend.get_free_username("tutu")
|
username = backend.get_free_username("tutu", None)
|
||||||
self.assertFalse(UserModel.objects.filter(username=username).exists())
|
self.assertFalse(UserModel.objects.filter(username=username).exists())
|
||||||
UserModel.objects.create(username=username)
|
UserModel.objects.create(username=username)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue