1
0
forked from moepman/bk-dss

Fix stupid bugs (dict in format).

This commit is contained in:
Markus 2016-03-20 17:17:13 +01:00
parent 60f6671d1d
commit ae02dc4944
2 changed files with 10 additions and 9 deletions

View File

@ -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"

View File

@ -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())