From e55175e8a702b9544838dc4b52c01d64fa1f6e8f Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Wed, 1 Apr 2026 03:20:35 +0200 Subject: [PATCH] modified: web/blueprints/group_admin.py modified: web/templates/group_admin/database.html --- web/blueprints/group_admin.py | 17 ++++++++++++----- web/templates/group_admin/database.html | 10 +++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/web/blueprints/group_admin.py b/web/blueprints/group_admin.py index 55c61bc..449c0eb 100644 --- a/web/blueprints/group_admin.py +++ b/web/blueprints/group_admin.py @@ -132,6 +132,8 @@ def database(): has_db = db.has_db_configured(group_id) error = None + creds = db.get_group_db_creds(group_id) + if request.method == "POST": host = request.form.get("host", "").strip() port = request.form.get("port", "3306").strip() @@ -139,26 +141,31 @@ def database(): password = request.form.get("password", "") database_name = request.form.get("database", "").strip() + # If password left blank and creds already exist, keep the stored password + if not password and creds: + password = creds["password"] + if not all([host, port, user, database_name]): error = "Host, Port, User and Database name are required." + elif not password: + error = "Password is required." else: try: - # Verbindung testen import pymysql - test = pymysql.connect( + test_conn = pymysql.connect( host=host, port=int(port), user=user, password=password, database=database_name, connect_timeout=5 ) - test.close() + test_conn.close() db.set_group_db_creds(group_id, host, int(port), user, password, database_name) flash("Database connection saved and tested ✓", "success") return redirect(url_for("group_admin.database")) except Exception as e: - error = f"Verbindungstest fehlgeschlagen: {e}" + error = f"Connection test failed: {e}" return render_template("group_admin/database.html", - group=group, has_db=has_db, error=error) + group=group, has_db=has_db, creds=creds, error=error) @group_admin.route("/database/delete", methods=["POST"]) diff --git a/web/templates/group_admin/database.html b/web/templates/group_admin/database.html index b968c38..fd549cb 100644 --- a/web/templates/group_admin/database.html +++ b/web/templates/group_admin/database.html @@ -8,13 +8,9 @@
Connection Details
- {% if test_result is defined %} -
- {% if test_result %} - Connection successful! Settings saved. - {% else %} - Connection failed: {{ test_error }} - {% endif %} + {% if error %} +
+ {{ error }}
{% endif %}