user.py 1.05 KB
# -*- 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