forked from moepman/bk-dss
Add some error messages and improve edit dialog.
This commit is contained in:
parent
60e5380d37
commit
23c88975ca
35
index.py
35
index.py
@ -23,7 +23,8 @@ class ReadonlyStringField(StringField):
|
|||||||
|
|
||||||
class EditForm(Form):
|
class EditForm(Form):
|
||||||
user = ReadonlyStringField('Username')
|
user = ReadonlyStringField('Username')
|
||||||
pswd = PasswordField('Password')
|
pwd1 = PasswordField('Password')
|
||||||
|
pwd2 = PasswordField('Password (repeat)')
|
||||||
submit = SubmitField('Submit')
|
submit = SubmitField('Submit')
|
||||||
|
|
||||||
class LoginForm(Form):
|
class LoginForm(Form):
|
||||||
@ -50,26 +51,32 @@ def index():
|
|||||||
@app.route('/edit', methods=['GET', 'POST'])
|
@app.route('/edit', methods=['GET', 'POST'])
|
||||||
def edit():
|
def edit():
|
||||||
if not isLoggedin():
|
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']
|
nav = ['edit', 'logout']
|
||||||
form = EditForm()
|
form = EditForm()
|
||||||
user = rdb.hget(session['uuid'], 'user')
|
user = rdb.hget(session['uuid'], 'user')
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
opwd = rdb.hget(session['uuid'], 'pswd')
|
if form.pwd1.data != form.pwd2.data:
|
||||||
npwd = form.pswd.data
|
form.pwd1.errors.append("Passwords do not match.")
|
||||||
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
form.pwd2.errors.append("Passwords do not match.")
|
||||||
try:
|
|
||||||
l.simple_bind_s(user, opwd)
|
|
||||||
l.passwd_s(user, opwd, npwd)
|
|
||||||
except ldap.INVALID_CREDENTIALS as e:
|
|
||||||
# TODO display error message
|
|
||||||
l.unbind_s()
|
|
||||||
else:
|
else:
|
||||||
rdb.hset(session['uuid'], 'pswd', pswd)
|
opwd = rdb.hget(session['uuid'], 'pswd')
|
||||||
# TODO display success message
|
npwd = form.pwd1.data
|
||||||
return redirect(url_for('index'))
|
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
||||||
|
try:
|
||||||
|
l.simple_bind_s(user, opwd)
|
||||||
|
l.passwd_s(user, opwd, npwd)
|
||||||
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
|
# TODO display error message
|
||||||
|
l.unbind_s()
|
||||||
|
else:
|
||||||
|
# TODO display success message
|
||||||
|
rdb.hset(session['uuid'], 'pswd', npwd)
|
||||||
|
l.unbind_s()
|
||||||
|
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)
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
<form method="POST">
|
<form method="POST">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ render_field(form.user) }}
|
{{ 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>
|
<div class="form-group">{{ form.submit(class_="btn btn-default") }}</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
4
templates/error.html
Normal file
4
templates/error.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<p>Error: {{ message }}</p>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user