feat(verification): add infrastructure for user verification

- **FSM States:** Added `VerificationStates` to manage the dialog flow.
- **Services:** Implemented `get_or_create_user` and `verify_student` to encapsulate business logic.
- **Middleware Chain:** Refactored the middleware to a clean, sequential chain (`Database`, `TelegramUser`, `Registration`) where each has a single responsibility.
- **Verification Status:** Introduced a `VerificationStatus` enum for clear and type-safe results from the verification service.
This commit is contained in:
Vladimir 2025-11-04 19:26:33 +05:00
parent 305c31d4b0
commit 5070cf8191

View file

@ -1,5 +1,4 @@
__all__ = [ __all__ = [
"check_registration_status",
"verify_student" "verify_student"
] ]
@ -13,32 +12,11 @@ from src.database.models import Student, TelegramUser
from .types.verification_statuses import VerificationStatus from .types.verification_statuses import VerificationStatus
async def check_registration_status(
tg_id: int,
session: AsyncSession,
) -> bool:
"""
Checks if a tg user is linked to a university member.
Args:
tg_id (int): user's telegram id.
session (AsyncSession): database session.
Returns:
bool: True if the user is registered (linked), otherwise False.
"""
query = select(TelegramUser).where(TelegramUser.id == tg_id)
result = await session.execute(query)
user = result.scalar_one_or_none()
return user is not None and user.university_member_id is not None
async def verify_student( async def verify_student(
tg_user: TelegramUser, tg_user: TelegramUser,
name: str, name: str,
student_id: int, student_id: int,
group_id: int, group_id: str,
session: AsyncSession, session: AsyncSession,
) -> VerificationStatus: ) -> VerificationStatus:
""" """