Blame view

flaskr/controllers/user_controller.py 939 Bytes
df4268cc   Goutte   Add the main cont...
1
2
3
from flask import Blueprint, render_template, flash, request, redirect, url_for
from flask_login import login_user, logout_user, login_required

df4268cc   Goutte   Add the main cont...
4
from flaskr.forms import LoginForm
7b4d2926   Goutte   Rework the contro...
5
from flaskr.models import db, User
df4268cc   Goutte   Add the main cont...
6

7b4d2926   Goutte   Rework the contro...
7
from flaskr.controllers.main_controller import main
df4268cc   Goutte   Add the main cont...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


@main.route("/login", methods=["GET", "POST"])
def login():
    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).one()
        login_user(user)

        flash("Logged in successfully.", "success")
        return redirect(request.args.get("next") or url_for(".home"))

    return render_template("login.html", form=form)


@main.route("/logout")
def logout():
    logout_user()
    flash("You have been logged out.", "success")

    return redirect(url_for(".home"))


7b4d2926   Goutte   Rework the contro...
32
33
34
35
# @main.route("/restricted")
# @login_required
# def restricted():
#     return "You can only see this if you are logged in!", 200