From b75552b0b349d1161ff37a0aea077a8e776ff604 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Wed, 17 Jun 2015 20:34:30 +0200 Subject: [PATCH] Working login/logout. Generate navigation based on login status. --- index.py | 17 +++++++++++++---- templates/base.html | 7 +++++-- templates/index.html | 5 ----- templates/login.html | 5 ----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/index.py b/index.py index e86ab8d..8479d02 100755 --- a/index.py +++ b/index.py @@ -24,11 +24,18 @@ class LoginForm(Form): @app.route('/') def index(): - return render_template('index.html') + nav = None + if 'uuid' in session: + nav = ['logout'] + else: + nav = ['login'] + + return render_template('index.html', nav=nav) @app.route('/login', methods=['GET', 'POST']) def login(): + nav = ['login'] form = LoginForm() if form.validate_on_submit(): @@ -40,7 +47,7 @@ def login(): except ldap.INVALID_CREDENTIALS as e: form.pswd.errors.append(e.message['desc']) l.unbind_s() - return render_template('login.html', form=form) + return render_template('login.html', form=form, nav=nav) l.unbind_s() session['uuid'] = str(uuid.uuid4()) @@ -50,12 +57,14 @@ def login(): rdb.expire(session['uuid'], 3600) return redirect(url_for('index')) - return render_template('login.html', form=form) + return render_template('login.html', form=form, nav=nav) @app.route('/logout') def logout(): - session['uuid'] = None + if 'uuid' in session: + rdb.delete(session['uuid']) + del session['uuid'] return redirect(url_for('index')) diff --git a/templates/base.html b/templates/base.html index 43d0b81..1a00afb 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,8 +12,11 @@

LDAP User Administration Portal

{% block content %} diff --git a/templates/index.html b/templates/index.html index 86329a5..951f86b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,8 +2,3 @@ {% block content %}

Hello, World!

{% endblock %} -{% block navigation %} - -{% endblock %} diff --git a/templates/login.html b/templates/login.html index 3b099e3..45f86e1 100644 --- a/templates/login.html +++ b/templates/login.html @@ -8,8 +8,3 @@
{{ form.submit(class_="btn btn-default") }}
{% endblock %} -{% block navigation %} - -{% endblock %}