From d2c221e2dad8183d4a85d10f45a55f31635ccc9c Mon Sep 17 00:00:00 2001 From: hupenglong1 Date: Mon, 25 May 2026 11:55:56 +0800 Subject: [PATCH] =?UTF-8?q?auth:=20=E9=82=AE=E7=AE=B1=E6=B3=A8=E5=86=8C/?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=A1=A5=E5=85=A8=20Linux=20=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit registerByEmail / loginByEmail 漏掉 ensureLinuxAccount,开 CLAW_ENABLE_LINUX_ACCOUNTS=1 时邮箱用户既不会建 Linux 账号、createAccountDirectories 的 chown 也会失败。 照搬 username 路径的位置补上即可。同时删掉后端 server.py 里同逻辑的 dead code (_XIAOMI_EMAIL_RE / _account_id_from_email),实际拆分发生在 TS 层。 --- backend/api/server.py | 22 ---------------------- frontend/app/lib/claw-auth.ts | 2 ++ 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/backend/api/server.py b/backend/api/server.py index 48b95ef..d83520b 100644 --- a/backend/api/server.py +++ b/backend/api/server.py @@ -4556,28 +4556,6 @@ def _safe_account_id(account_id: str | None) -> str: return normalized[:80] or 'default' -_XIAOMI_EMAIL_RE = re.compile(r'^([\w.-]+)@xiaomi\.com$', re.IGNORECASE) -_EMAIL_ACCOUNT_ID_RE = re.compile(r'^[a-z0-9._-]{2,40}$') - - -def _account_id_from_email(email: str | None) -> str | None: - """Validate a Xiaomi email and return its prefix as account_id. - - The prefix is lowercased and must satisfy the platform account_id rule: - only lowercase letters / digits / dot / underscore / dash, length 2-40. - Returns None if the email or prefix is invalid (caller must reject). - """ - if not isinstance(email, str): - return None - match = _XIAOMI_EMAIL_RE.match(email.strip()) - if not match: - return None - prefix = match.group(1).lower() - if not _EMAIL_ACCOUNT_ID_RE.match(prefix): - return None - return prefix - - def _linux_accounts_enabled() -> bool: return os.environ.get(LINUX_ACCOUNT_ENV, '').strip().lower() in { '1', diff --git a/frontend/app/lib/claw-auth.ts b/frontend/app/lib/claw-auth.ts index ee5c356..2ba811f 100644 --- a/frontend/app/lib/claw-auth.ts +++ b/frontend/app/lib/claw-auth.ts @@ -103,6 +103,7 @@ export async function registerByEmail(email: string, password: string) { createdAt: new Date().toISOString(), }; usersFile.users.push(account); + await ensureLinuxAccount(account.id, password); await writeUsers(usersFile); await createAccountDirectories(account.id); return createSession(account); @@ -121,6 +122,7 @@ export async function loginByEmail(email: string, password: string) { if (!verifyPassword(password, account.passwordHash)) { throw new Error("邮箱或密码错误"); } + await ensureLinuxAccount(account.id, password); await createAccountDirectories(account.id); return createSession(account); }