add password authentication for bot users
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user