from flask import render_template, request, redirect, url_for, flash from flask_login import login_user, logout_user from app.models import User from . import bp @bp.route('/login') def login(): return render_template('login.html', title="Login") @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') user = User.query.filter_by(login=user_login).one_or_none() print("user login: {}, user password: {}".format(user.login, user.password)) if user and user.password == user_password: # login code goes here login_user(user) flash("Connection RĂ©ussie !") return redirect(url_for('main.index')) else: flash("Mauvais login ou mot de passe.") return redirect(url_for('auth.login')) @bp.route('/logout') def logout(): logout_user() return redirect(url_for('main.index'))