60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""
|
|
用户相关的 Pydantic Schema
|
|
"""
|
|
from pydantic import BaseModel, Field, EmailStr
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
"""用户基础 Schema"""
|
|
username: str = Field(..., min_length=3, max_length=50, description="用户名")
|
|
nickname: Optional[str] = Field(None, max_length=50, description="昵称")
|
|
email: Optional[EmailStr] = Field(None, description="邮箱")
|
|
phone: Optional[str] = Field(None, max_length=20, description="手机号")
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
"""创建用户 Schema"""
|
|
password: str = Field(..., min_length=6, max_length=50, description="密码")
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
"""更新用户 Schema"""
|
|
nickname: Optional[str] = None
|
|
email: Optional[EmailStr] = None
|
|
phone: Optional[str] = None
|
|
avatar: Optional[str] = None
|
|
|
|
|
|
class UserResponse(UserBase):
|
|
"""用户响应 Schema"""
|
|
id: int
|
|
avatar: Optional[str] = None
|
|
status: int
|
|
is_superuser: int
|
|
last_login_at: Optional[datetime] = None
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
"""用户登录 Schema"""
|
|
username: str = Field(..., description="用户名")
|
|
password: str = Field(..., description="密码")
|
|
|
|
|
|
class Token(BaseModel):
|
|
"""Token 响应 Schema"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
user: UserResponse
|
|
|
|
|
|
class ChangePassword(BaseModel):
|
|
"""修改密码 Schema"""
|
|
old_password: str = Field(..., description="旧密码")
|
|
new_password: str = Field(..., min_length=6, max_length=50, description="新密码")
|