1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

Automatic input first name last name and email with ldap

This commit is contained in:
Info-IIG 2022-06-14 15:41:38 +02:00
parent de2dce7573
commit 32eb91f53f

View file

@ -30,8 +30,11 @@ try:
return None return None
specificUser = connection.response[0] specificUser = connection.response[0]
userDn = str(specificUser.get('raw_dn'),'utf-8') userDn = str(specificUser.get('raw_dn'),'utf-8')
userGivenName = connection.entries[0].givenName
userSn = connection.entries[0].sn
userMail = connection.entries[0].mail
with Connection(server, userDn, password) as con: with Connection(server, userDn, password) as con:
return username return username, userGivenName, userSn, userMail
except Exception as e: except Exception as e:
print("LDAP Exception: {}".format(e)) print("LDAP Exception: {}".format(e))
return None return None
@ -46,10 +49,14 @@ try:
isStaff = False isStaff = False
isTechnician = False isTechnician = False
if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_ADMINS) is None: requeteLdap = self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_ADMINS)
if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_STAFF) is None: if requeteLdap is None:
if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_TECHNICIANS) is None: requeteLdap = self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_STAFF)
if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_USERS) is None: if requeteLdap is None:
requeteLdap = self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_TECHNICIANS)
if requeteLdap is None:
requeteLdap = self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_USERS)
if requeteLdap is None:
print("User does not belong to any search group. Check LDAP_SEARCH_GROUP_FILTER in settings.") print("User does not belong to any search group. Check LDAP_SEARCH_GROUP_FILTER in settings.")
return None return None
else: else:
@ -78,6 +85,9 @@ try:
except User.DoesNotExist: except User.DoesNotExist:
print("authenticate-create new user: {}".format(username)) print("authenticate-create new user: {}".format(username))
user = User(username=username) user = User(username=username)
user.first_name = requeteLdap[1]
user.last_name = requeteLdap[2]
user.email = requeteLdap[3]
user.is_active = True user.is_active = True
user.is_staff = isStaff user.is_staff = isStaff
user.is_superuser = isAdmin user.is_superuser = isAdmin