- 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.
46 lines
806 B
Python
46 lines
806 B
Python
"""Pydantic schemas for API and validation."""
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
full_name: str
|
|
username: str | None = None
|
|
first_name: str | None = None
|
|
last_name: str | None = None
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
telegram_user_id: int
|
|
|
|
|
|
class UserInDb(UserBase):
|
|
id: int
|
|
telegram_user_id: int
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class DutyBase(BaseModel):
|
|
user_id: int
|
|
start_at: str # ISO 8601
|
|
end_at: str # ISO 8601
|
|
|
|
|
|
class DutyCreate(DutyBase):
|
|
pass
|
|
|
|
|
|
class DutyInDb(DutyBase):
|
|
id: int
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class DutyWithUser(DutyInDb):
|
|
"""Duty with full_name for calendar display."""
|
|
|
|
full_name: str
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|