mirror of
https://github.com/moepman/bk-dss
synced 2024-11-17 21:59:11 +01:00
Fix stupid bugs (dict in format).
This commit is contained in:
parent
60f6671d1d
commit
ae02dc4944
@ -16,7 +16,8 @@ CREATE_ATTRS = {
|
|||||||
'loginShell' : '/bin/bash',
|
'loginShell' : '/bin/bash',
|
||||||
'sn' : '{sn}',
|
'sn' : '{sn}',
|
||||||
'uid' : '{user}',
|
'uid' : '{user}',
|
||||||
'uidNumber' : '{uid}'
|
'uidNumber' : '{uid}',
|
||||||
|
'gidNumber' : '1000'
|
||||||
}
|
}
|
||||||
|
|
||||||
REDIS_HOST = "127.0.0.1"
|
REDIS_HOST = "127.0.0.1"
|
||||||
|
16
index.py
16
index.py
@ -3,6 +3,7 @@
|
|||||||
from flask import Flask, render_template, redirect, url_for, session
|
from flask import Flask, render_template, redirect, url_for, session
|
||||||
from flask_wtf import Form
|
from flask_wtf import Form
|
||||||
import ldap
|
import ldap
|
||||||
|
import ldap.modlist
|
||||||
from redis import Redis
|
from redis import Redis
|
||||||
import uuid
|
import uuid
|
||||||
from wtforms.fields import IntegerField, PasswordField, SelectField, StringField, SubmitField
|
from wtforms.fields import IntegerField, PasswordField, SelectField, StringField, SubmitField
|
||||||
@ -84,20 +85,19 @@ def create():
|
|||||||
'gn' : form.gn.data,
|
'gn' : form.gn.data,
|
||||||
'sn' : form.sn.data,
|
'sn' : form.sn.data,
|
||||||
}
|
}
|
||||||
dn = app.config.get('CREATE_DN').format(d)
|
dn = app.config.get('CREATE_DN').format(**d)
|
||||||
attrs = {}
|
attrs = {}
|
||||||
for k,v in app.config.get('CREATE_ATTRS'):
|
for k,v in app.config.get('CREATE_ATTRS').iteritems():
|
||||||
if isinstance(v, string):
|
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(v.format(d))
|
attrs[k].append(e.format(**d))
|
||||||
l.add_s(dn, ldap.modlist.addModlist(attrs))
|
l.add_s(dn, ldap.modlist.addModlist(attrs))
|
||||||
except:
|
except ldap.LDAPError as e:
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
# TODO better message
|
return render_template('error.html', message=e.message['desc'] + ": " + e.message['info'], nav=buildNav())
|
||||||
return render_template('error.html', message="Something went wrong.", nav=buildNav())
|
|
||||||
else:
|
else:
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
return render_template('success.html', message="User successfully created.", nav=buildNav())
|
return render_template('success.html', message="User successfully created.", nav=buildNav())
|
||||||
|
Loading…
Reference in New Issue
Block a user