feat: complete email binding and pending oauth verification flows
This commit is contained in:
@@ -58,11 +58,20 @@
|
||||
<p v-else class="text-xs text-gray-500 dark:text-dark-400">
|
||||
{{ t('auth.verificationCodeHint') }}
|
||||
</p>
|
||||
<input
|
||||
v-if="invitationCodeEnabled"
|
||||
v-model="invitationCode"
|
||||
:data-testid="`${testIdPrefix}-create-account-invitation-code`"
|
||||
type="text"
|
||||
class="input w-full"
|
||||
:placeholder="t('auth.invitationCodePlaceholder')"
|
||||
:disabled="isSubmitting"
|
||||
/>
|
||||
<button
|
||||
:data-testid="`${testIdPrefix}-create-account-submit`"
|
||||
type="button"
|
||||
class="btn btn-primary w-full"
|
||||
:disabled="isSubmitting || !email.trim() || password.length < 6"
|
||||
:disabled="isSubmitting || !email.trim() || password.length < 6 || (invitationCodeEnabled && !invitationCode.trim())"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
{{ isSubmitting ? t('common.processing') : 'Create account' }}
|
||||
@@ -92,12 +101,13 @@
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import TurnstileWidget from '@/components/TurnstileWidget.vue'
|
||||
import { getPublicSettings, sendVerifyCode } from '@/api/auth'
|
||||
import { getPublicSettings, sendPendingOAuthVerifyCode } from '@/api/auth'
|
||||
|
||||
export type PendingOAuthCreateAccountPayload = {
|
||||
email: string
|
||||
password: string
|
||||
verifyCode: string
|
||||
invitationCode?: string
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -117,10 +127,12 @@ const { t } = useI18n()
|
||||
const email = ref('')
|
||||
const password = ref('')
|
||||
const verifyCode = ref('')
|
||||
const invitationCode = ref('')
|
||||
const isSendingCode = ref(false)
|
||||
const sendCodeError = ref('')
|
||||
const sendCodeSuccess = ref(false)
|
||||
const countdown = ref(0)
|
||||
const invitationCodeEnabled = ref(false)
|
||||
const turnstileEnabled = ref(false)
|
||||
const turnstileSiteKey = ref('')
|
||||
const turnstileToken = ref('')
|
||||
@@ -203,7 +215,7 @@ async function handleSendCode() {
|
||||
sendCodeSuccess.value = false
|
||||
|
||||
try {
|
||||
const response = await sendVerifyCode({
|
||||
const response = await sendPendingOAuthVerifyCode({
|
||||
email: trimmedEmail,
|
||||
turnstile_token: turnstileEnabled.value ? turnstileToken.value : undefined
|
||||
})
|
||||
@@ -228,7 +240,8 @@ function handleSubmit() {
|
||||
emit('submit', {
|
||||
email: trimmedEmail,
|
||||
password: password.value,
|
||||
verifyCode: verifyCode.value.trim()
|
||||
verifyCode: verifyCode.value.trim(),
|
||||
invitationCode: invitationCode.value.trim() || undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -239,9 +252,11 @@ function emitSwitchToBind() {
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const settings = await getPublicSettings()
|
||||
invitationCodeEnabled.value = settings.invitation_code_enabled === true
|
||||
turnstileEnabled.value = settings.turnstile_enabled === true
|
||||
turnstileSiteKey.value = settings.turnstile_site_key || ''
|
||||
} catch {
|
||||
invitationCodeEnabled.value = false
|
||||
turnstileEnabled.value = false
|
||||
turnstileSiteKey.value = ''
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { flushPromises, mount } from '@vue/test-utils'
|
||||
import PendingOAuthCreateAccountForm from '../PendingOAuthCreateAccountForm.vue'
|
||||
|
||||
const sendVerifyCode = vi.fn()
|
||||
const sendPendingOAuthVerifyCode = vi.fn()
|
||||
const getPublicSettings = vi.fn()
|
||||
|
||||
vi.mock('vue-i18n', async () => {
|
||||
@@ -21,6 +22,7 @@ vi.mock('@/api/auth', async () => {
|
||||
return {
|
||||
...actual,
|
||||
sendVerifyCode: (...args: any[]) => sendVerifyCode(...args),
|
||||
sendPendingOAuthVerifyCode: (...args: any[]) => sendPendingOAuthVerifyCode(...args),
|
||||
getPublicSettings: (...args: any[]) => getPublicSettings(...args)
|
||||
}
|
||||
})
|
||||
@@ -28,6 +30,7 @@ vi.mock('@/api/auth', async () => {
|
||||
describe('PendingOAuthCreateAccountForm', () => {
|
||||
beforeEach(() => {
|
||||
sendVerifyCode.mockReset()
|
||||
sendPendingOAuthVerifyCode.mockReset()
|
||||
getPublicSettings.mockReset()
|
||||
getPublicSettings.mockResolvedValue({
|
||||
turnstile_enabled: false,
|
||||
@@ -61,8 +64,42 @@ describe('PendingOAuthCreateAccountForm', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('shows and emits invitation code when invitation-only signup is enabled', async () => {
|
||||
getPublicSettings.mockResolvedValue({
|
||||
invitation_code_enabled: true,
|
||||
turnstile_enabled: false,
|
||||
turnstile_site_key: ''
|
||||
})
|
||||
|
||||
const wrapper = mount(PendingOAuthCreateAccountForm, {
|
||||
props: {
|
||||
providerName: 'LinuxDo',
|
||||
testIdPrefix: 'linuxdo',
|
||||
initialEmail: 'prefill@example.com',
|
||||
isSubmitting: false
|
||||
}
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
await wrapper.get('[data-testid="linuxdo-create-account-password"]').setValue('secret-123')
|
||||
await wrapper.get('[data-testid="linuxdo-create-account-verify-code"]').setValue('246810')
|
||||
await wrapper.get('[data-testid="linuxdo-create-account-invitation-code"]').setValue(' INVITE123 ')
|
||||
await wrapper.get('form').trigger('submit.prevent')
|
||||
|
||||
expect(wrapper.emitted('submit')).toEqual([
|
||||
[
|
||||
{
|
||||
email: 'prefill@example.com',
|
||||
password: 'secret-123',
|
||||
verifyCode: '246810',
|
||||
invitationCode: 'INVITE123'
|
||||
}
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
it('sends a verify code for the trimmed email value', async () => {
|
||||
sendVerifyCode.mockResolvedValue({
|
||||
sendPendingOAuthVerifyCode.mockResolvedValue({
|
||||
message: 'sent',
|
||||
countdown: 60
|
||||
})
|
||||
@@ -80,7 +117,7 @@ describe('PendingOAuthCreateAccountForm', () => {
|
||||
await wrapper.get('[data-testid="linuxdo-create-account-send-code"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(sendVerifyCode).toHaveBeenCalledWith({
|
||||
expect(sendPendingOAuthVerifyCode).toHaveBeenCalledWith({
|
||||
email: 'user@example.com'
|
||||
})
|
||||
})
|
||||
@@ -90,7 +127,7 @@ describe('PendingOAuthCreateAccountForm', () => {
|
||||
turnstile_enabled: true,
|
||||
turnstile_site_key: 'site-key'
|
||||
})
|
||||
sendVerifyCode.mockResolvedValue({
|
||||
sendPendingOAuthVerifyCode.mockResolvedValue({
|
||||
message: 'sent',
|
||||
countdown: 60
|
||||
})
|
||||
@@ -120,7 +157,7 @@ describe('PendingOAuthCreateAccountForm', () => {
|
||||
await wrapper.get('[data-testid="linuxdo-create-account-send-code"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(sendVerifyCode).toHaveBeenCalledWith({
|
||||
expect(sendPendingOAuthVerifyCode).toHaveBeenCalledWith({
|
||||
email: 'user@example.com',
|
||||
turnstile_token: 'turnstile-token'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user