This commit is contained in:
1 parent
0cf6f62e23
commit
0c12ce5f33
5 files changed
+109
-1
No files matched your search
@@ -91,6 +91,8 @@ def initialize_database() -> None:
|
||||
connection.execute("ALTER TABLE users ADD COLUMN is_active INTEGER NOT NULL DEFAULT 1")
|
||||
if "last_login_at" not in user_columns:
|
||||
connection.execute("ALTER TABLE users ADD COLUMN last_login_at TEXT")
|
||||
if "session_token" not in user_columns:
|
||||
connection.execute("ALTER TABLE users ADD COLUMN session_token TEXT")
|
||||
interaction_columns = {
|
||||
row["name"]
|
||||
for row in connection.execute("PRAGMA table_info(user_interactions)").fetchall()
|
||||
@@ -148,6 +150,7 @@ def row_to_user(row: sqlite3.Row) -> dict[str, object]:
|
||||
"createdAt": row["created_at"],
|
||||
"updatedAt": row["updated_at"],
|
||||
"lastLoginAt": row["last_login_at"] or "",
|
||||
"sessionToken": row["session_token"] or "",
|
||||
}
|
||||
|
||||
|
||||
@@ -391,6 +394,20 @@ def mark_user_login(user_id: int) -> None:
|
||||
)
|
||||
|
||||
|
||||
def rotate_user_session_token(user_id: int, session_token: str) -> None:
|
||||
with get_connection() as connection:
|
||||
connection.execute(
|
||||
"""
|
||||
UPDATE users
|
||||
SET session_token = ?,
|
||||
last_login_at = CURRENT_TIMESTAMP,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
""",
|
||||
(session_token, user_id),
|
||||
)
|
||||
|
||||
|
||||
def register_user_with_activation(*, username: str, password_hash: str, activation_code: str) -> dict[str, object]:
|
||||
clean_username = repair_mojibake_text(username)
|
||||
clean_code = activation_code.strip().upper()
|
||||
|
||||
Reference in new issue
Block a user