Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>
Add a logout route
src/blueprints/auth.py | 15 ++++++++++-----
diff --git a/src/blueprints/auth.py b/src/blueprints/auth.py index 8438ab16738832e09617fb797e5bb2b121dc463f..85db91707c4881b6078f76464d4bf583764d72db 100644 --- a/src/blueprints/auth.py +++ b/src/blueprints/auth.py @@ -1,15 +1,15 @@ from flask import Blueprint, render_template, url_for, redirect, request, flash from ..types.user import User from werkzeug.security import generate_password_hash, check_password_hash -from flask_login import login_user, current_user +from flask_login import login_user, current_user, logout_user auth = Blueprint('auth', __name__, url_prefix = "/auth") @auth.route('/login', methods = ['GET', 'POST']) def login(): if request.method == 'GET': - if current_user: - return redirect(url_for('basic.profile')) + if current_user.is_authenticated: + return redirect(url_for('basic.main')) else: return render_template('login.html', title = "Entrar - Feira Virtual Bem da Terra") else: @@ -25,7 +25,7 @@ return redirect(url_for('auth.login')) # User exists and works! login_user(user, remember = False) - return redirect(url_for('basic.profile')) + return redirect(url_for('basic.index')) @auth.route('/sign_up', methods = ['GET', 'POST']) def sign_up(): @@ -56,4 +56,9 @@ new_user.create() flash('Account created successfully') return redirect(url_for('auth.login')) - + +@auth.route('/logout') +def logout(): + logout_user() + + return redirect(url_for('basic.index'))