423baff73b
- Docker bridge 网络隔离(8000 端口封死) - Gunicorn 4 Worker 多进程 - Alembic 数据库迁移基线 - 日志轮转 20m×3 - JWT 密钥 + DB 密码 + CORS 收紧 - 3-2-1 备份链路(NAS + R740-B 冷备) - 连接池 pool_pre_ping + pool_recycle=3600
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""
|
|
Auth 相关 Pydantic V2 Schema
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# ── 登录请求 ──────────────────────────────────────────────
|
|
class LoginRequest(BaseModel):
|
|
username: str = Field(..., min_length=1, max_length=50, examples=["admin"])
|
|
password: str = Field(..., min_length=1, max_length=128, examples=["123456"])
|
|
|
|
|
|
# ── Token 响应 ────────────────────────────────────────────
|
|
class TokenResponse(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
# ── 当前用户信息(从 JWT 解析 + DB 查表组合而来)──────────
|
|
class CurrentUserPayload(BaseModel):
|
|
"""注入到 Dependency 中的用户权限上下文"""
|
|
user_id: uuid.UUID
|
|
username: str
|
|
real_name: str | None = None
|
|
dept_id: uuid.UUID | None = None
|
|
dept_name: str | None = None
|
|
role_id: uuid.UUID | None = None
|
|
role_name: str | None = None
|
|
data_scope: str = "self" # all / dept_and_sub / self
|
|
menu_keys: list[str] = Field(default_factory=list)
|
|
|
|
|
|
# ── 修改密码请求 ────────────────────────────────────
|
|
class UpdatePasswordRequest(BaseModel):
|
|
old_password: str = Field(..., min_length=1, max_length=128)
|
|
new_password: str = Field(..., min_length=6, max_length=128, description="新密码至少6位")
|