- Improved formatting and readability in config.py and other files by adding line breaks. - Introduced INIT_DATA_MAX_AGE_SECONDS to enforce replay protection for Telegram initData. - Updated validate_init_data function to include max_age_seconds parameter for validation. - Enhanced API to reject old initData based on the new max_age_seconds setting. - Added tests for auth_date expiry and validation of initData in test_telegram_auth.py. - Updated README with details on the new INIT_DATA_MAX_AGE_SECONDS configuration.
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Initial users and duties tables
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2025-02-17
|
|
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision: str = "001"
|
|
down_revision: Union[str, None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"users",
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column("telegram_user_id", sa.BigInteger(), nullable=False),
|
|
sa.Column("full_name", sa.Text(), nullable=False),
|
|
sa.Column("username", sa.Text(), nullable=True),
|
|
sa.Column("first_name", sa.Text(), nullable=True),
|
|
sa.Column("last_name", sa.Text(), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("telegram_user_id"),
|
|
)
|
|
op.create_table(
|
|
"duties",
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("start_at", sa.Text(), nullable=False),
|
|
sa.Column("end_at", sa.Text(), nullable=False),
|
|
sa.ForeignKeyConstraint(
|
|
["user_id"],
|
|
["users.id"],
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("duties")
|
|
op.drop_table("users")
|