From 47e51d2451552dfe472fc8f2209458100e79b506 Mon Sep 17 00:00:00 2001 From: kakwa Date: Mon, 15 Jun 2015 21:30:19 +0200 Subject: [PATCH] implementing basic add of users --- ldapcherry/__init__.py | 23 +++++++++++++++++++++++ ldapcherry/attributes.py | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index c1514db..5968a3a 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -401,6 +401,24 @@ class LdapCherry(object): ) raise cherrypy.HTTPRedirect("/signin") + def _adduser(self, params): + badd = {} + for attr in self.attributes.get_attributes(): + if self.attributes.attributes[attr]['type'] == 'password': + pwd1 = attr + '1' + pwd2 = attr + '2' + if params[pwd1] != params[pwd2]: + raise Exception() + params[attr] = params[pwd1] + if attr in params: + backends = self.attributes.get_backends_attributes(attr) + for b in backends: + if not b in badd: + badd[b] = {} + badd[b][backends[b]] = params[attr] + for b in badd: + self.backends[b].add_user(badd[b]) + @cherrypy.expose def logout(self): """ logout page @@ -460,6 +478,11 @@ class LdapCherry(object): if cherrypy.request.method.upper() == 'POST': notification = "" + cherrypy.log.error( + msg = params , + severity = logging.DEBUG + ) + self._adduser(params) else: notification = '' diff --git a/ldapcherry/attributes.py b/ldapcherry/attributes.py index ae5913e..860cae9 100644 --- a/ldapcherry/attributes.py +++ b/ldapcherry/attributes.py @@ -87,4 +87,7 @@ class Attributes: def get_attributes(self): """get the list of groups from roles""" - return self.self_attributes + return self.attributes.keys() + + def get_backends_attributes(self, attribute): + return self.attributes[attribute]['backends']