From fc8b11fa66d9a47a544969f65a232b726f08d770 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Fri, 15 Nov 2024 16:07:29 +0100 Subject: [PATCH] update auth package --- app/blueprints/auth/__init__.py | 26 +++++++++++++++++++++++++- app/blueprints/auth/routes.py | 20 -------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/blueprints/auth/__init__.py b/app/blueprints/auth/__init__.py index 6f6ba82d..8f2af4cf 100644 --- a/app/blueprints/auth/__init__.py +++ b/app/blueprints/auth/__init__.py @@ -1,5 +1,29 @@ -from flask import Blueprint +from flask import Blueprint, redirect, request, url_for +from flask_login import current_user +from app import db bp = Blueprint('auth', __name__) + + +@bp.before_app_request +def before_request(): + if not current_user.is_authenticated: + return + + current_user.ping() + db.session.commit() + + if ( + not current_user.confirmed + and request.endpoint + and request.blueprint != 'auth' + and request.endpoint != 'static' + ): + return redirect(url_for('auth.unconfirmed')) + + if not current_user.terms_of_use_accepted: + return redirect(url_for('main.terms_of_use')) + + from . import routes diff --git a/app/blueprints/auth/routes.py b/app/blueprints/auth/routes.py index 36b07b19..3faaced3 100644 --- a/app/blueprints/auth/routes.py +++ b/app/blueprints/auth/routes.py @@ -12,26 +12,6 @@ from .forms import ( ) -@bp.before_app_request -def before_request(): - """ - Checks if a user is unconfirmed when visiting specific sites. Redirects to - unconfirmed view if user is unconfirmed. - """ - if not current_user.is_authenticated: - return - - current_user.ping() - db.session.commit() - if (not current_user.confirmed - and request.endpoint - and request.blueprint != 'auth' - and request.endpoint != 'static'): - return redirect(url_for('auth.unconfirmed')) - if not current_user.terms_of_use_accepted: - return redirect(url_for('main.terms_of_use')) - - @bp.route('/register', methods=['GET', 'POST']) def register(): if current_user.is_authenticated: