51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from datetime import date, timedelta
|
|
|
|
from pydantic_core import PydanticCustomError
|
|
from pydantic import BaseModel, EmailStr, ConfigDict, field_validator
|
|
from fastapi import Query
|
|
|
|
|
|
class SUserLogin(BaseModel):
|
|
email_or_username: EmailStr | str
|
|
password: str
|
|
|
|
|
|
class SUserRegister(BaseModel):
|
|
email: EmailStr
|
|
username: str = Query(None, min_length=2, max_length=30)
|
|
password: str = Query(None, min_length=8)
|
|
date_of_birth: date
|
|
|
|
@field_validator("date_of_birth")
|
|
@classmethod
|
|
def validate_date_of_birth(cls, input_date):
|
|
if date.today() - input_date < timedelta(days=365 * 16):
|
|
date_of_birth = date.today() - timedelta(days=365*16)
|
|
raise PydanticCustomError(
|
|
"date_input_error",
|
|
"date of birth might be earlier than {date_of_birth}",
|
|
{"date_of_birth": date_of_birth}
|
|
)
|
|
return input_date
|
|
|
|
|
|
class SUser(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
email: EmailStr
|
|
id: int
|
|
username: str
|
|
avatar_image: str
|
|
black_phoenix: bool
|
|
date_of_birth: date
|
|
date_of_registration: date
|
|
|
|
|
|
class SUserName(BaseModel):
|
|
username: str = Query(None, min_length=2, max_length=30)
|
|
|
|
|
|
class SUserPassword(BaseModel):
|
|
password: str = Query(None, min_length=8)
|
|
new_password: str = Query(None, min_length=8)
|
|
new_password2: str = Query(None, min_length=8)
|