html refactoring

This commit is contained in:
Bkolb 2026-04-02 12:31:54 +02:00
parent 2ab719774b
commit 341a6e61ee
5 changed files with 177 additions and 208 deletions

View File

@ -270,6 +270,30 @@ def get_current_user():
"is_admin": user_is_admin() if session.get("user_id") else False, "is_admin": user_is_admin() if session.get("user_id") else False,
} }
def get_current_user_mandant_level():
user_id = session.get("user_id")
if not user_id:
return None
conn = get_connection()
cur = conn.cursor()
cur.execute("""
SELECT m.level
FROM app_user u
JOIN mandant m ON m.id = u.mandant_id
WHERE u.id = %s
""", (user_id,))
row = cur.fetchone()
cur.close()
conn.close()
if row is None:
return None
return row[0]
def admin_required(view_func): def admin_required(view_func):
@wraps(view_func) @wraps(view_func)
@ -407,16 +431,42 @@ def health():
return f"DB Fehler: {exc}\n", 500 return f"DB Fehler: {exc}\n", 500
@app.route("/videos/<path:filename>")
@login_required
def protected_videos(filename):
mandant_level = get_current_user_mandant_level()
if mandant_level is None:
abort(403)
basename = os.path.basename(filename)
first_char = basename[:1].upper()
# Level 0 und 1: alles erlaubt
if mandant_level in (0, 1):
allowed = True
# Level 2: nur A und B
elif mandant_level == 2:
allowed = first_char in ("A", "B")
# Level 3: nur A
elif mandant_level == 3:
allowed = first_char == "A"
else:
allowed = False
if not allowed:
abort(403)
return send_from_directory("/app/images/videos", filename)
@app.route("/images/<path:filename>") @app.route("/images/<path:filename>")
def images(filename): def serve_image(filename):
# 🔒 Schutz für Videos
if filename.startswith("videos/"): if filename.startswith("videos/"):
if not session.get("user_id"): abort(403)
return redirect(url_for("login", next=request.path))
return send_from_directory("images", filename)
return send_from_directory("/app/images", filename)
@app.route("/styles/<path:filename>") @app.route("/styles/<path:filename>")
def serve_style(filename): def serve_style(filename):

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page_title }}</title>
<link rel="stylesheet" href="/styles/site.css">
</head>
<body>
<!-- HEADER + MENU -->
<header class="site-header">
<div class="header-inner">
<div class="logo-area">
<a href="/home">
<img src="/images/Logo-Compliance-Verification-bg-1.png" alt="Logo" class="site-logo">
</a>
</div>
<nav class="top-nav">
<a href="/home" class="{% if active_page == 'home' %}active{% endif %}">Home</a>
<a href="/preise" class="{% if active_page == 'preise' %}active{% endif %}">Preise</a>
<a href="/allgemein" class="{% if active_page == 'allgemein' %}active{% endif %}">Allgemein</a>
{% if is_logged_in %}
<div class="user-menu">
<button class="user-menu-toggle" type="button">{{ user_name }} ▾</button>
<div class="user-menu-dropdown">
<a href="/profil">Profil</a>
{% if is_admin %}
<a href="/admin/mandanten">Admin</a>
{% endif %}
<a href="/logout">Logout</a>
</div>
</div>
{% else %}
<a href="/login" class="{% if active_page == 'login' %}active{% endif %}">Login</a>
{% endif %}
</nav>
</div>
</header>
<!-- CONTENT -->
<main class="content-area">
<section class="content-box">
{% block content %}
{% endblock %}
</section>
</main>
</body>
</html>

View File

@ -1,71 +1,25 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page_title }}</title>
<link rel="stylesheet" href="/styles/site.css">
</head>
<body>
<header class="site-header">
<div class="header-inner">
<div class="logo-area">
<a href="/home">
<img src="/images/Logo-Compliance-Verification-bg-1.png" alt="Logo" class="site-logo">
</a>
</div>
<nav class="top-nav"> {% block content %}
<a href="/home" class="{% if active_page == 'home' %}active{% endif %}">Home</a>
<a href="/preise" class="{% if active_page == 'preise' %}active{% endif %}">Preise</a>
<a href="/allgemein" class="{% if active_page == 'allgemein' %}active{% endif %}">Allgemein</a>
{% if is_logged_in %} <h1>Login</h1>
<div class="user-menu">
<button class="user-menu-toggle" type="button">{{ user_name }} ▾</button>
<div class="user-menu-dropdown">
<a href="/profil">Profil</a>
{% if is_admin %}
<a href="/admin/mandanten">Admin</a>
{% endif %}
<a href="/logout">Logout</a>
</div>
</div>
{% else %}
<a href="/login" class="{% if active_page == 'login' %}active{% endif %}">Login</a>
{% endif %}
</nav>
</div>
</header>
<main class="content-area"> {% if error_message %}
<section class="content-box login-box">
<h1>Login</h1>
<p class="intro-text">Bitte melden Sie sich an, um in den Kundenbereich zu gelangen.</p>
<p class="intro-text">Sollten Sie noch über keine Login-Daten verfügen, wenden Sie sich bitte an Ihren Kundenbetreuer.</p>
{% if error_message %}
<div class="error-box">{{ error_message }}</div> <div class="error-box">{{ error_message }}</div>
{% endif %} {% endif %}
<form method="post" action="/login" class="login-form">
<input type="hidden" name="next" value="{{ next_url }}">
<form method="post" class="login-form">
<div class="form-row"> <div class="form-row">
<label for="email">E-Mail</label> <label>E-Mail</label>
<input type="email" id="email" name="email" required> <input type="email" name="email" required>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="password">Passwort</label> <label>Passwort</label>
<input type="password" id="password" name="password" required> <input type="password" name="password" required>
</div> </div>
<div class="form-row"> <button type="submit" class="btn-primary">Login</button>
<button type="submit" class="btn-primary">Anmelden</button> </form>
</div>
</form> {% endblock %}
</section>
</main>
</body>
</html>

View File

@ -1,72 +1,20 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page_title }}</title>
<link rel="stylesheet" href="/styles/site.css">
</head>
<body>
<header class="site-header">
<div class="header-inner">
<div class="logo-area">
<a href="/home">
<img src="/images/Logo-Compliance-Verification-bg-1.png" alt="Logo" class="site-logo">
</a>
</div>
<nav class="top-nav"> {% block content %}
<a href="/home">Home</a>
<a href="/preise">Preise</a>
<a href="/allgemein">Allgemein</a>
{% if is_logged_in %} <h1>Profil</h1>
<div class="user-menu">
<button class="user-menu-toggle" type="button">{{ user_name }} ▾</button>
<div class="user-menu-dropdown">
<a href="/profil">Profil</a>
{% if is_admin %}
<a href="/admin/mandanten">Admin</a>
{% endif %}
<a href="/logout">Logout</a>
</div>
</div>
{% else %}
<a href="/login">Login</a>
{% endif %}
</nav>
</div>
</header>
<main class="content-area"> <table class="admin-table">
<section class="content-box">
<h1>Profil</h1>
<table class="admin-table">
<tr><th>ID</th><td>{{ profile.id }}</td></tr> <tr><th>ID</th><td>{{ profile.id }}</td></tr>
<tr><th>Name</th><td>{{ profile.name }}</td></tr> <tr><th>Name</th><td>{{ profile.name }}</td></tr>
<tr><th>E-Mail</th><td>{{ profile.email }}</td></tr> <tr><th>E-Mail</th><td>{{ profile.email }}</td></tr>
<tr><th>Mandant</th><td>{{ profile.mandant_name }} ({{ profile.mandant_kuerzel }})</td></tr> <tr><th>Mandant</th><td>{{ profile.mandant_name }} ({{ profile.mandant_kuerzel }})</td></tr>
<tr><th>Status</th><td>{{ profile.status }}</td></tr> <tr><th>Mandant E-Mail</th><td>{{ profile.mandant_email or '-' }}</td></tr>
<tr><th>Letzter Login</th><td>{{ profile.last_login }}</td></tr> <tr><th>Mandant Level</th><td>{{ profile.mandant_level }}</td></tr>
</table>
<div class="admin-actions">
<tr>
<th>Mandant E-Mail</th>
<td>{{ profile.mandant_email }}</td>
</tr>
<tr>
<th>Mandant Level</th>
<td>{{ profile.mandant_level }}</td>
</tr>
</table>
<div class="admin-actions">
<a href="/pwdchange" class="btn-primary">Passwort ändern</a> <a href="/pwdchange" class="btn-primary">Passwort ändern</a>
</div> </div>
</section> {% endblock %}
</main>
</body>
</html>

View File

@ -1,78 +1,39 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page_title }}</title>
<link rel="stylesheet" href="/styles/site.css">
</head>
<body>
<header class="site-header">
<div class="header-inner">
<div class="logo-area">
<a href="/home">
<img src="/images/Logo-Compliance-Verification-bg-1.png" alt="Logo" class="site-logo">
</a>
</div>
<nav class="top-nav"> {% block content %}
<a href="/home">Home</a>
<a href="/preise">Preise</a>
<a href="/allgemein">Allgemein</a>
{% if is_logged_in %} <h1>Passwort ändern</h1>
<div class="user-menu">
<button class="user-menu-toggle" type="button">{{ user_name }} ▾</button>
<div class="user-menu-dropdown">
<a href="/profil">Profil</a>
{% if is_admin %}
<a href="/admin/mandanten">Admin</a>
{% endif %}
<a href="/logout">Logout</a>
</div>
</div>
{% else %}
<a href="/login">Login</a>
{% endif %}
</nav>
</div>
</header>
<main class="content-area"> {% if error_message %}
<section class="content-box login-box">
<h1>Passwort ändern</h1>
<p class="intro-text">Ändern Sie hier Ihr Passwort.</p>
{% if error_message %}
<div class="error-box">{{ error_message }}</div> <div class="error-box">{{ error_message }}</div>
{% endif %} {% endif %}
{% if success_message %} {% if success_message %}
<div class="success-box">{{ success_message }}</div> <div class="success-box">{{ success_message }}</div>
{% endif %} {% endif %}
<form method="post" class="login-form">
<form method="post" action="/pwdchange" class="login-form">
<div class="form-row"> <div class="form-row">
<label for="current_password">Aktuelles Passwort</label> <label>Aktuelles Passwort</label>
<input type="password" id="current_password" name="current_password" required> <input type="password" name="current_password" required>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="new_password">Neues Passwort</label> <label>Neues Passwort</label>
<input type="password" id="new_password" name="new_password" required> <input type="password" name="new_password" required>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="confirm_password">Neues Passwort bestätigen</label> <label>Bestätigen</label>
<input type="password" id="confirm_password" name="confirm_password" required> <input type="password" name="confirm_password" required>
</div> </div>
<div class="admin-actions"> <div class="admin-actions">
<button type="submit" class="btn-primary">Passwort speichern</button> <button type="submit" class="btn-primary">Speichern</button>
<a href="/profil" class="btn-secondary">Zurück zum Profil</a> <a href="/profil" class="btn-secondary">Zurück zum Profil</a>
</div> </div>
</form>
</section> </form>
</main>
</body> {% endblock %}
</html>