auth.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """Pydantic schemas - 用户认证"""
  2. from pydantic import BaseModel, Field
  3. from typing import Optional
  4. from datetime import datetime
  5. class LoginRequest(BaseModel):
  6. """登录请求"""
  7. username: str = Field(..., min_length=3, max_length=50)
  8. password: str = Field(..., min_length=6)
  9. class LoginResponse(BaseModel):
  10. """登录响应"""
  11. access_token: str
  12. token_type: str = "bearer"
  13. user_id: int
  14. username: str
  15. role: str
  16. real_name: Optional[str] = None
  17. class UserCreate(BaseModel):
  18. """创建用户请求"""
  19. username: str = Field(..., min_length=3, max_length=50)
  20. password: str = Field(..., min_length=6)
  21. real_name: Optional[str] = None
  22. phone: Optional[str] = None
  23. role: str
  24. region_id: Optional[int] = None
  25. class UserResponse(BaseModel):
  26. """用户响应"""
  27. id: int
  28. username: str
  29. real_name: Optional[str] = None
  30. phone: Optional[str] = None
  31. role: str
  32. region_id: Optional[int] = None
  33. is_active: bool
  34. created_at: datetime
  35. class Config:
  36. from_attributes = True
  37. class ChangePasswordRequest(BaseModel):
  38. """修改密码请求"""
  39. old_password: str
  40. new_password: str = Field(..., min_length=6)
  41. class ResetPasswordRequest(BaseModel):
  42. """重置密码请求(运营操作)"""
  43. user_id: int