68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
"""Pydantic schemas - 用户认证"""
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
"""登录请求"""
|
|
username: str = Field(..., min_length=3, max_length=50)
|
|
password: str = Field(..., min_length=6)
|
|
|
|
|
|
class LoginResponse(BaseModel):
|
|
"""登录响应"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
user_id: int
|
|
username: str
|
|
role: str
|
|
real_name: Optional[str] = None
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
"""创建用户请求"""
|
|
username: str = Field(..., min_length=3, max_length=50)
|
|
password: str = Field(..., min_length=6)
|
|
real_name: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
role: str
|
|
region_id: Optional[int] = None
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
"""用户响应"""
|
|
id: int
|
|
username: str
|
|
real_name: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
role: str
|
|
region_id: Optional[int] = None
|
|
is_active: bool
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class ChangePasswordRequest(BaseModel):
|
|
"""修改密码请求"""
|
|
old_password: str
|
|
new_password: str = Field(..., min_length=6)
|
|
|
|
|
|
class ProfileUpdateRequest(BaseModel):
|
|
"""当前用户个人信息更新(仅允许自助修改的字段)"""
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
phone_no: Optional[str] = Field(None, alias="phoneNo", max_length=11)
|
|
email: Optional[str] = Field(None, max_length=50)
|
|
sex: Optional[str] = Field(None, pattern=r"^[012]$")
|
|
remark: Optional[str] = Field(None, max_length=512)
|
|
avatar: Optional[str] = Field(None, alias="avatarUrl", max_length=512)
|
|
|
|
|
|
class ResetPasswordRequest(BaseModel):
|
|
"""重置密码请求(运营操作)"""
|
|
user_id: int
|