feat(白名单): 账号级登录口令——管理员设明文口令,用户凭 /login/<用户名>?password= 直登

白名单管理页可给单个账号设明文登录口令(users.login_password,可空):
设置后该账号用户名直登(/login/username)须带匹配 ?password=,且优先于全局共享口令门;
未设口令的账号行为不变。前端登录 URL 已支持透传 ?password=,无需改登录页。

- 后端:UserRow/User 新增 login_password + 仓储映射;/login/username 账号级口令闸门
  (_lookup_user_by_username 仅查不建);新管理员接口 PUT /users/{id}/login-password;
  UserListItem 暴露明文(仅 admin 列表);migration 20260625_04 + 幂等补列 SQL。
- 前端:白名单页新增「登录口令」列(设置/修改/清除 + 复制登录链接);
  core/auth api+hooks 增 setUserLoginPassword/useSetUserLoginPassword(含 Y-Log)。
- 文档:根 + 后端 CLAUDE.md 同步。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
吉鑫升andClaude Opus 4.8 committed 2026-06-27 11:03:39 +08:00
1 parent bce0abba6e
commit 9572b66ecb
11 files changed
+402 -44

No files matched your search

@@ -0,0 +1,56 @@
"""Add users.login_password (per-account 登录口令, 明文).
Backs the 白名单管理「设置登录口令」feature: an admin assigns an individual
plaintext password to a specific account, and that account's username login
(``POST /api/v1/auth/login/username``) then requires a matching ``?password=``
(it takes precedence over the global shared-password gate). The column is
nullable — NULL/empty means "no personal password" and the account keeps the
existing shared-gate / passwordless behavior.
Stored in plaintext on purpose: the password rides in the login URL's query
string anyway, and keeping it readable lets the admin re-copy the full login
link ``…/login/<username>?password=xxxx`` at any time. The ``/users`` list that
exposes it is admin-only.
Revision ID: 20260625_04
Revises: 20260625_03
Create Date: 2026-06-27
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
from sqlalchemy import inspect
revision = "20260625_04"
down_revision = "20260625_03"
branch_labels = None
depends_on = None
def _has_table(table_name: str) -> bool:
inspector = inspect(op.get_bind())
return table_name in inspector.get_table_names()
def _has_column(table_name: str, column_name: str) -> bool:
if not _has_table(table_name):
return False
inspector = inspect(op.get_bind())
return any(col["name"] == column_name for col in inspector.get_columns(table_name))
def upgrade() -> None:
# A brand-new DB gets the column from create_all; only patch existing tables.
if _has_table("users") and not _has_column("users", "login_password"):
op.add_column(
"users",
sa.Column("login_password", sa.String(length=255), nullable=True),
)
def downgrade() -> None:
if _has_column("users", "login_password"):
op.drop_column("users", "login_password")