From b17b75e043d7d12cefb2ab579df60c30a6fcd6d7 Mon Sep 17 00:00:00 2001
From: wiktr
Date: Mon, 24 Aug 2026 18:21:20 +0200
Subject: [PATCH] add admin user list
---
app/auth.py | 38 ++++++++++++++++++++++++++++
app/main.py | 12 ++++++---
app/templates/admin.html | 48 ++++++++++++++++++++++++++++++++++++
app/templates/dashboard.html | 2 +-
4 files changed, 95 insertions(+), 5 deletions(-)
create mode 100644 app/templates/admin.html
diff --git a/app/auth.py b/app/auth.py
index d5a8b18..accb18c 100644
--- a/app/auth.py
+++ b/app/auth.py
@@ -243,3 +243,41 @@ def set_user_password(db_path: str, userid: int, newpass: str) -> bool:
''', (salt, newpass_hash, userid))
return True
+
+def is_admin(db_path: str, userid: int) -> bool:
+ with sqlite3.connect(db_path) as connection:
+ cursor = connection.cursor()
+
+ cursor.execute('''
+ SELECT COUNT(*) FROM Users
+ WHERE userid = ?
+ AND IS_ADMIN = 1
+ ''', (userid, ))
+
+ return cursor.fetchone()[0] == 1
+
+def get_users(db_path: str) -> dict:
+ with sqlite3.connect(db_path) as connection:
+ cursor = connection.cursor()
+
+ cursor.execute('''
+ SELECT userid, username, is_admin FROM Users
+ ''')
+
+ users = cursor.fetchall()
+
+ users = list(map(lambda x: {"userid": x[0], "username": x[1], "domains": [], "is_admin": bool(x[2])}, users))
+
+ for user in users:
+ cursor.execute('''
+ SELECT domain FROM Domains
+ WHERE userid = ?
+ ''', (user["userid"], ))
+
+ domains = cursor.fetchall()
+
+ domains = list(map(lambda x: x[0], domains))
+
+ user['domains'] = domains
+
+ return users
diff --git a/app/main.py b/app/main.py
index c00115c..56816c2 100644
--- a/app/main.py
+++ b/app/main.py
@@ -76,11 +76,15 @@ def logout():
def dashboard():
if session.get("USERID") is None:
return redirect("/")
- username = auth.get_username(DB_PATH, session.get("USERID"))
- domains = auth.get_user_domains(DB_PATH, session.get("USERID"))
- tokens = auth.get_user_tokens(DB_PATH, session.get("USERID"))
+ userid = session.get("USERID")
+ username = auth.get_username(DB_PATH, userid)
+ domains = auth.get_user_domains(DB_PATH, userid)
+ tokens = auth.get_user_tokens(DB_PATH, userid)
- return render_template("dashboard.html", username=username, domains=domains, tokens=tokens)
+ if auth.is_admin(DB_PATH, userid):
+ users = auth.get_users(DB_PATH)
+ return render_template("dashboard.html", username=username, domains=domains, tokens=tokens, is_admin=True, users=users)
+ return render_template("dashboard.html", username=username, domains=domains, tokens=tokens, is_admin=False)
diff --git a/app/templates/admin.html b/app/templates/admin.html
new file mode 100644
index 0000000..bf7d090
--- /dev/null
+++ b/app/templates/admin.html
@@ -0,0 +1,48 @@
+
+
+ Administration
+
+ Users:
+
+ | Username | Domains | Password | Admin | Email | Delete |
+
+
+
+ {% for user in users %}
+
+ | {{ user["username"] }} |
+ |
+ |
+ |
+ |
+ |
+
+ {% endfor %}
+
+
diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html
index 8e16c53..ffb6a6c 100644
--- a/app/templates/dashboard.html
+++ b/app/templates/dashboard.html
@@ -44,6 +44,6 @@
-
+ {% if is_admin %}{% include 'admin.html' %}{% endif %}