Files
FastapiAdmin/backend/app/api/v1/module_system/auth/schema.py
T
zhangtao 3c12fa56eb refactor: 移除多租户和客户相关代码及功能
refactor: 统一状态字段为字符串类型并更新相关组件
refactor: 更新模型基类移除租户和客户相关字段
refactor: 简化数据权限控制逻辑
refactor: 优化类型注解使用Python 3.10+语法
refactor: 清理无用导入和注释
docs: 更新文档移除多租户相关内容
2025-12-01 00:36:05 +08:00

59 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
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: datetime | int = Field(..., description='过期时间')
@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编码的验证码图片')