add password authentication for bot users

This commit is contained in:
kandrusyak
2026-07-25 15:57:30 +03:00
parent c04fb9480b
commit 053b124a9a
8 changed files with 210 additions and 0 deletions

View File

@@ -55,6 +55,11 @@ class AssistantStorage:
updated_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS authorized_users (
user_id INTEGER PRIMARY KEY,
authorized_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS memories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
@@ -127,6 +132,25 @@ class AssistantStorage:
"ALTER TABLE user_settings ADD COLUMN yandex_model TEXT"
)
def is_user_authorized(self, user_id: int) -> bool:
with self._connection() as connection:
row = connection.execute(
"SELECT 1 FROM authorized_users WHERE user_id = ?",
(user_id,),
).fetchone()
return row is not None
def authorize_user(self, user_id: int) -> None:
with self._connection() as connection:
connection.execute(
"""
INSERT INTO authorized_users(user_id, authorized_at)
VALUES (?, ?)
ON CONFLICT(user_id) DO NOTHING
""",
(user_id, to_utc_iso(utc_now())),
)
def add_conversation_exchange(
self,
user_id: int,