summaryrefslogtreecommitdiff
path: root/app/views/login.py
blob: 413d40635a56a731c3137603c0e4e1f8d9ba9224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from . import Blueprint, flash, db, \
        current_user, login_required, \
        templated, request, url_for

from ..forms import LoginForm
from ..login import login_user, logout_user, login_manager

# we explicitly need flask's redirect and not our variant
from flask import redirect

mod = Blueprint('login', __name__)

@mod.route("/login", methods=("GET", "POST"))
@templated()
def login():
   form = LoginForm()

   if form.validate_on_submit():
       login_user(form.user)
       return redirect(request.args.get("next") or url_for("index"))
   elif form.is_submitted():
       flash("Login fehlgeschlagen!", "error")

   return { 'form': form }

@mod.route("/logout")
def logout():
    logout_user()
    return redirect(url_for(".login"))

login_manager.login_view = 'login.login'