feat: email and password login
This commit is contained in:
@@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from ..models import SecurityThrottle
|
||||
|
||||
EMAIL_CODE_VERIFY_SCOPE = "email_code_verify"
|
||||
EMAIL_PASSWORD_LOGIN_SCOPE = "email_password_login"
|
||||
PROMO_CODE_APPLY_SCOPE = "promo_code_apply"
|
||||
|
||||
|
||||
|
||||
@@ -744,6 +744,16 @@ def _migration_0022_add_indexes_for_admin_reports(connection: Connection) -> Non
|
||||
)
|
||||
|
||||
|
||||
def _migration_0023_add_email_password_auth_fields(connection: Connection) -> None:
|
||||
inspector = inspect(connection)
|
||||
columns: Set[str] = {col["name"] for col in inspector.get_columns("users")}
|
||||
|
||||
if "password_hash" not in columns:
|
||||
connection.execute(text("ALTER TABLE users ADD COLUMN password_hash VARCHAR"))
|
||||
if "password_set_at" not in columns:
|
||||
connection.execute(text("ALTER TABLE users ADD COLUMN password_set_at TIMESTAMPTZ"))
|
||||
|
||||
|
||||
MIGRATIONS: List[Migration] = [
|
||||
Migration(
|
||||
id="0001_add_channel_subscription_fields",
|
||||
@@ -866,6 +876,11 @@ MIGRATIONS: List[Migration] = [
|
||||
description="Indexes to speed up financial stats and admin log queries",
|
||||
upgrade=_migration_0022_add_indexes_for_admin_reports,
|
||||
),
|
||||
Migration(
|
||||
id="0023_add_email_password_auth_fields",
|
||||
description="Store hashed passwords for optional email password login",
|
||||
upgrade=_migration_0023_add_email_password_auth_fields,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ class User(Base):
|
||||
username = Column(String, nullable=True, index=True)
|
||||
email = Column(String, nullable=True, unique=True, index=True)
|
||||
email_verified_at = Column(DateTime(timezone=True), nullable=True)
|
||||
password_hash = Column(String, nullable=True)
|
||||
password_set_at = Column(DateTime(timezone=True), nullable=True)
|
||||
telegram_id = Column(BigInteger, nullable=True, unique=True, index=True)
|
||||
telegram_photo_url = Column(Text, nullable=True)
|
||||
first_name = Column(String, nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user