Commit 33d6d812 authored by Recteur LP's avatar Recteur LP

Check if ldap attr is a list

parent 1bba8091
......@@ -146,6 +146,12 @@ class auth():
ld.unbind_s()
return True
def _to_string(self, lst):
if isinstance(lst, list):
return lst[0]
else:
return lst
def get(self, name):
pyrmin.log.debug("Trying to get: " + name)
if sys.version_info >= (3, 0):
......@@ -153,15 +159,15 @@ class auth():
for entry in self.__getresults(filter):
if "attributes" in entry:
attrs = entry['attributes']
name = attrs.get(self.config['user_id'], ['Guest'])[0]
mail = str(attrs.get('mail')[0]).lower()
name = self._to_string(attrs.get(self.config['user_id'], ['Guest']))
mail = str(self._to_string(attrs.get('mail'))).lower()
gravatar_url = "https://www.gravatar.com/avatar/" + \
hashlib.md5(mail.encode('utf-8')).hexdigest() + "?"
gravatar_url += urllib.parse.urlencode({'d': "identicon", 's': str(50)})
division = attrs.get('division', ['Guest'])[0]
displayname = attrs.get(self.config['user_displayname'], ['Guest'])[0]
company = attrs.get('company', [''])[0]
dn = attrs.get("entryDN", [entry.get("dn")])[0]
division = self._to_string(attrs.get('division', 'Guest'))
displayname = self._to_string(attrs.get(self.config['user_displayname'], 'Guest'))
company = self._to_string(attrs.get('company', ''))
dn = self._to_string(attrs.get("entryDN", entry.get("dn")))
isadmin = False
admins = []
......@@ -182,11 +188,11 @@ class auth():
"admin": isadmin,
"division": division,
"displayname": displayname,
"mobile": attrs.get('otherMobile', [''])[0],
"mobile": self._to_string(attrs.get('otherMobile', [''])),
"company": company,
"mail": mail,
"img": gravatar_url,
"dn" : dn
"dn": dn
}
else:
filter = "(&(" + self.config['user_id'] + "=" + name + ")(!(objectClass=computer)))"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment