add admin user list
This commit is contained in:
+38
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user