Make Nextcloud user and password mandatory for all sites
- NC User and NC Pass are now required fields when adding a site - Auto-provision Nextcloud user on site creation - Client-side validation enforces all fields in both Add and Edit forms - Updated placeholder text to reflect required status - Sites without NC creds now show Not set badge instead of Global Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
26
app.py
26
app.py
@@ -981,14 +981,15 @@ def admin_dashboard():
|
||||
def admin_add_site():
|
||||
"""Add a new site to sites.conf.
|
||||
|
||||
JSON body: {site, pin, nc_user?, nc_pass?}
|
||||
JSON body: {site, pin, nc_user, nc_pass}
|
||||
Site must be exactly 4 digits and must not already exist.
|
||||
NC User and NC Pass are required.
|
||||
"""
|
||||
data = request.get_json(force=True)
|
||||
site = data.get("site", "").strip()
|
||||
pin = data.get("pin", "").strip()
|
||||
nc_user = data.get("nc_user", "").strip() or None
|
||||
nc_pass = data.get("nc_pass", "").strip() or None
|
||||
nc_user = data.get("nc_user", "").strip()
|
||||
nc_pass = data.get("nc_pass", "").strip()
|
||||
|
||||
if not re.fullmatch(r"\d{4}", site):
|
||||
return jsonify({"ok": False, "error": "Site must be exactly 4 digits"}), 400
|
||||
@@ -996,6 +997,12 @@ def admin_add_site():
|
||||
if not pin:
|
||||
return jsonify({"ok": False, "error": "PIN is required"}), 400
|
||||
|
||||
if not nc_user:
|
||||
return jsonify({"ok": False, "error": "NC User is required"}), 400
|
||||
|
||||
if not nc_pass:
|
||||
return jsonify({"ok": False, "error": "NC Pass is required"}), 400
|
||||
|
||||
# Reject characters that would corrupt sites.conf (colon is the
|
||||
# field delimiter, newlines would inject extra lines)
|
||||
for field_name, value in [("PIN", pin), ("NC User", nc_user), ("NC Pass", nc_pass)]:
|
||||
@@ -1011,7 +1018,18 @@ def admin_add_site():
|
||||
|
||||
sites[site] = {"pin": pin, "nc_user": nc_user, "nc_pass": nc_pass}
|
||||
save_sites(sites)
|
||||
return jsonify({"ok": True})
|
||||
|
||||
# Auto-provision the Nextcloud user
|
||||
nc_msg = None
|
||||
if all([NC_URL, NC_USER, NC_PASS]):
|
||||
if nc_user_exists(nc_user):
|
||||
nc_msg = f"NC user '{nc_user}' already exists"
|
||||
elif nc_create_user(nc_user, nc_pass):
|
||||
nc_msg = f"NC user '{nc_user}' created"
|
||||
else:
|
||||
nc_msg = f"Site saved, but failed to create NC user '{nc_user}'"
|
||||
|
||||
return jsonify({"ok": True, "nc_msg": nc_msg})
|
||||
|
||||
|
||||
@app.route("/admin/api/sites/<site_id>", methods=["PUT"])
|
||||
|
||||
Reference in New Issue
Block a user