Files
xiaobai-review/backend/features/accounts/application.py
T
施工员andmultica-agent 3eaa36a8d5 feat(HEL-560): 数据中枢接管数据源/模型池/会员,注册改一次性邀请码
主站
- 新增 m0006 invite_codes 迁移;注册强制邀请码(首个管理员除外),消码与建号
  同一事务,并发提交只有一个能成功
- 新增 /api/hub-admin/* 服务端点(共享 HUB_ADMIN_TOKEN,先于鉴权校验),供数据
  中枢桥接读写会话/密码/模型池/会员/邀请码,并提供供应商模型列表拉取
- 前端:注册表单加邀请码(桌面 login、index.html、移动端);「系统管理」改为
  「数据中枢」入口指向 8766,原模型池与会员管理分区移除,仅留「行情管理」;
  随之清理陈旧 CSS

数据中枢
- 取消独立账号:删除 hub_admin/hub_sessions 与登录、改密、锁定逻辑,改为校验
  主站 xiaobai_session,仅管理员可进,CSRF 由会话派生,危险操作二次确认走主站
- 控制台新增数据源凭证可编辑区(原有内容一项不删)、供应商制模型池(自动拉取
  /models,失败退回卡内手动录入)、会员管理与邀请码页
- 日夜双主题:颜色收敛为同名 token 换值,SVG 改用 inline style 以吃到变量

自测
- 主站 verify_baseline 通过(498 项);数据中枢 235 项通过
- tools/verify_datahub_console.py 端到端跑通两服务真实对话;
  tools/verify_datahub_console_ui.py 浏览器跑通门禁/凭证/模型池/会员/主题/1030 窄屏

Co-authored-by: multica-agent <github@multica.ai>
2026-09-16 11:44:09 +08:00

70 lines
2.5 KiB
Python

from __future__ import annotations
from typing import Any
from backend.features.accounts.service import AccountService
class AccountApplicationMixin:
def bind_user(self, user_id: int) -> None:
self._request_context.user_id = int(user_id)
encrypted = self.database.get_user_credentials(int(user_id))
self._request_context.credentials = self.vault.decrypt_json(encrypted) if encrypted else {}
self._request_context.access = self.database.user_access(int(user_id)) or {}
@property
def current_user_id(self) -> int:
user_id = getattr(self._request_context, "user_id", 0)
if not user_id:
raise ValueError("当前请求尚未绑定账号。")
return int(user_id)
def membership(self) -> dict[str, Any]:
return self.accounts.membership()
def admin_users(self) -> list[dict[str, Any]]:
return self.accounts.admin_users(self._platform_usage_today_for_user)
def update_membership(self, payload: dict[str, Any]) -> None:
self.accounts.update_membership(payload)
def register_account(
self,
username: str,
password: str,
device_hash: str = "",
invite_code: str = "",
) -> dict[str, Any]:
return self.accounts.register(username, password, device_hash, invite_code)
def login_account(self, username: str, password: str, device_hash: str = "") -> dict[str, Any]:
return self.accounts.login(username, password, device_hash)
def change_password(self, current_password: str, new_password: str) -> None:
self.accounts.change_password(current_password, new_password)
def create_account_session(self, user: dict[str, Any]) -> dict[str, Any]:
return self.accounts.create_session(user)
@staticmethod
def _validate_account_input(username: str, password: str) -> None:
AccountService.validate_input(username, password)
def save_birth_profile(self, payload: dict[str, Any]) -> dict[str, Any]:
return self.accounts.save_birth_profile(payload)
def stored_birth_profile(self) -> dict[str, str] | None:
return self.accounts.stored_birth_profile()
def account_personal_field(
self,
current_date: str,
current_field: dict[str, Any],
public: bool = False,
) -> dict[str, Any] | None:
return self.accounts.personal_field(current_date, current_field, public)
@staticmethod
def _public_personal_profile(personal: dict[str, Any]) -> dict[str, Any]:
return AccountService.public_personal_profile(personal)