Files
FastapiAdmin/backend/app/api/v1/module_system/auth/schema.py
T
zhangtao 42fa1944e0 refactor: 统一状态字段类型为字符串并移除租户配额功能
- 将多个模型中的status字段从布尔值改为字符串类型
- 移除租户配额相关字段和功能
- 优化任务调度器中的租户上下文处理
- 清理无用代码和注释
2025-11-28 00:59:38 +08:00

61 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
from typing import Optional, Union
from datetime import datetime
from pydantic import ConfigDict, Field, BaseModel, model_validator
from sqlalchemy.ext.asyncio import AsyncSession
from ..user.model import UserModel
class AuthSchema(BaseModel):
"""权限认证模型"""
model_config = ConfigDict(arbitrary_types_allowed=True)
user: UserModel | None = Field(default=None, description='用户信息')
check_data_scope: bool = Field(default=True, description='是否检查数据权限')
db: AsyncSession = Field(description='数据库会话')
class JWTPayloadSchema(BaseModel):
"""JWT载荷模型"""
sub: str = Field(..., description='用户登录信息')
is_refresh: bool = Field(default=False, description='是否刷新token')
exp: Union[datetime, int] = Field(..., description='过期时间')
tenant_id: Optional[int] = Field(default=None, description='租户ID')
@model_validator(mode='after')
def validate_fields(self):
if not self.sub or len(self.sub.strip()) == 0:
raise ValueError("会话编号不能为空")
return self
class JWTOutSchema(BaseModel):
"""JWT响应模型"""
model_config = ConfigDict(from_attributes=True)
access_token: str = Field(..., min_length=1, description='访问token')
refresh_token: str = Field(..., min_length=1, description='刷新token')
token_type: str = Field(default='Bearer', description='token类型')
expires_in: int = Field(..., gt=0, description='过期时间(秒)')
class RefreshTokenPayloadSchema(BaseModel):
"""刷新Token载荷模型"""
refresh_token: str = Field(..., min_length=1, description='刷新token')
class LogoutPayloadSchema(BaseModel):
"""退出登录载荷模型"""
token: str = Field(..., min_length=1, description='token')
class CaptchaOutSchema(BaseModel):
"""验证码响应模型"""
model_config = ConfigDict(from_attributes=True)
enable: bool = Field(default=True, description='是否启用验证码')
key: str = Field(..., min_length=1, description='验证码唯一标识')
img_base: str = Field(..., min_length=1, description='Base64编码的验证码图片')