From c7395b07d91744fe0276aca95dd8ae7ba5a219da Mon Sep 17 00:00:00 2001 From: Stef Date: Mon, 11 Aug 2025 18:05:30 +0200 Subject: [PATCH] Move logout route to auth blueprint The logout route was relocated from the main app to the auth blueprint for better organization. The logout link in the base template was updated to reference the new route location. --- app.py | 7 ------- application/auth/routes.py | 11 ++++++++++- application/templates/base.html | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 09b8d82..5afaacd 100644 --- a/app.py +++ b/app.py @@ -55,13 +55,6 @@ def favicon(): return send_from_directory("static", "favicon.ico") -@app.route("/logout") -@login_required -def logout(): - logout_user() - return redirect(url_for("index")) - - # Run if __name__ == "__main__": # If there are no users, create admin account diff --git a/application/auth/routes.py b/application/auth/routes.py index b37b025..6d6f4b2 100644 --- a/application/auth/routes.py +++ b/application/auth/routes.py @@ -1,5 +1,5 @@ from flask import Blueprint, request, render_template, redirect, url_for -from flask_login import current_user, login_user +from flask_login import current_user, login_user, logout_user from forms import LoginForm, ChangePasswordForm from models import User from application.utils import default_return @@ -48,3 +48,12 @@ def change_password(): db.session.commit() return default_return() return render_template("change_password.html", form=form) + + +@bp.route("/logout") +def logout(): + if not current_user.is_authenticated: + return redirect(url_for("auth.login")) + + logout_user() + return redirect(url_for("index")) diff --git a/application/templates/base.html b/application/templates/base.html index 37428ff..bd29f84 100644 --- a/application/templates/base.html +++ b/application/templates/base.html @@ -32,7 +32,7 @@