05/24 Fix bugs

This commit is contained in:
2026-05-24 17:27:45 -04:00
parent cd63d5a020
commit 136b0e5635
14 changed files with 158 additions and 68 deletions
+16 -19
View File
@@ -3,6 +3,7 @@ models.py — Data-access layer for all entities.
Ported 1-for-1 from the desktop version; all function signatures preserved.
"""
import datetime
import hashlib
import logging
import bcrypt
@@ -99,7 +100,6 @@ def check_login_allowed(username: str) -> tuple:
return True, 0
locked_until = row.get("locked_until")
if locked_until:
import datetime
now = datetime.datetime.now()
if now < locked_until:
remaining = int((locked_until - now).total_seconds())
@@ -113,7 +113,6 @@ def check_login_allowed(username: str) -> tuple:
def record_failed_attempt(username: str, ip_address: str = None):
conn = None
try:
import datetime
conn = get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT id, failed_attempts FROM users WHERE username=%s", (username,))
@@ -678,25 +677,23 @@ def get_activity_log(limit=200, search: str = ""):
try:
conn = get_connection()
cur = conn.cursor(dictionary=True)
where = ""
params = []
if search:
where = "WHERE al.action LIKE %s OR u.username LIKE %s OR al.entity LIKE %s OR al.detail LIKE %s"
like = f"%{search}%"
params.extend([like, like, like, like])
params.append(limit)
cur.execute(
f"""
SELECT al.id, al.user_id, al.action, al.entity, al.entity_id,
al.detail, al.logged_at AS created_at, u.username
FROM activity_log al
LEFT JOIN users u ON u.id = al.user_id
{where}
ORDER BY al.logged_at DESC
LIMIT %s
""",
params,
sql = (
"SELECT al.id, al.user_id, al.action, al.entity, al.entity_id,"
" al.detail, al.logged_at AS created_at, u.username"
" FROM activity_log al"
" LEFT JOIN users u ON u.id = al.user_id"
)
if search:
sql += (
" WHERE al.action LIKE %s OR u.username LIKE %s"
" OR al.entity LIKE %s OR al.detail LIKE %s"
)
like = f"%{search}%"
params.extend([like, like, like, like])
sql += " ORDER BY al.logged_at DESC LIMIT %s"
params.append(limit)
cur.execute(sql, params)
rows = cur.fetchall()
cur.close()
return rows