Merge pull request #1840 from modoboa/fix/ldap_login_with_simple_username

Allow login with username instead of email for LDAP.
This commit is contained in:
Antoine Nguyen
2020-02-17 16:58:09 +01:00
committed by GitHub
2 changed files with 11 additions and 5 deletions
+2 -4
View File
@@ -107,11 +107,9 @@ class LDAPAuthenticationTestCase(LDAPTestCaseMixin, ModoTestCase):
self.client.logout()
self.directbind_mode()
# 1: must fail because usernames of simple users must be email
# addresses
username = "testuser"
with self.assertRaises(TypeError):
self.client.login(username=username, password="test")
self.client.login(username=username, password="test")
self.check_created_user(username + "@example.com")
# 1: must work because usernames of domain admins are not
# always email addresses
+9 -1
View File
@@ -87,7 +87,15 @@ try:
if group == "SimpleUsers":
lpart, domain = split_mailbox(username)
if domain is None:
return None
# Try to find associated email
email = None
for attr in ['mail', 'userPrincipalName']:
if attr in ldap_user.attrs:
email = ldap_user.attrs[attr][0]
break
if email is None:
return None
username = email
user, created = User.objects.get_or_create(
username__iexact=username,
defaults={