"""认证相关数据模型""" from datetime import datetime from pydantic import BaseModel, Field class LoginRequest(BaseModel): """登录请求""" username: str = Field(description="用户名") password: str = Field(description="明文密码") class RegisterRequest(BaseModel): """注册请求""" username: str = Field(min_length=3, max_length=32, description="用户名(3-32 字符)") password: str = Field(min_length=6, max_length=128, description="密码(6-128 字符)") class AuthUser(BaseModel): """对外暴露的用户信息(不含密码)""" username: str = Field(description="用户名") role: str = Field(default="user", description="角色:admin | user") created_at: datetime = Field(description="创建时间") class StoredUser(AuthUser): """存储层用户:含密码哈希,仅内部使用,不对外暴露""" hashed_password: str = Field(description="bcrypt 密码哈希") class TokenResponse(BaseModel): """登录成功返回的 token 信息""" access_token: str = Field(description="JWT access token") token_type: str = Field(default="bearer", description="token 类型") expires_in: int = Field(description="token 有效期(秒)") user: AuthUser = Field(description="登录用户信息")