nspotapov/back (#4)
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
58
backend/app/schemas/user.py
Normal file
58
backend/app/schemas/user.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from typing import Self
|
||||
|
||||
from pydantic import (
|
||||
Field,
|
||||
model_validator,
|
||||
)
|
||||
|
||||
from app.auth.utils import get_password_hash
|
||||
from app.models.user import UserRole
|
||||
from .general import EmailModel
|
||||
|
||||
|
||||
class UserBase(EmailModel):
|
||||
name: str = Field(
|
||||
min_length=3, max_length=50, description="Имя, от 3 до 50 символов"
|
||||
)
|
||||
surname: str = Field(
|
||||
min_length=3, max_length=50, description="Фамилия, от 3 до 50 символов"
|
||||
)
|
||||
patronymic: str = Field(
|
||||
min_length=3,
|
||||
max_length=50,
|
||||
description="Отчество, от 3 до 50 символов",
|
||||
default=None,
|
||||
)
|
||||
role: UserRole = Field(description="Роль пользователя в системе", default=UserRole.GUEST)
|
||||
|
||||
|
||||
class SUserRegister(UserBase):
|
||||
password: str = Field(
|
||||
min_length=5, max_length=50, description="Пароль, от 5 до 50 знаков"
|
||||
)
|
||||
confirm_password: str = Field(
|
||||
min_length=5, max_length=50, description="Повторите пароль"
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def check_password(self) -> Self:
|
||||
if self.password != self.confirm_password:
|
||||
raise ValueError("Пароли не совпадают")
|
||||
self.password = get_password_hash(
|
||||
self.password
|
||||
) # хешируем пароль до сохранения в базе данных
|
||||
return self
|
||||
|
||||
|
||||
class SUserAddDB(UserBase):
|
||||
password: str = Field(min_length=5, description="Пароль в формате HASH-строки")
|
||||
|
||||
|
||||
class SUserAuth(EmailModel):
|
||||
password: str = Field(
|
||||
min_length=5, max_length=50, description="Пароль, от 5 до 50 знаков"
|
||||
)
|
||||
|
||||
|
||||
class SUserInfo(UserBase):
|
||||
id: int = Field(description="Идентификатор пользователя")
|
||||
Reference in New Issue
Block a user