Add username login and expiring reset links so accounts stay recoverable.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0277039b07
commit
89d149684e
24 files changed
+1595
-67
No files matched your search
+50
-1
@@ -56,7 +56,35 @@ SQLITE_HISTORY_MIGRATIONS = (
|
||||
_PROFILE_COLUMNS = {
|
||||
"status": "TEXT NOT NULL DEFAULT 'active'",
|
||||
"tier_id": "TEXT NOT NULL DEFAULT 'local'",
|
||||
"username": "TEXT",
|
||||
"secondary_email": "TEXT",
|
||||
"email_verified_at": "TEXT",
|
||||
"secondary_email_verified_at": "TEXT",
|
||||
"pending_email": "TEXT",
|
||||
"pending_secondary_email": "TEXT",
|
||||
}
|
||||
_ACCOUNT_INDEXES = (
|
||||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS profiles_username_lower_idx
|
||||
ON profiles (lower(username))
|
||||
WHERE username IS NOT NULL AND username <> ''
|
||||
""",
|
||||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS profiles_secondary_email_lower_idx
|
||||
ON profiles (lower(secondary_email))
|
||||
WHERE secondary_email IS NOT NULL AND secondary_email <> ''
|
||||
""",
|
||||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS profiles_pending_email_lower_idx
|
||||
ON profiles (lower(pending_email))
|
||||
WHERE pending_email IS NOT NULL AND pending_email <> ''
|
||||
""",
|
||||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS profiles_pending_secondary_email_lower_idx
|
||||
ON profiles (lower(pending_secondary_email))
|
||||
WHERE pending_secondary_email IS NOT NULL AND pending_secondary_email <> ''
|
||||
""",
|
||||
)
|
||||
_PROMPT_COLUMNS = {
|
||||
"description": "TEXT NOT NULL DEFAULT ''",
|
||||
"category": "TEXT NOT NULL DEFAULT 'uncategorized'",
|
||||
@@ -227,6 +255,27 @@ def _mark(conn: Any, migration_id: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _ensure_account_identifiers(conn: Any) -> None:
|
||||
"""Add login identifiers on existing SQLite files and grandfather current emails once."""
|
||||
_ensure_columns(conn, "profiles", _PROFILE_COLUMNS)
|
||||
for statement in _ACCOUNT_INDEXES:
|
||||
conn.execute(statement)
|
||||
row = conn.execute(
|
||||
"SELECT id FROM schema_migrations WHERE id = ?",
|
||||
("027_account_identifiers",),
|
||||
).fetchone()
|
||||
if row:
|
||||
return
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE profiles
|
||||
SET email_verified_at = COALESCE(created, datetime('now'))
|
||||
WHERE email_verified_at IS NULL OR email_verified_at = ''
|
||||
"""
|
||||
)
|
||||
_mark(conn, "027_account_identifiers")
|
||||
|
||||
|
||||
def _seed_platform(conn: Any) -> None:
|
||||
seed = json.loads(SEED_PATH.read_text(encoding="utf-8"))
|
||||
for tier in seed.get("tiers", []):
|
||||
@@ -582,7 +631,7 @@ def init_db() -> None:
|
||||
|
||||
_ensure_columns(conn, "provider_settings", {"profile_id": "TEXT"})
|
||||
seed_provider_settings(conn)
|
||||
_ensure_columns(conn, "profiles", _PROFILE_COLUMNS)
|
||||
_ensure_account_identifiers(conn)
|
||||
_ensure_columns(conn, "conversations", _CONVERSATION_COLUMNS)
|
||||
_ensure_columns(conn, "journal_days", _JOURNAL_DAY_COLUMNS)
|
||||
_ensure_columns(conn, "journal_drafts", _JOURNAL_DRAFT_COLUMNS)
|
||||
|
||||
Reference in new issue
Block a user