mirror of
https://github.com/moepman/bk-dss
synced 2024-12-22 23:04:26 +01:00
Implement password changing and configurable session timeout.
This commit is contained in:
parent
6705ce83cc
commit
33e5432c5e
@ -1,5 +1,6 @@
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
SECRET_KEY = "CHANGE!ME"
|
SECRET_KEY = "CHANGE!ME"
|
||||||
|
SESSION_TIMEOUT = 3600
|
||||||
|
|
||||||
LDAP_URI = "ldaps://ldap.example.com"
|
LDAP_URI = "ldaps://ldap.example.com"
|
||||||
LDAP_BASE = "ou=people,dc=example,dc=com"
|
LDAP_BASE = "ou=people,dc=example,dc=com"
|
||||||
|
23
index.py
23
index.py
@ -50,10 +50,27 @@ def edit():
|
|||||||
|
|
||||||
nav = ['edit', 'logout']
|
nav = ['edit', 'logout']
|
||||||
form = EditForm()
|
form = EditForm()
|
||||||
user = rdb.hgetall(session['uuid'])['user']
|
user = rdb.hget(session['uuid'], 'user')
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
opwd = rdb.hget(session['uuid'], 'pswd')
|
||||||
|
pswd = form.pswd.data
|
||||||
|
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, pswd)
|
||||||
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
|
# TODO error message
|
||||||
|
l.unbind_s()
|
||||||
|
else:
|
||||||
|
rdb.hset(session'uuid'], 'pswd', pswd)
|
||||||
|
# TODO show a success message
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
nav = ['login']
|
nav = ['login']
|
||||||
@ -74,8 +91,8 @@ def login():
|
|||||||
session['uuid'] = str(uuid.uuid4())
|
session['uuid'] = str(uuid.uuid4())
|
||||||
credentials = { 'user': user, 'pswd': pswd }
|
credentials = { 'user': user, 'pswd': pswd }
|
||||||
rdb.hmset(session['uuid'], credentials)
|
rdb.hmset(session['uuid'], credentials)
|
||||||
# TODO refactor this are reuse, make session timeout a config variable
|
# TODO refactor this and reuse
|
||||||
rdb.expire(session['uuid'], 3600)
|
rdb.expire(session['uuid'], app.config.get('SESSION_TIMEOUT', 3600))
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
return render_template('login.html', form=form, nav=nav)
|
return render_template('login.html', form=form, nav=nav)
|
||||||
|
Loading…
Reference in New Issue
Block a user