mirror of
https://github.com/moepman/bk-dss
synced 2024-11-04 21:27:05 +01:00
Add some error messages and improve edit dialog.
This commit is contained in:
parent
60e5380d37
commit
23c88975ca
15
index.py
15
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,15 +51,20 @@ 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():
|
||||||
|
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')
|
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'))
|
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
||||||
try:
|
try:
|
||||||
l.simple_bind_s(user, opwd)
|
l.simple_bind_s(user, opwd)
|
||||||
@ -67,8 +73,9 @@ def edit():
|
|||||||
# TODO display error message
|
# TODO display error message
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
else:
|
else:
|
||||||
rdb.hset(session['uuid'], 'pswd', pswd)
|
|
||||||
# TODO display success message
|
# 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
|
form.user.data = user
|
||||||
|
@ -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