auth.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from datetime import datetime
  4. from typing import Optional, Any, List
  5. from pydantic import Field
  6. from pydantic.main import BaseModel
  7. from schemas.base import DetailMixin
  8. class SwaggerToken(BaseModel):
  9. access_token: str
  10. token_type: str
  11. class Token(DetailMixin):
  12. pass
  13. class TokenPayload(BaseModel):
  14. sub: Optional[Any] = None
  15. class AdminLoginInfo(BaseModel):
  16. username: str = Field(..., description="用户名")
  17. password: str = Field(..., description="密码")
  18. class UserLoginInfo(BaseModel):
  19. utype: int = Field(..., description="用户类型,1=教师,2=学生")
  20. username: str = Field(..., description="用户名")
  21. password: str = Field(..., description="密码")
  22. class UserProfileItem(BaseModel):
  23. id: int = Field(..., description="用户ID")
  24. username: str = Field(..., description="账号")
  25. name: str = Field(..., description="姓名")
  26. role: Optional[str] = Field(None, description="职务")
  27. pcodes: Optional[List[Any]] = []
  28. class Config:
  29. orm_mode = True
  30. anystr_strip_whitespace = True
  31. class CurrentUserProfile(DetailMixin):
  32. data: Optional[UserProfileItem] = None
  33. class LastLoginInfo(BaseModel):
  34. is_first_login: Optional[bool] = Field(None, description="是否首次登录")
  35. last_login_ip: Optional[str] = Field(None, description="最后登录IP")
  36. last_login_time: Optional[datetime] = Field(None, description="最后登录时间")
  37. class EditPwdInfo(BaseModel):
  38. code: str = Field(..., description="验证码")
  39. oldpwd: str = Field(..., description="原始密码")
  40. newpwd: str = Field(..., max_length=6, description="新密码")
  41. class Config:
  42. anystr_strip_whitespace = True
  43. class UpdatePassword(BaseModel):
  44. password: str
  45. is_first_login: bool = None