04/30 Web Checker web app ver. 1.0

This commit is contained in:
2026-04-30 17:15:56 -04:00
parent feb8e5051c
commit cd63d5a020
39 changed files with 8031 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
"""
utils/decorators.py — Route protection decorators for the Flask web app.
"""
import functools
from flask import session, redirect, url_for, flash, abort
def login_required(f):
"""Redirect to login if the user is not authenticated."""
@functools.wraps(f)
def decorated(*args, **kwargs):
if "user" not in session:
flash("Please log in to access this page.", "warning")
return redirect(url_for("auth.login"))
return f(*args, **kwargs)
return decorated
def admin_required(f):
"""Abort 403 if the authenticated user is not an admin."""
@functools.wraps(f)
def decorated(*args, **kwargs):
if "user" not in session:
flash("Please log in to access this page.", "warning")
return redirect(url_for("auth.login"))
if session["user"].get("role") != "admin":
abort(403)
return f(*args, **kwargs)
return decorated