gonets/SRV/models/auth.py

62 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from pydantic import BaseModel
from typing import Optional
class UserCreate(BaseModel):
"""Модель созданного пользователя.
Атрибуты:
- ``username`` (str): Имя пользователя.
- ``password`` (str): Пароль пользователя.
- ``is_admin`` (bool): Флаг административного доступа.
"""
username: str
password: str
is_admin: bool = False
class UserLogin(BaseModel):
"""Модель авторизации пользователя.
Атрибуты:
- ``username`` (str): Имя пользователя.
- ``password`` (str): Пароль пользователя.
"""
username: str
password: str
class UserResponse(BaseModel):
"""Модель, используемая при возврате сведений о пользователе.
Атрибуты:
- ``id`` (int): Идентификатор пользователя.
- ``username`` (str): Имя пользователя.
- ``is_admin`` (bool): Флаг административного доступа.
"""
id: int
username: str
is_admin: bool
class Token(BaseModel):
"""Модель JWT-токена.
Атрибуты:
- ``access_token`` (str): Значение токена (в формате JWT).
- ``token_type`` (str): Тип токена (обычно ``bearer``).
- ``session_id`` (Optional[str]): Идентификатор сессии.
- ``user`` (Optional[UserResponse]): Данные пользователя, если включены в ответ.
"""
access_token: str
token_type: str
session_id: Optional[str] = None
user: Optional[UserResponse] = None