read log files from end, added user management
This commit is contained in:
@@ -452,6 +452,43 @@ def create_user(username, password_hash, role="viewer", is_active=1):
|
||||
return cursor.lastrowid
|
||||
|
||||
|
||||
def update_user_password(user_id, password_hash):
|
||||
with _tx():
|
||||
cursor = _conn.execute(
|
||||
"""
|
||||
UPDATE users
|
||||
SET password_hash = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(password_hash, user_id),
|
||||
)
|
||||
return cursor.rowcount
|
||||
|
||||
|
||||
def delete_user(user_id):
|
||||
with _tx():
|
||||
cursor = _conn.execute(
|
||||
"""
|
||||
DELETE FROM users
|
||||
WHERE id = ?
|
||||
""",
|
||||
(user_id,),
|
||||
)
|
||||
return cursor.rowcount
|
||||
|
||||
|
||||
def count_admin_users():
|
||||
with _lock:
|
||||
row = _conn.execute(
|
||||
"""
|
||||
SELECT COUNT(*) AS n
|
||||
FROM users
|
||||
WHERE role = 'admin' AND is_active = 1
|
||||
"""
|
||||
).fetchone()
|
||||
return row["n"]
|
||||
|
||||
|
||||
def count_users():
|
||||
with _lock:
|
||||
row = _conn.execute("SELECT COUNT(*) AS n FROM users").fetchone()
|
||||
|
||||
Reference in New Issue
Block a user