MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / chats

Function chats

Scripts/ButSystem.py:13132–13177  ·  view source on GitHub ↗

chats. Route handler or application helper. This docstring was expanded to make future maintenance easier. Returns: Varies.

()

Source from the content-addressed store, hash-verified

13130 u = (request.form.get("username") or "").strip()
13131 if not u or u == current_user():
13132 return redirect(url_for("admin_panel"))
13133
13134 conn = db_connect()
13135 # Prevent deleting the last admin
13136 if user_is_admin(u):
13137 row = conn.execute("SELECT COUNT(*) AS c FROM users WHERE is_admin=1").fetchone()
13138 if row and int(row["c"]) <= 1:
13139 conn.close()
13140 flash("Cannot delete the last admin.")
13141 return redirect(url_for("admin_panel"))
13142
13143 # Remove account + public profile + memberships
13144 conn.execute("DELETE FROM profiles WHERE username=?", (u,))
13145 conn.execute("DELETE FROM group_members WHERE username=?", (u,))
13146 conn.execute("DELETE FROM users WHERE username=?", (u,))
13147 conn.commit()
13148 conn.close()
13149
13150 # Also remove their vault directory (encrypted files)
13151 try:
13152 shutil.rmtree(user_root(u), ignore_errors=True)
13153 except Exception:
13154 pass
13155
13156 flash(f"Deleted @{u}.")
13157 return redirect(url_for("admin_panel"))
13158
13159
13160
13161
13162@app.route("/admin/delete_me", methods=["POST"])
13163@login_required
13164def admin_delete_me():
13165 """Delete the currently logged-in admin account (keeps files)."""
13166 require_admin()
13167 try:
13168 log_security_event("admin_action", detail="delete_self_admin", username=current_user(), level="info")
13169 except Exception:
13170 pass
13171 me = current_user()
13172 password = request.form.get("password") or ""
13173
13174 conn = db_connect()
13175 row = conn.execute("SELECT pw_hash FROM users WHERE username=?", (me,)).fetchone()
13176 if not row or not check_password_hash(row["pw_hash"], password):
13177 conn.close()
13178 flash("Wrong password.")
13179 return redirect(url_for("admin_panel"))
13180

Callers

nothing calls this directly

Calls 6

current_userFunction · 0.70
db_connectFunction · 0.70
now_zFunction · 0.70
user_cardsFunction · 0.70
dm_unread_countsFunction · 0.70
ensure_profile_rowFunction · 0.70

Tested by

no test coverage detected