mirror of
https://github.com/moepman/bk-dss
synced 2024-11-01 01:27:05 +01:00
refactore more single character variable names
This commit is contained in:
parent
d827884fbf
commit
70af9f56dd
30
dss.py
30
dss.py
@ -93,7 +93,7 @@ def create():
|
|||||||
ldap_connection = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
ldap_connection = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
||||||
try:
|
try:
|
||||||
ldap_connection.simple_bind_s(rdb.hget(session['uuid'], 'user'), rdb.hget(session['uuid'], 'pswd'))
|
ldap_connection.simple_bind_s(rdb.hget(session['uuid'], 'user'), rdb.hget(session['uuid'], 'pswd'))
|
||||||
d = {
|
user_data = {
|
||||||
'user': form.user.data,
|
'user': form.user.data,
|
||||||
'uid': form.uid.data,
|
'uid': form.uid.data,
|
||||||
'gn': form.gn.data,
|
'gn': form.gn.data,
|
||||||
@ -102,28 +102,28 @@ def create():
|
|||||||
}
|
}
|
||||||
|
|
||||||
# add user
|
# add user
|
||||||
user_dn = app.config.get('USER_DN').format(**d)
|
user_dn = app.config.get('USER_DN').format(**user_data)
|
||||||
attrs = {}
|
attrs = {}
|
||||||
for k, v in app.config.get('USER_ATTRS').items():
|
for key, value in app.config.get('USER_ATTRS').items():
|
||||||
if isinstance(v, str):
|
if isinstance(value, str):
|
||||||
attrs[k] = v.format(**d).encode()
|
attrs[key] = value.format(**user_data).encode()
|
||||||
elif isinstance(v, list):
|
elif isinstance(value, list):
|
||||||
attrs[k] = []
|
attrs[key] = []
|
||||||
for e in v:
|
for element in value:
|
||||||
attrs[k].append(e.format(**d).encode())
|
attrs[key].append(element.format(**user_data).encode())
|
||||||
ldap_connection.add_s(user_dn, ldap.modlist.addModlist(attrs))
|
ldap_connection.add_s(user_dn, ldap.modlist.addModlist(attrs))
|
||||||
|
|
||||||
# add user to group
|
# add user to group
|
||||||
group_dn = app.config.get('GROUP_DN').format(**d)
|
group_dn = app.config.get('GROUP_DN').format(**user_data)
|
||||||
ldap_connection.modify_s(group_dn, [(ldap.MOD_ADD, 'memberUid', str(form.user.data).encode())])
|
ldap_connection.modify_s(group_dn, [(ldap.MOD_ADD, 'memberUid', str(form.user.data).encode())])
|
||||||
|
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as err:
|
||||||
ldap_connection.unbind_s()
|
ldap_connection.unbind_s()
|
||||||
message = "LDAP Error"
|
message = "LDAP Error"
|
||||||
if 'desc' in e.args[0]:
|
if 'desc' in err.args[0]:
|
||||||
message = message + " " + e.args[0]['desc']
|
message = message + " " + err.args[0]['desc']
|
||||||
if 'info' in e.args[0]:
|
if 'info' in err.args[0]:
|
||||||
message = message + ": " + e.args[0]['info']
|
message = message + ": " + err.args[0]['info']
|
||||||
return render_template('error.html', message=message, nav=build_nav())
|
return render_template('error.html', message=message, nav=build_nav())
|
||||||
else:
|
else:
|
||||||
ldap_connection.unbind_s()
|
ldap_connection.unbind_s()
|
||||||
|
Loading…
Reference in New Issue
Block a user