mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-26 06:19:07 +00:00
67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from datetime import datetime
|
|
from typing import Annotated
|
|
|
|
from pydantic import ConfigDict, Field, HttpUrl, PlainSerializer
|
|
|
|
from backend.common.enums import StatusType
|
|
from backend.common.schema import CustomEmailStr, CustomPhoneNumber, SchemaBase, ser_string
|
|
|
|
|
|
class AuthSchemaBase(SchemaBase):
|
|
"""用户认证基础模型"""
|
|
|
|
username: str = Field(description='用户名')
|
|
password: str = Field(description='密码')
|
|
|
|
|
|
class AuthLoginParam(AuthSchemaBase):
|
|
"""用户登录参数"""
|
|
|
|
uuid: str | None = Field(None, description='验证码 UUID')
|
|
captcha: str | None = Field(None, description='验证码')
|
|
|
|
|
|
class AddUserParam(AuthSchemaBase):
|
|
"""添加用户参数"""
|
|
|
|
nickname: str | None = Field(None, description='昵称')
|
|
email: CustomEmailStr | None = Field(None, description='邮箱')
|
|
phone: CustomPhoneNumber | None = Field(None, description='手机号码')
|
|
|
|
|
|
class ResetPasswordParam(SchemaBase):
|
|
"""重置密码参数"""
|
|
|
|
old_password: str = Field(description='旧密码')
|
|
new_password: str = Field(description='新密码')
|
|
confirm_password: str = Field(description='确认密码')
|
|
|
|
|
|
class UserInfoSchemaBase(SchemaBase):
|
|
"""用户信息基础模型"""
|
|
|
|
username: str = Field(description='用户名')
|
|
nickname: str = Field(description='昵称')
|
|
avatar: Annotated[HttpUrl, PlainSerializer(ser_string)] | None = Field(None, description='头像地址')
|
|
email: CustomEmailStr | None = Field(None, description='邮箱')
|
|
phone: CustomPhoneNumber | None = Field(None, description='手机号')
|
|
|
|
|
|
class UpdateUserParam(UserInfoSchemaBase):
|
|
"""更新用户参数"""
|
|
|
|
|
|
class GetUserInfoDetail(UserInfoSchemaBase):
|
|
"""用户信息详情"""
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int = Field(description='用户 ID')
|
|
uuid: str = Field(description='用户 UUID')
|
|
status: StatusType = Field(description='状态')
|
|
is_superuser: bool = Field(description='是否超级管理员')
|
|
is_staff: bool = Field(description='是否管理员')
|
|
is_multi_login: bool = Field(description='是否允许多端登录')
|
|
join_time: datetime = Field(description='加入时间')
|
|
last_login_time: datetime | None = Field(None, description='最后登录时间')
|