1
0
mirror of https://github.com/moepman/bk-dss synced 2024-11-18 00:19:11 +01:00

Refactor navigation.

This commit is contained in:
Markus 2016-02-10 17:00:40 +01:00
parent 516b448422
commit 4fff031fc4

View File

@ -6,7 +6,7 @@ import ldap
from redis import Redis from redis import Redis
import uuid import uuid
from wtforms.fields import PasswordField, SelectField, StringField, SubmitField from wtforms.fields import PasswordField, SelectField, StringField, SubmitField
from wtforms.validators import Required from wtforms.validators import EqualTo, Required
app = Flask(__name__) app = Flask(__name__)
app.config.from_pyfile('config.cfg') app.config.from_pyfile('config.cfg')
@ -37,24 +37,27 @@ def isLoggedin():
return 'uuid' in session and rdb.exists(session['uuid']) return 'uuid' in session and rdb.exists(session['uuid'])
def buildNav():
nav = []
if isLoggedin():
nav.append('edit')
nav.append('logout')
else:
nav.append('login')
return nav
@app.route('/') @app.route('/')
def index(): def index():
nav = None
if isLoggedin():
nav = ['edit', 'logout']
else:
nav = ['login']
return render_template('index.html', nav=nav) return render_template('index.html', nav=buildNav())
@app.route('/edit', methods=['GET', 'POST']) @app.route('/edit', methods=['GET', 'POST'])
def edit(): def edit():
if not isLoggedin(): if not isLoggedin():
nav = ['login'] return render_template('error.html', message="You are not logged in. Please log in first.", nav=buildNav())
return render_template('error.html', message="You are not logged in. Please log in first.", nav=nav)
nav = ['edit', 'logout']
form = EditForm() form = EditForm()
user = rdb.hget(session['uuid'], 'user') user = rdb.hget(session['uuid'], 'user')
@ -68,7 +71,7 @@ def edit():
except ldap.INVALID_CREDENTIALS as e: except ldap.INVALID_CREDENTIALS as e:
form.user.errors.append(e.message['desc']) form.user.errors.append(e.message['desc'])
l.unbind_s() l.unbind_s()
return render_template('edit.html', form=form, nav=nav) return render_template('edit.html', form=form, nav=buildNav())
else: else:
# TODO display success message # TODO display success message
rdb.hset(session['uuid'], 'pswd', npwd) rdb.hset(session['uuid'], 'pswd', npwd)
@ -76,12 +79,11 @@ def edit():
return redirect(url_for('index')) 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=buildNav())
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
def login(): def login():
nav = ['login']
form = LoginForm() form = LoginForm()
if form.validate_on_submit(): if form.validate_on_submit():
@ -93,7 +95,7 @@ def login():
except ldap.INVALID_CREDENTIALS as e: except ldap.INVALID_CREDENTIALS as e:
form.pswd.errors.append(e.message['desc']) form.pswd.errors.append(e.message['desc'])
l.unbind_s() l.unbind_s()
return render_template('login.html', form=form, nav=nav) return render_template('login.html', form=form, nav=buildNav())
l.unbind_s() l.unbind_s()
session['uuid'] = str(uuid.uuid4()) session['uuid'] = str(uuid.uuid4())
@ -103,7 +105,7 @@ def login():
rdb.expire(session['uuid'], app.config.get('SESSION_TIMEOUT', 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=buildNav())
@app.route('/logout') @app.route('/logout')