1
0
mirror of https://github.com/moepman/bk-dss synced 2024-12-22 19:34:27 +01:00

Add some error messages and improve edit dialog.

This commit is contained in:
Markus 2015-10-01 17:06:33 +02:00
parent 60e5380d37
commit 23c88975ca
3 changed files with 27 additions and 15 deletions

View File

@ -23,7 +23,8 @@ class ReadonlyStringField(StringField):
class EditForm(Form):
user = ReadonlyStringField('Username')
pswd = PasswordField('Password')
pwd1 = PasswordField('Password')
pwd2 = PasswordField('Password (repeat)')
submit = SubmitField('Submit')
class LoginForm(Form):
@ -50,15 +51,20 @@ def index():
@app.route('/edit', methods=['GET', 'POST'])
def edit():
if not isLoggedin():
return redirect(url_for('index'))
nav = ['login']
return render_template('error.html', message="You are not logged in. Please log in first.", nav=nav)
nav = ['edit', 'logout']
form = EditForm()
user = rdb.hget(session['uuid'], 'user')
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')
npwd = form.pswd.data
npwd = form.pwd1.data
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
try:
l.simple_bind_s(user, opwd)
@ -67,8 +73,9 @@ def edit():
# TODO display error message
l.unbind_s()
else:
rdb.hset(session['uuid'], 'pswd', pswd)
# TODO display success message
rdb.hset(session['uuid'], 'pswd', npwd)
l.unbind_s()
return redirect(url_for('index'))
form.user.data = user

View File

@ -4,7 +4,8 @@
<form method="POST">
{{ form.hidden_tag() }}
{{ render_field(form.user) }}
{{ render_field(form.pswd) }}
{{ render_field(form.pwd1) }}
{{ render_field(form.pwd2) }}
<div class="form-group">{{ form.submit(class_="btn btn-default") }}</div>
</form>
{% endblock %}

4
templates/error.html Normal file
View File

@ -0,0 +1,4 @@
{% extends "base.html" %}
{% block content %}
<p>Error: {{ message }}</p>
{% endblock %}