diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 0289159d9..ec304fe93 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -32551,3 +32551,19 @@ - 相关记录:BUG-1507(新疆部分由本条关闭)、BUG-1971(自己选流程;平票两按钮由本条取代)、BUG-2192、BUG-2256(随缘版记录)、BUG-2272。 - 复发自:无 - 修复版本:分支 `claude/rect-tie-tz-2355`(待父会话推送)。 + +## BUG-2395 | 邮箱后缀打错(如 qq.con)时照样发验证码,退信率升到 21% + +- **状态**:resolved(staging 待推) +- **现象**:负责人转来发信服务后台截图:近一天退信率 21.43%,远高于服务商 4% 的风险线;被退回的全是后缀打错的地址(`@qq.con`),同一个错地址连点几次发送。用户收不到验证码,页面只说「暂时无法发送」或什么都不说。 +- **触发条件**:登录、注册或重设密码时邮箱后缀打错,例如 `.con`、`.cmo`、`gmial.com`。 +- **根因**:登录页只有浏览器自带的邮箱格式检查,`x@qq.con` 格式合法;服务端收到就生成验证码并调用发信接口。发信量小时几封退信就把退信率推过风险线,长期如此服务商会限制整个账号发信。 +- **修复**: + - `frontend/src/lib/email-typo.ts`:`emailDomainTypo`(最后一段是任何邮箱都不会用的后缀,如 con/cmo/comm)与 `suggestEmailFix`(和常见邮箱服务商域名只差一个字,且只匹配一个时给出改正后的地址)。 + - `frontend/src/modules/identity/auth-factory.ts`:Better Auth `hooks.before` 在四个发验证码接口上拒绝 `emailDomainTypo` 的地址(400,code `EMAIL_DOMAIN_TYPO`),在生成验证码和调用发信之前。 + - `frontend/src/modules/identity/client.ts`:发送与重设密码遇到这个 code 时提示「这个邮箱地址的后缀好像不完整,请检查一下再发送」,不再说「请稍后再试」。 + - `frontend/src/components/email-otp-login.tsx`:两个邮箱输入框改为 `EmailField`(负责人 11-25 追加「后缀放进输入框右边下拉,选了自动替换」):输入框右侧「@后缀 ▾」菜单列 16 个常用后缀(qq、163、gmail、126、icloud、outlook 等);选中后框里只填 @ 前面的部分,后缀自动接上,换一个就直接替换;自己打出「@」或浏览器自动填入完整地址就回到整址输入;菜单末项「其他邮箱(自己输入完整地址)」;打了「@y」时菜单只列 y 开头的后缀。整址输入时一打出「@」,框下自动展开后缀列表(负责人 11-25「@之后自动展开」),随后续字母收窄(`@y` → yahoo.com、yeah.net),点一项补全,焦点留在输入框,↑↓/回车可选,Esc、离开输入框或后缀已完整时收起;列表浮在下方,不推动页面。整址输入时域名差一个字,框下显示「是不是 …@qq.com?」,点地址即改正。只是帮助,不拦发送,不用 toast。 +- **验证**:新测 `frontend/tests/email-typo-2395.test.ts` 6 条;登录/身份相关前端测试 104 条中 103 过,1 条 `identity-auth-integration` 需要本机 docker 启 Postgres(本机无 docker,CI 跑);tsc 无错;`npx eslint .` 0 错。 +- **防复发**:测试钉住纠错与拒发规则、拦截挂在四个发码路径、客户端提示文字、两个输入框都有内联提示。 +- **关联记录**:BUG-2348(发信重试与失败信号)、BUG-2346、BUG-2056(结果用 toast,内联提示除外)。 +- **修复版本**:1.5(待发)。 diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 51827229d..3fdf96b96 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -3035,6 +3035,20 @@ input:not([type="radio"]):not([type="checkbox"]):not([class^="ant-"]):not([class .auth-center { min-width: 0; width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: center; gap: var(--space-6); padding: var(--space-8) 0 var(--space-12); text-align: center; } .auth-body { width: min(340px, 100%); display: grid; gap: var(--space-4); text-align: left; } .auth-heading { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: var(--space-3); } +/* BUG-2395: the ending menu sits inside the email field on the right. */ +.auth-email-field { position: relative; min-width: 0; } +.auth-email-field input { padding-right: 164px; } +.auth-email-domain-trigger { position: absolute; top: 4px; right: 4px; bottom: 4px; display: inline-flex; align-items: center; gap: 4px; max-width: 156px; height: auto; min-height: 0; padding: 0 10px; border: 0; border-radius: calc(var(--radius-md, 8px) - 2px); background: var(--color-surface-muted, transparent); color: var(--color-ink-secondary); font-size: var(--type-body-sm); white-space: nowrap; cursor: pointer; } +.auth-email-domain-trigger span { overflow: hidden; text-overflow: ellipsis; } +.auth-email-domain-trigger svg { flex: none; width: 14px; height: 14px; } +.auth-email-domain-menu { max-height: min(360px, 60vh); overflow-y: auto; } +.auth-email-domain-item { min-height: 40px; } +.auth-email-suggest { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; right: 0; max-height: min(264px, 45vh); overflow-y: auto; padding: 6px; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-canvas); box-shadow: var(--shadow-elevated); } +.auth-email-suggest-item { display: flex; gap: 0; width: 100%; justify-content: flex-start; height: 44px; padding: 0 12px; overflow: hidden; color: var(--color-ink-secondary); font-weight: 400; text-overflow: ellipsis; white-space: nowrap; } +.auth-email-suggest-item strong { color: var(--color-ink); font-weight: 500; } +.auth-email-suggest-item[data-active] { background: var(--sidebar-accent); } +.auth-email-hint { margin: 0; color: var(--color-ink-secondary); font-size: var(--type-body-sm); line-height: 1.5; } +.auth-email-hint-fix { display: inline; height: auto; min-height: 0; padding: 0; color: var(--color-ink); font: inherit; text-decoration: underline; text-underline-offset: 3px; vertical-align: baseline; } .auth-intro { max-width: 340px; margin: 0; color: var(--color-ink-secondary); font-size: var(--type-body-sm); line-height: 1.6; text-wrap: pretty; } /* The headline is in the server HTML. With motion allowed it waits hidden (at its final size) for up to 2 s while the script loads, then types out; past 2 s it simply shows. */ diff --git a/frontend/src/components/email-otp-login.tsx b/frontend/src/components/email-otp-login.tsx index 43e5338c8..f4d16dc0b 100644 --- a/frontend/src/components/email-otp-login.tsx +++ b/frontend/src/components/email-otp-login.tsx @@ -8,6 +8,10 @@ import { LoginConsentNotice, LoginLegalFooter } from "@/components/legal/login-c import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; +import { ChevronDown } from "lucide-react"; + +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/dropdown-menu-lazy"; +import { autoEmailDomains, menuEmailDomains, suggestEmailFix } from "@/lib/email-typo"; import { recordLegalConsent } from "@/lib/legal-consent-client"; import { findEarlyLoginForm, LOGIN_EMAIL_FORM_ID, LOGIN_EMAIL_INPUT_ID, takeEarlyLoginInput } from "@/lib/login-early-input"; import { dismissNotice, notifyError, notifyInfo, notifySuccess, NOTICE_DURATION_MS } from "@/lib/notify"; @@ -84,6 +88,130 @@ function authMessage(caught: unknown) { return message; } +// BUG-2395 (owner 11-25: endings in a menu at the right of the field, replaced on pick). +// With an ending picked, the field holds only the part before 「@」 and the ending is added; typing 「@」 +// (or an autofilled full address) goes back to the whole address. A domain one slip from a common provider +// (`qq.con`) gets 「是不是 …?」 under the field. A typed 「@y」 narrows the menu to the endings starting with y. +// Typing 「@」 opens the endings under the field by themselves (the field keeps the focus; ↑↓ and Enter work); +// they narrow as letters follow and close on a pick, Esc, leaving the field, or a complete known ending. Only help: nothing is blocked here, nothing is a toast. +type EmailFieldProps = { + id: string; + name?: string; + email: string; + picked: string | null; + placeholder: string; + onChange: (email: string, picked: string | null) => void; +}; + +function EmailField({ id, name, email, picked, placeholder, onChange }: EmailFieldProps) { + const local = picked && email.endsWith(`@${picked}`) ? email.slice(0, -picked.length - 1) : picked ? "" : email; + const shown = picked ? local : email; + const [focused, setFocused] = useState(false); + const [dismissed, setDismissed] = useState(null); + const [active, setActive] = useState(0); + const suggestions = picked || !focused || dismissed === email ? [] : autoEmailDomains(email); + const listId = `${id}-domains`; + const fixed = picked || suggestions.length ? null : suggestEmailFix(email); + const complete = (domain: string) => { + const before = email.slice(0, email.indexOf("@")).trim(); + onChange(`${before}@${domain}`, null); + setActive(0); + }; + const pick = (domain: string | null) => { + if (domain === null) { + onChange(email, null); + } else { + const before = (picked ? local : email.split("@")[0]).trim(); + onChange(before ? `${before}@${domain}` : "", domain); + } + document.getElementById(id)?.focus(); + }; + return ( + <> +
+ { + const typed = event.target.value; + setActive(0); + if (picked && !typed.includes("@")) onChange(typed.trim() ? `${typed}@${picked}` : "", picked); + else onChange(typed, null); + }} + onFocus={() => setFocused(true)} + onBlur={() => setFocused(false)} + onKeyDown={(event) => { + if (!suggestions.length) return; + if (event.key === "ArrowDown" || event.key === "ArrowUp") { + event.preventDefault(); + const step = event.key === "ArrowDown" ? 1 : -1; + setActive((current) => (current + step + suggestions.length) % suggestions.length); + } else if (event.key === "Enter") { + event.preventDefault(); + complete(suggestions[Math.min(active, suggestions.length - 1)]); + } else if (event.key === "Escape") { + setDismissed(email); + } + }} + placeholder={picked ? "邮箱 @ 前面的部分" : placeholder} + /> + {suggestions.length ? ( +
+ {suggestions.map((domain, index) => ( + + ))} +
+ ) : null} + + + {picked ? `@${picked}` : "@后缀"} + + + {(picked ? menuEmailDomains("") : menuEmailDomains(email)).map((domain) => ( + pick(domain)}> + @{domain} + + ))} + + pick(null)}>其他邮箱(自己输入完整地址) + + +
+ {fixed ? ( +

+ 是不是{" "} + + ? +

+ ) : null} + + ); +} + function passwordError(password: string, confirmation: string): string { if (password.length < 8 || password.length > 128) { return "密码长度须为 8–128 位"; @@ -108,6 +236,8 @@ export function EmailOtpLogin({ const [mode, setMode] = useState(passwordOnly ? "password" : "otp"); const [step, setStep] = useState("email"); const [email, setEmail] = useState(""); + // BUG-2395: the ending picked from the menu at the right of the email field, or null for a typed address. + const [pickedDomain, setPickedDomain] = useState(null); const [token, setToken] = useState(""); const [password, setPassword] = useState(""); const [confirmation, setConfirmation] = useState(""); @@ -440,20 +570,16 @@ export function EmailOtpLogin({ onSubmit={signInWithPassword} > - { - setEmail(event.target.value); + email={email} + picked={pickedDomain} + placeholder="you@example.com" + onChange={(next, picked) => { + setEmail(next); + setPickedDomain(picked); dismissNotice(AUTH_ERROR); }} - placeholder="you@example.com" /> - { - setEmail(event.target.value); + email={email} + picked={pickedDomain} + placeholder={mode === "otp" ? "输入邮箱" : "you@example.com"} + onChange={(next, picked) => { + setEmail(next); + setPickedDomain(picked); clearAuthNotices(); }} - placeholder={mode === "otp" ? "输入邮箱" : "you@example.com"} />