Blame view

app/auth/routes.py 991 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
17
@bp.route('/login', methods=['POST'])
def login_post():
    user_login = request.form.get('login')
    user_password = request.form.get('password')
    user_remember = request.form.get('remember')
0d4479a4   hitier   Add login mechanism
18
    user = User.query.filter_by(login=user_login).one_or_none()
a49732b5   hitier   Add current user ...
19
    print("user login: {}, user password: {}".format(user.login, user.password))
0d4479a4   hitier   Add login mechanism
20
21
22
    if user and user.password == user_password:
        # login code goes here
        login_user(user)
59f42c31   hitier   Allow logout
23
        flash("Connection RĂ©ussie !")
0d4479a4   hitier   Add login mechanism
24
25
        return redirect(url_for('main.index'))
    else:
59f42c31   hitier   Allow logout
26
        flash("Mauvais login ou mot de passe.")
0d4479a4   hitier   Add login mechanism
27
        return redirect(url_for('auth.login'))
59f42c31   hitier   Allow logout
28
29
30
31
32
33


@bp.route('/logout')
def logout():
    logout_user()
    return redirect(url_for('main.index'))