Commit e3f619d4 authored by Recteur LP's avatar Recteur LP

add auth method

parent ddcc453c
......@@ -120,6 +120,31 @@ class auth():
})
return users
def auth(self, name, password):
user_dn = self.get(name)['dn']
pyrmin.log.debug("trying DN: {}".format(user_dn))
if sys.version_info >= (3, 0):
Connection(
Server(
self.config['server'],
port=int(self.config['port']),
use_ssl=self.config['ssl']
),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True,
user=user_dn,
password=password
)
return True
else:
ld = ldap.initialize('ldap://' + self.config['server'] + ':' + str(self.config['port']))
ld.protocol_version = self.config['version']
ld.set_option(ldap.OPT_REFERRALS, 0)
ld.simple_bind_s(user_dn, password)
ld.unbind_s()
return True
def get(self, name):
pyrmin.log.debug("Trying to get: " + name)
if sys.version_info >= (3, 0):
......@@ -135,6 +160,7 @@ class auth():
division = attrs.get('division', ['Guest'])[0]
displayname = attrs.get(self.config['user_displayname'], ['Guest'])[0]
company = attrs.get('company', [''])[0]
dn = attrs.get("entryDN", name)[0]
isadmin = False
admins = []
......@@ -155,7 +181,8 @@ class auth():
"mobile": attrs.get('otherMobile', [''])[0],
"company": company,
"mail": mail,
"img": gravatar_url
"img": gravatar_url,
"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