🔧 Update: Enhance Guest Request Management with OTP and Name Verification

**Änderungen:**
-  Hinzugefügt: Neue Methode `find_by_otp_and_name` in `GuestRequest`, um Gastanfragen anhand von OTP-Code und Name zu finden.
-  API-Endpunkte in `admin_unified.py` für die Verwaltung von Gastanfragen mit OTP-Codes implementiert, einschließlich Generierung und Druck von Zugangsdaten.
-  Anpassungen in `guest.py`, um die Authentifizierung von Gastanfragen mit Name und OTP-Code zu unterstützen.

**Ergebnis:**
- Verbesserte Sicherheit und Benutzerfreundlichkeit bei der Verwaltung von Gastanfragen im Offline-System.
- Klarere API-Responses und verbesserte Fehlerbehandlung für Gastanfragen.

🤖 Generated with [Claude Code](https://claude.ai/code)
This commit is contained in:
2025-06-16 01:27:41 +02:00
parent b1ae9523a9
commit b5c758c971
4 changed files with 842 additions and 25 deletions

View File

@@ -380,24 +380,29 @@ def api_create_guest_request():
@guest_blueprint.route('/api/guest/start-job', methods=['POST'])
# CSRF-Schutz wird in app.py für Guest-APIs deaktiviert
def api_start_job_with_code():
"""Job mit 6-stelligem OTP-Code starten."""
"""Job mit Name + 6-stelligem OTP-Code starten (Offline-System)."""
try:
data = request.get_json()
if not data or 'code' not in data:
return jsonify({"error": "Code ist erforderlich"}), 400
if not data or 'code' not in data or 'name' not in data:
return jsonify({"error": "Name und Code sind erforderlich"}), 400
code = data['code'].strip().upper()
name = data['name'].strip()
if len(code) != 6:
return jsonify({"error": "Code muss 6 Zeichen lang sein"}), 400
if not name:
return jsonify({"error": "Name ist erforderlich"}), 400
with get_cached_session() as db_session:
# Gastanfrage anhand des OTP-Codes finden
matching_request = GuestRequest.find_by_otp(code)
# Gastanfrage anhand des OTP-Codes UND Names finden
matching_request = GuestRequest.find_by_otp_and_name(code, name)
if not matching_request:
return jsonify({
"success": False,
"error": "Ungültiger oder bereits verwendeter Code"
"error": "Ungültiger Code oder Name stimmt nicht überein"
}), 400
# Prüfen ob zugehöriger Job existiert
@@ -997,8 +1002,8 @@ def api_get_request_otp(request_id):
# CSRF-Schutz wird in app.py für Guest-APIs deaktiviert
def api_guest_status_by_otp():
"""
Öffentliche Route für Gäste um ihren Auftragsstatus mit OTP-Code zu prüfen.
Keine Authentifizierung erforderlich.
Öffentliche Route für Gäste um ihren Auftragsstatus mit Name + OTP-Code zu prüfen.
Keine Authentifizierung erforderlich (Offline-System).
"""
try:
data = request.get_json()
@@ -1009,7 +1014,7 @@ def api_guest_status_by_otp():
}), 400
otp_code = data.get('otp_code', '').strip()
email = data.get('email', '').strip() # Optional für zusätzliche Verifikation
name = data.get('name', '').strip()
if not otp_code:
return jsonify({
@@ -1017,26 +1022,21 @@ def api_guest_status_by_otp():
'message': 'OTP-Code ist erforderlich'
}), 400
if not name:
return jsonify({
'success': False,
'message': 'Name ist erforderlich'
}), 400
with get_cached_session() as db_session:
# Alle Gastaufträge mit OTP-Codes finden
guest_requests = db_session.query(GuestRequest).filter(
GuestRequest.otp_code.isnot(None)
).all()
found_request = None
for request_obj in guest_requests:
if request_obj.verify_otp(otp_code):
# Zusätzliche E-Mail-Verifikation falls angegeben
if email and request_obj.email and request_obj.email.lower() != email.lower():
continue
found_request = request_obj
break
# Gastanfrage mit Name + OTP-Code finden (sichere Methode)
found_request = GuestRequest.find_by_otp_and_name(otp_code, name)
if not found_request:
logger.warning(f"Ungültiger OTP-Code für Gast-Status-Abfrage: {otp_code[:4]}****")
logger.warning(f"Ungültiger OTP-Code oder Name für Gast-Status-Abfrage: {name} / {otp_code[:4]}****")
return jsonify({
'success': False,
'message': 'Ungültiger Code oder E-Mail-Adresse'
'message': 'Ungültiger Code oder Name stimmt nicht überein'
}), 404
# Status-Informationen für den Gast zusammenstellen