mirror of
https://github.com/moepman/bk-dss
synced 2024-12-22 17:24:25 +01:00
Working login/logout. Generate navigation based on login status.
This commit is contained in:
parent
d40dd533a4
commit
b75552b0b3
17
index.py
17
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'))
|
||||
|
||||
|
||||
|
@ -12,8 +12,11 @@
|
||||
<h1>LDAP User Administration Portal</h1>
|
||||
</header>
|
||||
<nav>
|
||||
{% block navigation %}
|
||||
{% endblock %}
|
||||
<ul>
|
||||
{% for ni in nav %}
|
||||
<li><a href="{{ url_for(ni) }}">{{ ni|capitalize }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</nav>
|
||||
<main>
|
||||
{% block content %}
|
||||
|
@ -2,8 +2,3 @@
|
||||
{% block content %}
|
||||
<p>Hello, World!</p>
|
||||
{% endblock %}
|
||||
{% block navigation %}
|
||||
<ul>
|
||||
<li><a href="{{ url_for('login') }}">Login</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
@ -8,8 +8,3 @@
|
||||
<div class="form-group">{{ form.submit(class_="btn btn-default") }}</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% block navigation %}
|
||||
<ul>
|
||||
<li><a href="{{ url_for('login') }}">Login</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user