fix(auth): 第三方首登建号表单不再按全局邮箱验证开关隐藏验证码

后端 createPendingOAuthAccount → RegisterOAuthEmailAccount → VerifyOAuthEmailCode
无条件要求本地邮箱验证码(注释写明有意独立于全局 email_verify_enabled),
发码端点 SendPendingOAuthVerifyCode 同样不看该开关。共享表单
PendingOAuthCreateAccountForm 却在全局开关关闭时隐藏发码入口并把验证码
清空提交,导致微信、OIDC、钉钉首登(及需邀请码时的 Linux DO)在关闭邮箱
验证后一律返回 EMAIL_VERIFY_REQUIRED,用户无法完成建号。

门控源自 aea2950b1:后端只给 Linux DO 加了关闭验证时直接登录的分支,
却把门控加在了所有提供方共用的表单上。去掉该门控,始终显示发码入口
并提交用户填写的验证码;普通注册页 RegisterView 不受影响。

原用例把"关闭时隐藏控件、提交空验证码"写成了预期,改为断言控件仍在、
可发码、提交携带验证码。

Fixes #9103
This commit is contained in:
li committed 2026-11-27 19:19:03 +08:00
1 parent 4233cc3d80
commit 418bcedbbd
2 files changed
+29 -13

No files matched your search

@@ -34,7 +34,12 @@
@error="onTurnstileError"
/>
</div>
<div v-if="emailVerifyEnabled" class="flex gap-3">
<!--
第三方首登建号时后端无条件校验本地邮箱验证码(VerifyOAuthEmailCode 有意独立于
全局 email_verify_enabled 开关,防止把他人邮箱绑进新账号),发码端点同样不看该开关。
因此这里不能按全局开关隐藏发码入口,否则关闭邮箱验证后用户无法完成建号。
-->
<div class="flex gap-3">
<input
v-model="verifyCode"
:data-testid="`${testIdPrefix}-create-account-verify-code`"
@@ -61,10 +66,10 @@
}}
</button>
</div>
<p v-if="emailVerifyEnabled && sendCodeSuccess" class="text-sm text-green-600 dark:text-green-400">
<p v-if="sendCodeSuccess" class="text-sm text-green-600 dark:text-green-400">
{{ t('auth.codeSentSuccess') }}
</p>
<p v-else-if="emailVerifyEnabled" class="text-xs text-gray-500 dark:text-dark-400">
<p v-else class="text-xs text-gray-500 dark:text-dark-400">
{{ t('auth.verificationCodeHint') }}
</p>
<input
@@ -137,7 +142,6 @@ const sendCodeError = ref('')
const sendCodeSuccess = ref(false)
const countdown = ref(0)
const invitationCodeEnabled = ref(false)
const emailVerifyEnabled = ref(true)
const turnstileEnabled = ref(false)
const turnstileSiteKey = ref('')
const tencentCaptchaEnabled = ref(false)
@@ -323,7 +327,7 @@ async function handleSubmit() {
emit('submit', {
email: trimmedEmail,
password: password.value,
verifyCode: emailVerifyEnabled.value ? verifyCode.value.trim() : '',
verifyCode: verifyCode.value.trim(),
...((turnstileEnabled.value || aliyunCaptchaEnabled.value) && turnstileToken.value
? { turnstileToken: turnstileToken.value }
: {}),
@@ -349,7 +353,6 @@ onMounted(async () => {
try {
const settings = await getPublicSettings()
invitationCodeEnabled.value = settings.invitation_code_enabled === true
emailVerifyEnabled.value = settings.email_verify_enabled !== false
turnstileEnabled.value = settings.turnstile_enabled === true
turnstileSiteKey.value = settings.turnstile_site_key || ''
tencentCaptchaEnabled.value = settings.tencent_captcha_enabled === true
@@ -361,7 +364,6 @@ onMounted(async () => {
aliyunCaptchaRegion.value = settings.aliyun_captcha_region || 'cn'
} catch {
invitationCodeEnabled.value = false
emailVerifyEnabled.value = true
turnstileEnabled.value = false
turnstileSiteKey.value = ''
tencentCaptchaEnabled.value = false
@@ -169,33 +169,47 @@ describe('PendingOAuthCreateAccountForm', () => {
expect(wrapper.text()).toContain('auth.alreadyHaveAccount')
})
it('hides email verification controls when public settings disable email verification', async () => {
// 后端 createPendingOAuthAccount → RegisterOAuthEmailAccount 无条件校验本地邮箱验证码,
// 与全局 email_verify_enabled 无关(#9103)。关闭全局邮箱验证时,表单仍须提供发码入口并提交验证码,
// 否则用户只能拿到 EMAIL_VERIFY_REQUIRED 且无从补救。
it('keeps email verification controls when public settings disable email verification', async () => {
getPublicSettings.mockResolvedValue({
email_verify_enabled: false,
turnstile_enabled: false,
turnstile_site_key: ''
})
sendPendingOAuthVerifyCode.mockResolvedValue({ countdown: 60 })
const wrapper = mount(PendingOAuthCreateAccountForm, {
props: {
testIdPrefix: 'linuxdo',
providerName: 'WeChat',
testIdPrefix: 'wechat',
initialEmail: 'prefill@example.com',
isSubmitting: false
}
})
await flushPromises()
await wrapper.get('[data-testid="linuxdo-create-account-password"]').setValue('secret-123')
expect(wrapper.find('[data-testid="wechat-create-account-verify-code"]').exists()).toBe(true)
const sendButton = wrapper.find('[data-testid="wechat-create-account-send-code"]')
expect(sendButton.exists()).toBe(true)
expect(wrapper.text()).toContain('auth.verificationCodeHint')
await sendButton.trigger('click')
await flushPromises()
expect(sendPendingOAuthVerifyCode).toHaveBeenCalledTimes(1)
expect(sendPendingOAuthVerifyCode.mock.calls[0]?.[0]).toMatchObject({ email: 'prefill@example.com' })
await wrapper.get('[data-testid="wechat-create-account-password"]').setValue('secret-123')
await wrapper.get('[data-testid="wechat-create-account-verify-code"]').setValue(' 135790 ')
await wrapper.get('form').trigger('submit.prevent')
expect(wrapper.find('[data-testid="linuxdo-create-account-verify-code"]').exists()).toBe(false)
expect(wrapper.find('[data-testid="linuxdo-create-account-send-code"]').exists()).toBe(false)
expect(wrapper.emitted('submit')).toEqual([
[
{
email: 'prefill@example.com',
password: 'secret-123',
verifyCode: ''
verifyCode: '135790'
}
]
])