auth: 邮箱注册/登录补全 Linux 账号创建

registerByEmail / loginByEmail 漏掉 ensureLinuxAccount,开 CLAW_ENABLE_LINUX_ACCOUNTS=1
时邮箱用户既不会建 Linux 账号、createAccountDirectories 的 chown 也会失败。
照搬 username 路径的位置补上即可。同时删掉后端 server.py 里同逻辑的 dead code
(_XIAOMI_EMAIL_RE / _account_id_from_email),实际拆分发生在 TS 层。
This commit is contained in:
hupenglong1
2026-05-25 11:55:56 +08:00
parent d8741a3489
commit d2c221e2da
2 changed files with 2 additions and 22 deletions
-22
View File
@@ -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',