modify: auth 插件
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
模型导出 — auth
|
||||
自动生成,请勿手动修改
|
||||
"""
|
||||
|
||||
from .pydantic import AuthResponse
|
||||
from .pydantic import ChangePasswordPostRequest
|
||||
from .pydantic import ChangePasswordPostResponse
|
||||
from .pydantic import LoginPostRequest
|
||||
from .pydantic import LoginPostResponse
|
||||
from .pydantic import MeGetRequest
|
||||
from .pydantic import MeGetResponse
|
||||
from .pydantic import RegisterPostRequest
|
||||
from .pydantic import RegisterPostResponse
|
||||
from .pydantic import UpdateProfilePostRequest
|
||||
from .pydantic import UpdateProfilePostResponse
|
||||
|
||||
from .auth import Users
|
||||
|
||||
__all__ = [
|
||||
"AuthResponse",
|
||||
"ChangePasswordPostRequest",
|
||||
"ChangePasswordPostResponse",
|
||||
"LoginPostRequest",
|
||||
"LoginPostResponse",
|
||||
"MeGetRequest",
|
||||
"MeGetResponse",
|
||||
"RegisterPostRequest",
|
||||
"RegisterPostResponse",
|
||||
"UpdateProfilePostRequest",
|
||||
"UpdateProfilePostResponse",
|
||||
"Users",
|
||||
]
|
||||
@@ -0,0 +1,102 @@
|
||||
import os
|
||||
import time
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from sqlmodel import Field, SQLModel, Column
|
||||
from sqlalchemy import func, DateTime
|
||||
|
||||
|
||||
def primary_key_create():
|
||||
return f"{uuid4()}_{os.getpid()}_{int(time.time())}"
|
||||
|
||||
|
||||
class Users(SQLModel, table=True):
|
||||
__tablename__ = "users" # type: ignore
|
||||
|
||||
# ---------- 主键 ----------
|
||||
id: str = Field(
|
||||
default_factory=primary_key_create,
|
||||
primary_key=True,
|
||||
index=True,
|
||||
description="用户唯一ID(UUID格式)"
|
||||
)
|
||||
|
||||
# ---------- 登录凭证(唯一索引) ----------
|
||||
username: str = Field(
|
||||
max_length=50,
|
||||
unique=True,
|
||||
index=True,
|
||||
nullable=False,
|
||||
description="登录用户名"
|
||||
)
|
||||
email: str = Field(
|
||||
max_length=255,
|
||||
unique=True,
|
||||
index=True,
|
||||
nullable=False,
|
||||
description="电子邮箱"
|
||||
)
|
||||
hashed_password: str = Field(
|
||||
max_length=255,
|
||||
nullable=False,
|
||||
description="加密后的密码(不存明文)"
|
||||
)
|
||||
|
||||
# ---------- 个人信息(可选) ----------
|
||||
full_name: Optional[str] = Field(
|
||||
default=None,
|
||||
max_length=100,
|
||||
description="用户全名"
|
||||
)
|
||||
avatar_url: Optional[str] = Field(
|
||||
default=None,
|
||||
max_length=500,
|
||||
description="头像图片链接"
|
||||
)
|
||||
phone: Optional[str] = Field(
|
||||
default=None,
|
||||
max_length=20,
|
||||
description="手机号码"
|
||||
)
|
||||
|
||||
# ---------- 安全与状态标识 ----------
|
||||
is_active: bool = Field(
|
||||
default=True,
|
||||
description="账户是否启用(用于软禁用)"
|
||||
)
|
||||
is_verified: bool = Field(
|
||||
default=False,
|
||||
description="邮箱/手机是否已验证"
|
||||
)
|
||||
is_superuser: bool = Field(
|
||||
default=False,
|
||||
description="是否为超级管理员"
|
||||
)
|
||||
|
||||
# ---------- 审计时间戳(数据库自动维护) ----------
|
||||
created_at: datetime = Field(
|
||||
sa_column=Column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
nullable=False,
|
||||
comment="创建时间"
|
||||
)
|
||||
)
|
||||
updated_at: datetime = Field(
|
||||
sa_column=Column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
onupdate=func.now(),
|
||||
nullable=False,
|
||||
comment="最后更新时间"
|
||||
)
|
||||
)
|
||||
|
||||
# ---------- 最后登录记录(可选) ----------
|
||||
last_login_at: Optional[datetime] = Field(
|
||||
default=None,
|
||||
sa_column=Column(DateTime(timezone=True), nullable=True),
|
||||
description="最后一次登录时间"
|
||||
)
|
||||
@@ -0,0 +1,86 @@
|
||||
"""
|
||||
自动生成的 Pydantic 模型 — auth
|
||||
来源: config/workers/auth/
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
class ChangePasswordPostRequest(BaseModel):
|
||||
"""修改密码 — 请求体"""
|
||||
user_id: str = Field(...)
|
||||
old_password: str = Field(...)
|
||||
new_password: str = Field(...)
|
||||
|
||||
class ChangePasswordPostResponse(BaseModel):
|
||||
"""修改密码 — 响应体"""
|
||||
result: str = Field(...)
|
||||
message: str = Field(...)
|
||||
timestamp: Optional[float] = Field(default=None)
|
||||
|
||||
class LoginPostRequest(BaseModel):
|
||||
"""登录 — 请求体"""
|
||||
username: str = Field(...)
|
||||
password: str = Field(...)
|
||||
|
||||
class LoginPostResponse(BaseModel):
|
||||
"""登录 — 响应体"""
|
||||
result: str = Field(...)
|
||||
token: str = Field(...)
|
||||
message: str = Field(...)
|
||||
timestamp: Optional[float] = Field(default=None)
|
||||
|
||||
class MeGetRequest(BaseModel):
|
||||
"""获取当前用户信息 — 请求体"""
|
||||
user_id: str = Field(...)
|
||||
|
||||
class MeGetResponse(BaseModel):
|
||||
"""获取当前用户信息 — 响应体"""
|
||||
result: str = Field(...)
|
||||
id: str = Field(...)
|
||||
username: str = Field(...)
|
||||
email: str = Field(...)
|
||||
full_name: Optional[str] = Field(default=None)
|
||||
avatar_url: Optional[str] = Field(default=None)
|
||||
phone: Optional[str] = Field(default=None)
|
||||
is_active: bool = Field(...)
|
||||
is_verified: bool = Field(...)
|
||||
is_superuser: bool = Field(...)
|
||||
created_at: Optional[str] = Field(default=None)
|
||||
updated_at: Optional[str] = Field(default=None)
|
||||
last_login_at: Optional[str] = Field(default=None)
|
||||
|
||||
class RegisterPostRequest(BaseModel):
|
||||
"""用户注册 — 请求体"""
|
||||
username: str = Field(...)
|
||||
password: str = Field(...)
|
||||
email: str = Field(...)
|
||||
full_name: str = Field(...)
|
||||
phone: str = Field(...)
|
||||
|
||||
class RegisterPostResponse(BaseModel):
|
||||
"""用户注册 — 响应体"""
|
||||
result: str = Field(...)
|
||||
message: str = Field(...)
|
||||
user_id: Optional[str] = Field(default=None)
|
||||
timestamp: Optional[float] = Field(default=None)
|
||||
|
||||
class UpdateProfilePostRequest(BaseModel):
|
||||
"""更新用户资料 — 请求体"""
|
||||
user_id: str = Field(...)
|
||||
full_name: str = Field(...)
|
||||
email: str = Field(...)
|
||||
avatar_url: str = Field(...)
|
||||
phone: str = Field(...)
|
||||
|
||||
class UpdateProfilePostResponse(BaseModel):
|
||||
"""更新用户资料 — 响应体"""
|
||||
result: str = Field(...)
|
||||
message: str = Field(...)
|
||||
timestamp: Optional[float] = Field(default=None)
|
||||
|
||||
|
||||
# 所有响应模型的联合类型
|
||||
AuthResponse = LoginPostResponse | ChangePasswordPostResponse | MeGetResponse | UpdateProfilePostResponse | RegisterPostResponse
|
||||
Reference in New Issue
Block a user