modified: web/blueprints/group_admin.py

modified:   web/templates/group_admin/database.html
This commit is contained in:
SimolZimol
2026-04-01 03:20:35 +02:00
parent 9d7a0343d5
commit e55175e8a7
2 changed files with 15 additions and 12 deletions

View File

@@ -132,6 +132,8 @@ def database():
has_db = db.has_db_configured(group_id) has_db = db.has_db_configured(group_id)
error = None error = None
creds = db.get_group_db_creds(group_id)
if request.method == "POST": if request.method == "POST":
host = request.form.get("host", "").strip() host = request.form.get("host", "").strip()
port = request.form.get("port", "3306").strip() port = request.form.get("port", "3306").strip()
@@ -139,26 +141,31 @@ def database():
password = request.form.get("password", "") password = request.form.get("password", "")
database_name = request.form.get("database", "").strip() 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]): if not all([host, port, user, database_name]):
error = "Host, Port, User and Database name are required." error = "Host, Port, User and Database name are required."
elif not password:
error = "Password is required."
else: else:
try: try:
# Verbindung testen
import pymysql import pymysql
test = pymysql.connect( test_conn = pymysql.connect(
host=host, port=int(port), user=user, host=host, port=int(port), user=user,
password=password, database=database_name, password=password, database=database_name,
connect_timeout=5 connect_timeout=5
) )
test.close() test_conn.close()
db.set_group_db_creds(group_id, host, int(port), user, password, database_name) db.set_group_db_creds(group_id, host, int(port), user, password, database_name)
flash("Database connection saved and tested ✓", "success") flash("Database connection saved and tested ✓", "success")
return redirect(url_for("group_admin.database")) return redirect(url_for("group_admin.database"))
except Exception as e: except Exception as e:
error = f"Verbindungstest fehlgeschlagen: {e}" error = f"Connection test failed: {e}"
return render_template("group_admin/database.html", 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"]) @group_admin.route("/database/delete", methods=["POST"])

View File

@@ -8,13 +8,9 @@
<div class="card border-secondary"> <div class="card border-secondary">
<div class="card-header">Connection Details</div> <div class="card-header">Connection Details</div>
<div class="card-body"> <div class="card-body">
{% if test_result is defined %} {% if error %}
<div class="alert {{ 'alert-success' if test_result else 'alert-danger' }}"> <div class="alert alert-danger">
{% if test_result %} <i class="bi bi-x-circle-fill me-2"></i>{{ error }}
<i class="bi bi-check-circle-fill me-2"></i>Connection successful! Settings saved.
{% else %}
<i class="bi bi-x-circle-fill me-2"></i>Connection failed: {{ test_error }}
{% endif %}
</div> </div>
{% endif %} {% endif %}