forked from moepman/bk-dss
Fix user creation.
This commit is contained in:
parent
be26efa343
commit
dc2afe0e2a
@ -5,11 +5,11 @@ SESSION_TIMEOUT = 3600
|
|||||||
LDAP_URI = "ldaps://ldap.example.com"
|
LDAP_URI = "ldaps://ldap.example.com"
|
||||||
LDAP_BASE = "dc=example,dc=com"
|
LDAP_BASE = "dc=example,dc=com"
|
||||||
|
|
||||||
USER_DN = "cn={user},ou=people,dc=example,dc=com"
|
|
||||||
|
|
||||||
ADMINS = [ "cn=admin,ou=people,dc=example,dc=com" ]
|
ADMINS = [ "cn=admin,ou=people,dc=example,dc=com" ]
|
||||||
|
|
||||||
CREATE_ATTRS = {
|
USER_DN = "cn={user},ou=people,dc=example,dc=com"
|
||||||
|
|
||||||
|
USER_ATTRS = {
|
||||||
'objectClass' : ['top', 'inetOrgPerson', 'organizationalPerson', 'person', 'posixAccount'],
|
'objectClass' : ['top', 'inetOrgPerson', 'organizationalPerson', 'person', 'posixAccount'],
|
||||||
'cn' : '{user}',
|
'cn' : '{user}',
|
||||||
'givenName' : '{gn}',
|
'givenName' : '{gn}',
|
||||||
@ -21,5 +21,7 @@ CREATE_ATTRS = {
|
|||||||
'gidNumber' : '1000'
|
'gidNumber' : '1000'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GROUP_DN = 'cn=user,ou=Groups,dc=binary-kitchen,dc=de'
|
||||||
|
|
||||||
REDIS_HOST = "127.0.0.1"
|
REDIS_HOST = "127.0.0.1"
|
||||||
REDIS_PSWD = "foobared"
|
REDIS_PSWD = "foobared"
|
||||||
|
15
index.py
15
index.py
@ -85,16 +85,23 @@ def create():
|
|||||||
'gn' : form.gn.data,
|
'gn' : form.gn.data,
|
||||||
'sn' : form.sn.data,
|
'sn' : form.sn.data,
|
||||||
}
|
}
|
||||||
dn = app.config.get('USER_DN').format(**d)
|
|
||||||
|
# add user
|
||||||
|
user_dn = app.config.get('USER_DN').format(**d)
|
||||||
attrs = {}
|
attrs = {}
|
||||||
for k,v in app.config.get('CREATE_ATTRS').iteritems():
|
for k,v in app.config.get('USER_ATTRS').iteritems():
|
||||||
if type(v) == str:
|
if type(v) == str:
|
||||||
attrs[k] = v.format(**d)
|
attrs[k] = v.format(**d)
|
||||||
elif isinstance(v, list):
|
elif isinstance(v, list):
|
||||||
attrs[k] = []
|
attrs[k] = []
|
||||||
for e in v:
|
for e in v:
|
||||||
attrs[k].append(e.format(**d))
|
attrs[k].append(e.format(**d))
|
||||||
l.add_s(dn, ldap.modlist.addModlist(attrs))
|
l.add_s(user_dn, ldap.modlist.addModlist(attrs))
|
||||||
|
|
||||||
|
# add user to group
|
||||||
|
group_dn = app.config.get('GROUP_DN').format(**d)
|
||||||
|
l.modify_s(group_dn, [(ldap.MOD_ADD, 'memberUid', str(form.user.data))])
|
||||||
|
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as e:
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
return render_template('error.html', message=e.message['desc'] + ": " + e.message['info'], nav=buildNav())
|
return render_template('error.html', message=e.message['desc'] + ": " + e.message['info'], nav=buildNav())
|
||||||
@ -138,7 +145,7 @@ def login():
|
|||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = ""
|
user = ""
|
||||||
if form.user.data.endswith(app.config.get('LDAP_BASE','')):
|
if form.user.data.endswith(app.config.get('LDAP_BASE','')):
|
||||||
user = form.user.data
|
user = form.user.data
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user