From 0a4d79ec6d2da87edfd36f51bec4bdd145ef7351 Mon Sep 17 00:00:00 2001 From: UserIsMH Date: Tue, 10 Jun 2025 00:35:41 +0200 Subject: [PATCH] Neuer Kunde anlegen ohne Lizenz --- v2_adminpanel/app.py | 55 ++++++++++++++ v2_adminpanel/templates/create_customer.html | 74 +++++++++++++++++++ v2_adminpanel/templates/customers.html | 1 + .../templates/customers_licenses.html | 1 + 4 files changed, 131 insertions(+) create mode 100644 v2_adminpanel/templates/create_customer.html diff --git a/v2_adminpanel/app.py b/v2_adminpanel/app.py index b121900..2ad6183 100644 --- a/v2_adminpanel/app.py +++ b/v2_adminpanel/app.py @@ -2185,6 +2185,61 @@ def edit_customer(customer_id): return render_template("edit_customer.html", customer=customer, licenses=licenses, username=session.get('username')) +@app.route("/customer/create", methods=["GET", "POST"]) +@login_required +def create_customer(): + """Erstellt einen neuen Kunden ohne Lizenz""" + if request.method == "POST": + name = request.form.get('name') + email = request.form.get('email') + is_test = request.form.get('is_test') == 'on' + + if not name or not email: + flash("Name und E-Mail sind Pflichtfelder!", "error") + return render_template("create_customer.html", username=session.get('username')) + + conn = get_connection() + cur = conn.cursor() + + try: + # Prüfen ob E-Mail bereits existiert + cur.execute("SELECT id, name FROM customers WHERE email = %s", (email,)) + existing = cur.fetchone() + if existing: + flash(f"Ein Kunde mit der E-Mail '{email}' existiert bereits: {existing[1]}", "error") + return render_template("create_customer.html", username=session.get('username')) + + # Kunde erstellen + cur.execute(""" + INSERT INTO customers (name, email, created_at, is_test) + VALUES (%s, %s, %s, %s) RETURNING id + """, (name, email, datetime.now(), is_test)) + + customer_id = cur.fetchone()[0] + conn.commit() + + # Audit-Log + log_audit('CREATE', 'customer', customer_id, + new_values={ + 'name': name, + 'email': email, + 'is_test': is_test + }) + + flash(f"Kunde '{name}' wurde erfolgreich angelegt!", "success") + return redirect(f"/customer/edit/{customer_id}") + + except Exception as e: + conn.rollback() + flash(f"Fehler beim Anlegen des Kunden: {str(e)}", "error") + return render_template("create_customer.html", username=session.get('username')) + finally: + cur.close() + conn.close() + + # GET Request - Formular anzeigen + return render_template("create_customer.html", username=session.get('username')) + @app.route("/customer/delete/", methods=["POST"]) @login_required def delete_customer(customer_id): diff --git a/v2_adminpanel/templates/create_customer.html b/v2_adminpanel/templates/create_customer.html new file mode 100644 index 0000000..4e53ea3 --- /dev/null +++ b/v2_adminpanel/templates/create_customer.html @@ -0,0 +1,74 @@ +{% extends "base.html" %} + +{% block title %}Neuer Kunde{% endblock %} + +{% block content %} +
+
+

👤 Neuer Kunde anlegen

+
+ 📊 Dashboard + 👥 Zurück zur Übersicht +
+
+ +
+
+
+
+
+ + +
Der Name des Kunden oder der Firma
+
+
+ + +
Kontakt-E-Mail-Adresse des Kunden
+
+
+ +
+ + +
+ + + +
+ + Abbrechen +
+
+
+
+
+ + +{% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} +
+ {% for category, message in messages %} + + {% endfor %} +
+ {% endif %} +{% endwith %} +{% endblock %} \ No newline at end of file diff --git a/v2_adminpanel/templates/customers.html b/v2_adminpanel/templates/customers.html index 4e340d4..6552dc7 100644 --- a/v2_adminpanel/templates/customers.html +++ b/v2_adminpanel/templates/customers.html @@ -32,6 +32,7 @@ Kombinierte Ansicht 📊 Dashboard + 👤 Neuer Kunde ➕ Neue Lizenz 🔑 Batch-Lizenzen
diff --git a/v2_adminpanel/templates/customers_licenses.html b/v2_adminpanel/templates/customers_licenses.html index d2df36e..bd699c8 100644 --- a/v2_adminpanel/templates/customers_licenses.html +++ b/v2_adminpanel/templates/customers_licenses.html @@ -7,6 +7,7 @@