modified: web/blueprints/group_admin.py
modified: web/templates/group_admin/database.html
This commit is contained in:
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user