mirror of
https://github.com/fawney19/Aether.git
synced 2026-01-10 03:32:26 +08:00
refactor: 重构邮箱验证模块并修复代码审查问题
- 重构: 将 verification 模块重命名为 email,目录结构更清晰 - 新增: 独立的邮件配置管理页面 (EmailSettings.vue) - 新增: 邮件模板管理功能(支持自定义 HTML 模板和预览) - 新增: 查询验证状态 API,支持页面刷新后恢复验证流程 - 新增: 注册邮箱后缀白名单/黑名单限制功能 - 修复: 统一密码最小长度为 6 位(前后端一致) - 修复: SMTP 连接添加 30 秒超时配置,防止 worker 挂起 - 修复: 邮件模板变量添加 HTML 转义,防止 XSS - 修复: 验证状态清除改为 db.commit 后执行,避免竞态条件 - 优化: RegisterDialog 重写验证码输入组件,提升用户体验 - 优化: Input 组件支持 disableAutofill 属性
This commit is contained in:
@@ -161,8 +161,8 @@ class VerifyEmailRequest(BaseModel):
|
||||
raise ValueError("邮箱格式无效")
|
||||
return v.lower()
|
||||
|
||||
@classmethod
|
||||
@field_validator("code")
|
||||
@classmethod
|
||||
def validate_code(cls, v):
|
||||
"""验证验证码格式"""
|
||||
v = v.strip()
|
||||
@@ -180,12 +180,39 @@ class VerifyEmailResponse(BaseModel):
|
||||
success: bool
|
||||
|
||||
|
||||
class VerificationStatusRequest(BaseModel):
|
||||
"""验证状态查询请求"""
|
||||
|
||||
email: str = Field(..., min_length=3, max_length=255, description="邮箱地址")
|
||||
|
||||
@field_validator("email")
|
||||
@classmethod
|
||||
def validate_email(cls, v):
|
||||
"""验证邮箱格式"""
|
||||
v = v.strip().lower()
|
||||
if not v:
|
||||
raise ValueError("邮箱不能为空")
|
||||
email_pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
|
||||
if not re.match(email_pattern, v):
|
||||
raise ValueError("邮箱格式无效")
|
||||
return v
|
||||
|
||||
|
||||
class VerificationStatusResponse(BaseModel):
|
||||
"""验证状态响应"""
|
||||
|
||||
email: str
|
||||
has_pending_code: bool = Field(description="是否有待验证的验证码")
|
||||
is_verified: bool = Field(description="邮箱是否已验证")
|
||||
cooldown_remaining: Optional[int] = Field(None, description="发送冷却剩余秒数")
|
||||
code_expires_in: Optional[int] = Field(None, description="验证码剩余有效秒数")
|
||||
|
||||
|
||||
class RegistrationSettingsResponse(BaseModel):
|
||||
"""注册设置响应(公开接口返回)"""
|
||||
|
||||
enable_registration: bool
|
||||
require_email_verification: bool
|
||||
verification_code_expire_minutes: Optional[int] = 30
|
||||
|
||||
|
||||
# ========== 用户管理 ==========
|
||||
|
||||
Reference in New Issue
Block a user