1
0
forked from moepman/bk-dss

Improve error-handling.

This commit is contained in:
Markus 2016-01-31 16:12:35 +01:00
parent 23c88975ca
commit 89b96293ec

View File

@ -23,8 +23,8 @@ class ReadonlyStringField(StringField):
class EditForm(Form): class EditForm(Form):
user = ReadonlyStringField('Username') user = ReadonlyStringField('Username')
pwd1 = PasswordField('Password') pwd1 = PasswordField('New Password')
pwd2 = PasswordField('Password (repeat)') pwd2 = PasswordField('New Password (repeat)')
submit = SubmitField('Submit') submit = SubmitField('Submit')
class LoginForm(Form): class LoginForm(Form):
@ -60,7 +60,6 @@ def edit():
if form.validate_on_submit(): if form.validate_on_submit():
if form.pwd1.data != form.pwd2.data: if form.pwd1.data != form.pwd2.data:
form.pwd1.errors.append("Passwords do not match.")
form.pwd2.errors.append("Passwords do not match.") form.pwd2.errors.append("Passwords do not match.")
else: else:
opwd = rdb.hget(session['uuid'], 'pswd') opwd = rdb.hget(session['uuid'], 'pswd')
@ -70,13 +69,14 @@ def edit():
l.simple_bind_s(user, opwd) l.simple_bind_s(user, opwd)
l.passwd_s(user, opwd, npwd) l.passwd_s(user, opwd, npwd)
except ldap.INVALID_CREDENTIALS as e: except ldap.INVALID_CREDENTIALS as e:
# TODO display error message form.user.errors.append(e.message['desc'])
l.unbind_s() l.unbind_s()
return render_template('edit.html', form=form, nav=nav)
else: else:
# TODO display success message # TODO display success message
rdb.hset(session['uuid'], 'pswd', npwd) rdb.hset(session['uuid'], 'pswd', npwd)
l.unbind_s() l.unbind_s()
return redirect(url_for('index')) return redirect(url_for('index'))
form.user.data = user form.user.data = user
return render_template('edit.html', form=form, nav=nav) return render_template('edit.html', form=form, nav=nav)