"Refactor guest templates and blueprint"

This commit is contained in:
2025-05-29 11:39:13 +02:00
parent efca95aeb2
commit cd867c07f9
4 changed files with 306 additions and 763 deletions

View File

@@ -50,6 +50,36 @@ app.config["WTF_CSRF_ENABLED"] = True
# CSRF-Schutz initialisieren
csrf = CSRFProtect(app)
# CSRF-Exemption für Guest-API-Endpunkte
@app.before_request
def csrf_exempt_for_guest_api():
"""Befreit bestimmte API-Endpunkte vom CSRF-Schutz."""
if request.endpoint and (
request.endpoint.startswith('guest.api_') or
request.path.startswith('/api/guest/') or
request.path.startswith('/api/jobs/start/')
):
# CSRF-Schutz für diese Endpunkte deaktivieren
csrf._exempt_views.add(request.endpoint)
# CSRF-Error-Handler
@csrf.error_handler
def csrf_error(reason):
"""Behandelt CSRF-Fehler und gibt detaillierte Informationen zurück."""
app_logger.error(f"CSRF-Fehler für {request.path}: {reason}")
if request.path.startswith('/api/'):
# Für API-Anfragen: JSON-Response
return jsonify({
"error": "CSRF-Token fehlt oder ungültig",
"reason": str(reason),
"help": "Fügen Sie ein gültiges CSRF-Token zu Ihrer Anfrage hinzu"
}), 400
else:
# Für normale Anfragen: Weiterleitung zur Fehlerseite
flash("Sicherheitsfehler: Anfrage wurde abgelehnt. Bitte versuchen Sie es erneut.", "error")
return redirect(request.url)
# Blueprints registrieren
app.register_blueprint(guest_blueprint)
app.register_blueprint(calendar_blueprint)