130 lines
2.8 KiB
Python
130 lines
2.8 KiB
Python
from datetime import date, timedelta, datetime, time
|
|
|
|
from pydantic_core import PydanticCustomError
|
|
from pydantic import BaseModel, EmailStr, ConfigDict, field_validator, HttpUrl
|
|
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)
|
|
password2: 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}
|
|
)
|
|
elif datetime.combine(input_date, time.min).timestamp() < datetime(year=1924, month=1, day=1).timestamp():
|
|
date_of_birth = date(1924, 1, 1)
|
|
raise PydanticCustomError(
|
|
"date_input_error", "date of birth might be later than {date_of_birth}", {"date_of_birth": date_of_birth}
|
|
)
|
|
return input_date
|
|
|
|
|
|
class SUserResponse(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
email: EmailStr
|
|
id: int
|
|
username: str
|
|
black_phoenix: bool
|
|
avatar_image: HttpUrl
|
|
avatar_hex: str
|
|
date_of_birth: date
|
|
date_of_registration: date
|
|
|
|
|
|
class SUser(BaseModel):
|
|
id: int
|
|
email: str
|
|
username: str
|
|
hashed_password: str
|
|
role: int
|
|
black_phoenix: bool
|
|
avatar_image: HttpUrl
|
|
avatar_hex: str
|
|
date_of_birth: date
|
|
date_of_registration: date
|
|
|
|
|
|
class SUserPasswordRecover(BaseModel):
|
|
email: EmailStr
|
|
|
|
|
|
class SUserCode(BaseModel):
|
|
user_code: str
|
|
|
|
|
|
class SUserPasswordChange(BaseModel):
|
|
user_id: int
|
|
password1: str = Query(None, min_length=8)
|
|
password2: str = Query(None, min_length=8)
|
|
|
|
|
|
class SUserSendConfirmationCode(BaseModel):
|
|
email: EmailStr
|
|
current_password: str = Query(None, min_length=8)
|
|
|
|
|
|
class SUserChangeData(BaseModel):
|
|
verification_code: str
|
|
email: EmailStr
|
|
username: str = Query(None, min_length=2, max_length=30)
|
|
new_password: str | None = Query(None, min_length=8)
|
|
avatar_url: HttpUrl
|
|
|
|
|
|
class SRecoverEmailSent(BaseModel):
|
|
recover_email_sent: bool
|
|
|
|
|
|
class SEmailVerification(BaseModel):
|
|
email_verification: bool
|
|
|
|
|
|
class SUserToken(BaseModel):
|
|
access_token: str
|
|
|
|
|
|
class SConfirmPasswordRecovery(BaseModel):
|
|
user_id: int
|
|
|
|
|
|
class SPasswordRecovered(BaseModel):
|
|
username: str
|
|
|
|
|
|
class SCreateInvitationLink(BaseModel):
|
|
invitation_link: HttpUrl
|
|
|
|
|
|
class SUserAddedToChat(BaseModel):
|
|
user_added_to_chat: bool
|
|
|
|
|
|
class SUserAvatarUrl(BaseModel):
|
|
avatar_url: HttpUrl
|
|
|
|
|
|
class SUserAvatars(BaseModel):
|
|
user_avatars: list[SUserAvatarUrl] | None
|
|
|
|
|
|
class SUsername(BaseModel):
|
|
username: str = Query(None, min_length=2, max_length=30)
|
|
|
|
|
|
class SEmail(BaseModel):
|
|
email: EmailStr
|