generated from geekiot/python-template
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:
parent
305c31d4b0
commit
5070cf8191
1 changed files with 1 additions and 23 deletions
|
|
@ -1,5 +1,4 @@
|
|||
__all__ = [
|
||||
"check_registration_status",
|
||||
"verify_student"
|
||||
]
|
||||
|
||||
|
|
@ -13,32 +12,11 @@ from src.database.models import Student, TelegramUser
|
|||
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(
|
||||
tg_user: TelegramUser,
|
||||
name: str,
|
||||
student_id: int,
|
||||
group_id: int,
|
||||
group_id: str,
|
||||
session: AsyncSession,
|
||||
) -> VerificationStatus:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue