add registration page with nickname/phone fields and fix lateinit crashes
This commit is contained in:
@@ -75,6 +75,7 @@ class VideoRepository:
|
||||
id TEXT PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE COLLATE NOCASE,
|
||||
nickname TEXT NOT NULL,
|
||||
phone TEXT,
|
||||
password_hash TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
@@ -147,6 +148,14 @@ class VideoRepository:
|
||||
}
|
||||
if "user_id" not in attempt_columns:
|
||||
connection.execute("ALTER TABLE attempts ADD COLUMN user_id TEXT NOT NULL DEFAULT ''")
|
||||
|
||||
with self._connect() as connection:
|
||||
user_columns = {
|
||||
row["name"]
|
||||
for row in connection.execute("PRAGMA table_info(users)")
|
||||
}
|
||||
if "phone" not in user_columns:
|
||||
connection.execute("ALTER TABLE users ADD COLUMN phone TEXT")
|
||||
connection.execute("CREATE INDEX IF NOT EXISTS idx_attempts_user ON attempts(user_id)")
|
||||
|
||||
with self._connect() as connection:
|
||||
@@ -750,20 +759,28 @@ class VideoRepository:
|
||||
),
|
||||
)
|
||||
|
||||
def create_user(self, *, username: str, password: str, nickname: Optional[str]) -> Optional[Dict[str, Any]]:
|
||||
def create_user(
|
||||
self,
|
||||
*,
|
||||
username: str,
|
||||
password: str,
|
||||
nickname: Optional[str] = None,
|
||||
phone: Optional[str] = None,
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
user_id = uuid.uuid4().hex
|
||||
now = utc_now()
|
||||
try:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(
|
||||
"""
|
||||
INSERT INTO users (id, username, nickname, password_hash, created_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
INSERT INTO users (id, username, nickname, phone, password_hash, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
user_id,
|
||||
username.strip().lower(),
|
||||
(nickname or username).strip()[:80],
|
||||
(phone or "").strip()[:20] or None,
|
||||
hash_password(password),
|
||||
now,
|
||||
),
|
||||
@@ -783,7 +800,7 @@ class VideoRepository:
|
||||
def get_user_by_id(self, user_id: str) -> Optional[Dict[str, Any]]:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(
|
||||
"SELECT id, username, nickname, created_at FROM users WHERE id = ?",
|
||||
"SELECT id, username, nickname, phone, created_at FROM users WHERE id = ?",
|
||||
(user_id,),
|
||||
).fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
Reference in New Issue
Block a user