From 7c6ecd83f48f70af321ecd940e4cb419e3a2f0e2 Mon Sep 17 00:00:00 2001 From: AIIrondev Date: Tue, 25 Aug 2026 14:17:32 +0200 Subject: [PATCH] change to the buchungs system --- Website/main.py | 66 +++++++++++++++----------- Website/templates/schnell_buchung.html | 25 +++++----- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/Website/main.py b/Website/main.py index 4e17fc2..d2aab82 100644 --- a/Website/main.py +++ b/Website/main.py @@ -3714,38 +3714,46 @@ def run_tenant_provisioning_async(app, user_id, tenant_slug, school_name, user_e @app.route('/booking_payment_async', methods=['POST']) @login_required def booking_payment_async(): - user_id = session.get("user_id") - user_email = session.get("email") - tenant_slug = _slugify_subdomain(request.form.get('tenant_slug')) - school_name = request.form.get('school_name', tenant_slug) - - # Insert request record into instance_requests - req_client, req_col = _get_collection("instance_requests") try: - prov_doc = { - "user_id": user_id, - "tenant_slug": tenant_slug, - "school_name": school_name, - "provision_status": "pending", - "created_at": _utc_now_iso(), - "updated_at": _utc_now_iso() - } - prov_id = str(req_col.insert_one(prov_doc).inserted_id) - finally: - req_client.close() + user_id = session.get("user_id") + user_email = session.get("email") + tenant_slug = _slugify_subdomain(request.form.get('tenant_slug')) + school_name = request.form.get('school_name', tenant_slug) - # Start async worker passing prov_id - thread = threading.Thread( - target=run_tenant_provisioning_async, - args=(app._get_current_object(), user_id, tenant_slug, school_name, user_email, prov_id) - ) - thread.start() + if not tenant_slug: + return jsonify({"success": False, "error": "Ungültige Subdomain angegeben."}), 400 - return jsonify({ - "success": True, - "tenant_slug": tenant_slug, - "request_id": prov_id - }), 200 + # Datenbank-Eintrag erstellen... + req_client, req_col = _get_collection("instance_requests") + try: + prov_doc = { + "user_id": user_id, + "tenant_slug": tenant_slug, + "school_name": school_name, + "provision_status": "pending", + "created_at": _utc_now_iso(), + "updated_at": _utc_now_iso() + } + prov_id = str(req_col.insert_one(prov_doc).inserted_id) + finally: + req_client.close() + + # Asynchronen Thread starten... + thread = threading.Thread( + target=run_tenant_provisioning_async, + args=(app._get_current_object(), user_id, tenant_slug, school_name, user_email, prov_id) + ) + thread.start() + + return jsonify({ + "success": True, + "tenant_slug": tenant_slug, + "request_id": prov_id + }), 200 + + except Exception as e: + # WICHTIG: Fängt jegliche Python-Fehler ab und sendet sauberes JSON statt HTML-Crash + return jsonify({"success": False, "error": str(e)}), 500 @app.route('/instance_request/status') def tenant_status(): diff --git a/Website/templates/schnell_buchung.html b/Website/templates/schnell_buchung.html index a86413d..bd77fd4 100644 --- a/Website/templates/schnell_buchung.html +++ b/Website/templates/schnell_buchung.html @@ -481,20 +481,23 @@ body: formData, headers: { 'Accept': 'application/json' } }); - - const result = await response.json(); - - if (!response.ok) { + + // Prüfen, ob der Server echtes JSON zurückgibt + const contentType = response.headers.get("content-type"); + let result; + if (contentType && contentType.includes("application/json")) { + result = await response.json(); + } else { + // Wenn der Server HTML schickt (z.B. Flask Debugger Error Page) + const rawText = await response.text(); + console.error("Server hat kein JSON gesendet:", rawText); + throw new Error("Ein Serverfehler ist aufgetreten. Bitte prüfen Sie die Konsolenausgabe."); + } + + if (!response.ok || !result.success) { throw new Error(result.error || 'Es gab ein Problem bei der Buchung.'); } - // Erfolg: Formular verstecken, Ladebildschirm zeigen - formState.style.display = 'none'; - loadingState.style.display = 'block'; - - // Starte Polling - startPolling(tenantSlug); - } catch (error) { errorAlert.textContent = error.message; errorAlert.style.display = 'block';