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('/')
|
@app.route('/')
|
||||||
def index():
|
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'])
|
@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():
|
||||||
@ -40,7 +47,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)
|
return render_template('login.html', form=form, nav=nav)
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
|
|
||||||
session['uuid'] = str(uuid.uuid4())
|
session['uuid'] = str(uuid.uuid4())
|
||||||
@ -50,12 +57,14 @@ def login():
|
|||||||
rdb.expire(session['uuid'], 3600)
|
rdb.expire(session['uuid'], 3600)
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
return render_template('login.html', form=form)
|
return render_template('login.html', form=form, nav=nav)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
session['uuid'] = None
|
if 'uuid' in session:
|
||||||
|
rdb.delete(session['uuid'])
|
||||||
|
del session['uuid']
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,8 +12,11 @@
|
|||||||
<h1>LDAP User Administration Portal</h1>
|
<h1>LDAP User Administration Portal</h1>
|
||||||
</header>
|
</header>
|
||||||
<nav>
|
<nav>
|
||||||
{% block navigation %}
|
<ul>
|
||||||
{% endblock %}
|
{% for ni in nav %}
|
||||||
|
<li><a href="{{ url_for(ni) }}">{{ ni|capitalize }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -2,8 +2,3 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<p>Hello, World!</p>
|
<p>Hello, World!</p>
|
||||||
{% endblock %}
|
{% 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>
|
<div class="form-group">{{ form.submit(class_="btn btn-default") }}</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block navigation %}
|
|
||||||
<ul>
|
|
||||||
<li><a href="{{ url_for('login') }}">Login</a></li>
|
|
||||||
</ul>
|
|
||||||
{% endblock %}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user