add admin user management: list and delete registered users

This commit is contained in:
2026-08-31 15:54:30 +08:00
parent 4a61afd5a9
commit 3652ebda07
5 changed files with 133 additions and 1 deletions

View File

@@ -805,6 +805,25 @@ class VideoRepository:
).fetchone()
return dict(row) if row else None
def list_users(self) -> List[Dict[str, Any]]:
with self._connect() as connection:
rows = connection.execute(
"""
SELECT u.id, u.username, u.nickname, u.phone, u.created_at,
COUNT(DISTINCT e.video_hash) AS enrollment_count
FROM users u
LEFT JOIN enrollments e ON e.user_id = u.id
GROUP BY u.id
ORDER BY u.created_at DESC
"""
).fetchall()
return [dict(row) for row in rows]
def delete_user(self, user_id: str) -> bool:
with self._connect() as connection:
cursor = connection.execute("DELETE FROM users WHERE id = ?", (user_id,))
return cursor.rowcount > 0
def authenticate_user(self, username: str, password: str) -> Optional[Dict[str, Any]]:
with self._connect() as connection:
row = connection.execute(