提供基本前后端骨架

This commit is contained in:
hisatri
2026-01-06 23:49:23 +08:00
parent 84d4ccc226
commit 06f8176e23
89 changed files with 19293 additions and 2 deletions

112
app/schemas/auth.py Normal file
View File

@@ -0,0 +1,112 @@
"""
认证相关 Schema
定义登录、令牌等数据结构。
"""
from typing import Annotated
from pydantic import Field
from app.schemas.base import BaseSchema
class LoginRequest(BaseSchema):
"""登录请求"""
username: Annotated[
str,
Field(
min_length=1,
description="用户名或邮箱",
examples=["john_doe"],
),
]
password: Annotated[
str,
Field(
min_length=1,
description="密码",
examples=["SecurePass123"],
),
]
class TokenResponse(BaseSchema):
"""令牌响应"""
access_token: str = Field(description="访问令牌")
refresh_token: str = Field(description="刷新令牌")
token_type: str = Field(default="Bearer", description="令牌类型")
expires_in: int = Field(description="访问令牌过期时间(秒)")
class RefreshTokenRequest(BaseSchema):
"""刷新令牌请求"""
refresh_token: Annotated[
str,
Field(
min_length=1,
description="刷新令牌",
),
]
class PasswordChangeRequest(BaseSchema):
"""修改密码请求"""
current_password: Annotated[
str,
Field(
min_length=1,
description="当前密码",
),
]
new_password: Annotated[
str,
Field(
min_length=8,
max_length=128,
description="新密码",
),
]
def model_post_init(self, __context) -> None:
"""验证新旧密码不同"""
if self.current_password == self.new_password:
raise ValueError("新密码不能与当前密码相同")
class PasswordResetRequest(BaseSchema):
"""密码重置请求(忘记密码)"""
email: Annotated[
str,
Field(
min_length=1,
description="注册邮箱",
examples=["user@example.com"],
),
]
class PasswordResetConfirm(BaseSchema):
"""密码重置确认"""
token: Annotated[
str,
Field(
min_length=1,
description="重置令牌",
),
]
new_password: Annotated[
str,
Field(
min_length=8,
max_length=128,
description="新密码",
),
]