Blame view

app/auth/routes.py 959 Bytes
6d1690d1   hitier   All login mechani...
1
from flask import render_template, request, redirect, url_for, flash
59f42c31   hitier   Allow logout
2
from flask_login import login_user, logout_user
0d4479a4   hitier   Add login mechanism
3
from app.models import User
fcac7c5d   hitier   New auth blueprin...
4
5
6
7
8
9
10

from . import bp


@bp.route('/login')
def login():
    return render_template('login.html', title="Login")
6d1690d1   hitier   All login mechani...
11

0d4479a4   hitier   Add login mechanism
12

6d1690d1   hitier   All login mechani...
13
14
15
16
@bp.route('/login', methods=['POST'])
def login_post():
    user_login = request.form.get('login')
    user_password = request.form.get('password')
2816e773   hitier   Set flash with bo...
17
    # user_remember = request.form.get('remember')
0d4479a4   hitier   Add login mechanism
18
    user = User.query.filter_by(login=user_login).one_or_none()
0d4479a4   hitier   Add login mechanism
19
    if user and user.password == user_password:
0d4479a4   hitier   Add login mechanism
20
        login_user(user)
2816e773   hitier   Set flash with bo...
21
        flash("Connection Réussie !", 'success')
0d4479a4   hitier   Add login mechanism
22
23
        return redirect(url_for('main.index'))
    else:
2816e773   hitier   Set flash with bo...
24
        flash("Mauvais login ou mot de passe.", 'warning')
0d4479a4   hitier   Add login mechanism
25
        return redirect(url_for('auth.login'))
59f42c31   hitier   Allow logout
26
27
28
29
30


@bp.route('/logout')
def logout():
    logout_user()
2816e773   hitier   Set flash with bo...
31
    flash("Vous êtes maintenant déconnecté", 'info')
59f42c31   hitier   Allow logout
32
    return redirect(url_for('main.index'))