From 89b96293ec57594c20e0f35cd211b62e2e65410f Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sun, 31 Jan 2016 16:12:35 +0100 Subject: [PATCH] Improve error-handling. --- index.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.py b/index.py index f38de95..bd4bf96 100755 --- a/index.py +++ b/index.py @@ -23,8 +23,8 @@ class ReadonlyStringField(StringField): class EditForm(Form): user = ReadonlyStringField('Username') - pwd1 = PasswordField('Password') - pwd2 = PasswordField('Password (repeat)') + pwd1 = PasswordField('New Password') + pwd2 = PasswordField('New Password (repeat)') submit = SubmitField('Submit') class LoginForm(Form): @@ -60,7 +60,6 @@ def edit(): if form.validate_on_submit(): if form.pwd1.data != form.pwd2.data: - form.pwd1.errors.append("Passwords do not match.") form.pwd2.errors.append("Passwords do not match.") else: opwd = rdb.hget(session['uuid'], 'pswd') @@ -70,13 +69,14 @@ def edit(): l.simple_bind_s(user, opwd) l.passwd_s(user, opwd, npwd) except ldap.INVALID_CREDENTIALS as e: - # TODO display error message + form.user.errors.append(e.message['desc']) l.unbind_s() + return render_template('edit.html', form=form, nav=nav) else: # TODO display success message rdb.hset(session['uuid'], 'pswd', npwd) l.unbind_s() - return redirect(url_for('index')) + return redirect(url_for('index')) form.user.data = user return render_template('edit.html', form=form, nav=nav)