user.py
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
文件名: app/schemas/user.py
职责: 用户认证相关 Pydantic 校验模型。
注意: 不要删除这个注释。
"""
from typing import Optional
from pydantic import BaseModel, Field, field_validator
class UserBase(BaseModel):
username: str = Field(..., min_length=1, max_length=50)
class UserResponse(UserBase):
id: int
is_active: bool
is_superuser: bool
class Config:
from_attributes = True
class LoginRequest(BaseModel):
username: str = Field(..., min_length=1, max_length=50)
password: str = Field(..., min_length=1, max_length=50)
captcha_code: Optional[str] = Field(None, max_length=10)
captcha_token: Optional[str] = Field(None, max_length=64)
remember: bool = Field(False)
class LoginResponse(BaseModel):
status: str
message: str
need_captcha: bool = False
username: Optional[str] = None
class CaptchaRequiredResponse(BaseModel):
required: bool
class TokenPayload(BaseModel):
sub: str
exp: int