feat(trainer): add GitHub activity heatmap, 4-option quiz mode, active typing, and duplicate checks

This commit is contained in:
2026-09-23 10:02:29 +00:00
parent d31c77fdd0
commit 2294121777
16 changed files with 4318 additions and 685 deletions
+22
View File
@@ -108,9 +108,31 @@ def delete_session(token: str):
with get_db() as conn:
conn.execute("DELETE FROM sessions WHERE token = ?", (token,))
def change_user_password(user_id: int, old_password: str, new_password: str) -> tuple[bool, str]:
"""Changes password for the specified user after verifying old password."""
if not new_password or len(new_password) < 6:
return False, "Новый пароль должен содержать минимум 6 символов"
with get_db() as conn:
row = conn.execute(
"SELECT password_hash, salt FROM users WHERE id = ?",
(user_id,)
).fetchone()
if not row:
return False, "Пользователь не найден"
if not verify_password(old_password, row["password_hash"], row["salt"]):
return False, "Неверный текущий пароль"
pwd_hash, salt = hash_password(new_password)
conn.execute(
"UPDATE users SET password_hash = ?, salt = ? WHERE id = ?",
(pwd_hash, salt, user_id)
)
return True, "Пароль успешно изменён"
def ensure_admin_user():
"""Ensures at least one user exists; creates default admin from config if table empty."""
with get_db() as conn:
count = conn.execute("SELECT COUNT(*) FROM users").fetchone()[0]
if count == 0 and config.ADMIN_PASSWORD:
create_user(config.ADMIN_USERNAME, config.ADMIN_PASSWORD)