feat: add multi-provider auth via AuthIdentity and extend site config
- Extract AuthIdentity model for multi-provider authentication (email_password, OAuth, Passkey, Magic Link) - Remove password field from User model, credentials now stored in AuthIdentity - Refactor unified login/register to use AuthIdentity-based provider checking - Add site config fields: footer_code, tos_url, privacy_url, auth_methods - Add auth settings defaults in migration (email_password enabled by default) - Update admin user creation to create AuthIdentity records - Update all tests to use AuthIdentity model Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ from enum import StrEnum
|
||||
|
||||
from sqlmodel import UniqueConstraint
|
||||
|
||||
from .auth_identity import AuthProviderType
|
||||
from .base import SQLModelBase
|
||||
from .mixin import TableBaseMixin
|
||||
from .user import UserResponse
|
||||
@@ -12,6 +13,19 @@ class CaptchaType(StrEnum):
|
||||
GCAPTCHA = "gcaptcha"
|
||||
CLOUD_FLARE_TURNSTILE = "cloudflare turnstile"
|
||||
|
||||
|
||||
# ==================== Auth 配置 DTO ====================
|
||||
|
||||
class AuthMethodConfig(SQLModelBase):
|
||||
"""认证方式配置 DTO"""
|
||||
|
||||
provider: AuthProviderType
|
||||
"""提供者类型"""
|
||||
|
||||
is_enabled: bool
|
||||
"""是否启用"""
|
||||
|
||||
|
||||
# ==================== DTO 模型 ====================
|
||||
|
||||
class SiteConfigResponse(SQLModelBase):
|
||||
@@ -50,6 +64,27 @@ class SiteConfigResponse(SQLModelBase):
|
||||
captcha_key: str | None = None
|
||||
"""验证码 public key(DEFAULT 类型时为 None)"""
|
||||
|
||||
auth_methods: list[AuthMethodConfig] = []
|
||||
"""可用的登录方式列表"""
|
||||
|
||||
password_required: bool = True
|
||||
"""注册时是否必须设置密码"""
|
||||
|
||||
phone_binding_required: bool = False
|
||||
"""是否强制绑定手机号"""
|
||||
|
||||
email_binding_required: bool = True
|
||||
"""是否强制绑定邮箱"""
|
||||
|
||||
footer_code: str | None = None
|
||||
"""自定义页脚代码"""
|
||||
|
||||
tos_url: str | None = None
|
||||
"""服务条款 URL"""
|
||||
|
||||
privacy_url: str | None = None
|
||||
"""隐私政策 URL"""
|
||||
|
||||
|
||||
# ==================== 管理员设置 DTO ====================
|
||||
|
||||
@@ -133,4 +168,4 @@ class Setting(SettingItem, TableBaseMixin):
|
||||
__table_args__ = (UniqueConstraint("type", "name", name="uq_setting_type_name"),)
|
||||
|
||||
type: SettingsType
|
||||
"""设置类型/分组(覆盖基类的 str 类型为枚举类型)"""
|
||||
"""设置类型/分组(覆盖基类的 str 类型为枚举类型)"""
|
||||
|
||||
Reference in New Issue
Block a user