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() if user and user.password == user_password: login_user(user) flash("Connection Réussie !", 'success') return redirect(url_for('main.index')) else: flash("Mauvais login ou mot de passe.", 'warning') return redirect(url_for('auth.login')) @bp.route('/logout') def logout(): logout_user() flash("Vous êtes maintenant déconnecté", 'info') return redirect(url_for('main.index'))