Commit c8209fbc authored by Julian Rother's avatar Julian Rother
Browse files

Extended login and added login_required decorator

parent 56e1dfcb
from flask import *
from functools import wraps
import sqlite3
import os
import re
......@@ -109,6 +110,16 @@ def ldapget(user):
return notldap[user][2]
def login_required(func):
def decorator(*args, **kwargs):
if not 'user' in session:
flash('Diese Funktion ist nur für Moderatoren verfügbar!')
return redirect(url_for('login', ref=request.url))
return func(*args, **kwargs)
return decorator
def index():
return render_template('index.html', latestvideos=query('''
......@@ -172,8 +183,10 @@ def course():
return redirect(url_for('index'))
@app.route('/login', methods=['POST'])
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
user, groups = ldapauth(request.form.get('user'), request.form.get('password'))
if user and 'users' in groups:
session['user'] = ldapget(user)
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-xs-offset-1 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Login für Moderatoren</h1>
<div class="panel-body">
<form method="post" action="login">
<input placeholder="User" name="user" type="text"><br>
<input placeholder="Password" name="password" type="password"><br>
{% if 'ref' in request.values %}
<input type="hidden" name="ref" value="{{ request.values.ref|e }}">
{% endif %}
<input type="submit" value="Login">
{% endblock %}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment