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:
1 parent
bce0abba6e
commit
9572b66ecb
11 files changed
+402
-44
No files matched your search
+56
@@ -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")
|
||||
@@ -56,6 +56,13 @@ class UserRow(Base):
|
||||
# 时把已存在行置为已放行。
|
||||
approved: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default=text("1"))
|
||||
|
||||
# 管理员在「白名单管理」页给个别账号设置的「登录口令」(**明文**)。非空 → 该账号的
|
||||
# 用户名直登(``POST /api/v1/auth/login/username``)必须带 ``?password=`` 且与此值
|
||||
# 完全一致才放行(优先于全局共享口令门);为空/NULL → 走原有逻辑(全局共享口令门
|
||||
# 或免口令)。明文存储是有意为之:口令本就以 URL query 明文传输,存明文才能让管理员
|
||||
# 随时复制完整登录链接 ``…/login/<用户名>?password=xxxx``。仅 admin 可读写。
|
||||
login_password: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
|
||||
# 岗位 (position) the user is assigned to (1:1). NULL = no explicit
|
||||
# position → the user inherits the ``is_default`` position's grants. Drives
|
||||
# the subscription sync engine (see ``deerflow.services.position_sync``).
|
||||
|
||||
Reference in new issue
Block a user