2025-12-18 13:50:39 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<AuthLayout>
|
|
|
|
|
|
<div class="space-y-6">
|
|
|
|
|
|
<!-- Title -->
|
|
|
|
|
|
<div class="text-center">
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<h2 class="text-2xl font-bold text-gray-900 dark:text-white">
|
|
|
|
|
|
{{ t('auth.verifyYourEmail') }}
|
|
|
|
|
|
</h2>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<p class="mt-2 text-sm text-gray-500 dark:text-dark-400">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
We'll send a verification code to
|
|
|
|
|
|
<span class="font-medium text-gray-700 dark:text-gray-300">{{ email }}</span>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- No Data Warning -->
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="!hasRegisterData"
|
|
|
|
|
|
class="rounded-xl border border-amber-200 bg-amber-50 p-4 dark:border-amber-800/50 dark:bg-amber-900/20"
|
|
|
|
|
|
>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<div class="flex items-start gap-3">
|
|
|
|
|
|
<div class="flex-shrink-0">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg
|
|
|
|
|
|
class="h-5 w-5 text-amber-500"
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
stroke-width="1.5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="text-sm text-amber-700 dark:text-amber-400">
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<p class="font-medium">{{ t('auth.sessionExpired') }}</p>
|
|
|
|
|
|
<p class="mt-1">{{ t('auth.sessionExpiredDesc') }}</p>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Verification Form -->
|
|
|
|
|
|
<form v-else @submit.prevent="handleVerify" class="space-y-5">
|
|
|
|
|
|
<!-- Verification Code Input -->
|
|
|
|
|
|
<div>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<label for="code" class="input-label text-center">
|
|
|
|
|
|
{{ t('auth.verificationCode') }}
|
|
|
|
|
|
</label>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<input
|
|
|
|
|
|
id="code"
|
|
|
|
|
|
v-model="verifyCode"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
required
|
|
|
|
|
|
autocomplete="one-time-code"
|
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
|
maxlength="6"
|
|
|
|
|
|
:disabled="isLoading"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="input py-3 text-center font-mono text-xl tracking-[0.5em]"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
:class="{ 'input-error': errors.code }"
|
|
|
|
|
|
placeholder="000000"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<p v-if="errors.code" class="input-error-text text-center">
|
|
|
|
|
|
{{ errors.code }}
|
|
|
|
|
|
</p>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<p v-else class="input-hint text-center">{{ t('auth.verificationCodeHint') }}</p>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Code Status -->
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="codeSent"
|
|
|
|
|
|
class="rounded-xl border border-green-200 bg-green-50 p-4 dark:border-green-800/50 dark:bg-green-900/20"
|
|
|
|
|
|
>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<div class="flex items-start gap-3">
|
|
|
|
|
|
<div class="flex-shrink-0">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg
|
|
|
|
|
|
class="h-5 w-5 text-green-500"
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
stroke-width="1.5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p class="text-sm text-green-700 dark:text-green-400">
|
|
|
|
|
|
Verification code sent! Please check your inbox.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Turnstile Widget for Resend -->
|
|
|
|
|
|
<div v-if="turnstileEnabled && turnstileSiteKey && showResendTurnstile">
|
|
|
|
|
|
<TurnstileWidget
|
|
|
|
|
|
ref="turnstileRef"
|
|
|
|
|
|
:site-key="turnstileSiteKey"
|
|
|
|
|
|
@verify="onTurnstileVerify"
|
|
|
|
|
|
@expire="onTurnstileExpire"
|
|
|
|
|
|
@error="onTurnstileError"
|
|
|
|
|
|
/>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<p v-if="errors.turnstile" class="input-error-text mt-2 text-center">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
{{ errors.turnstile }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Error Message -->
|
|
|
|
|
|
<transition name="fade">
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="errorMessage"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="rounded-xl border border-red-200 bg-red-50 p-4 dark:border-red-800/50 dark:bg-red-900/20"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div class="flex items-start gap-3">
|
|
|
|
|
|
<div class="flex-shrink-0">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg
|
|
|
|
|
|
class="h-5 w-5 text-red-500"
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
stroke-width="1.5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p class="text-sm text-red-700 dark:text-red-400">
|
|
|
|
|
|
{{ errorMessage }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</transition>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Submit Button -->
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<button type="submit" :disabled="isLoading || !verifyCode" class="btn btn-primary w-full">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<svg
|
|
|
|
|
|
v-if="isLoading"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="-ml-1 mr-2 h-4 w-4 animate-spin text-white"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
fill="none"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<circle
|
|
|
|
|
|
class="opacity-25"
|
|
|
|
|
|
cx="12"
|
|
|
|
|
|
cy="12"
|
|
|
|
|
|
r="10"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
stroke-width="4"
|
|
|
|
|
|
></circle>
|
|
|
|
|
|
<path
|
|
|
|
|
|
class="opacity-75"
|
|
|
|
|
|
fill="currentColor"
|
|
|
|
|
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
|
|
|
|
></path>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg
|
|
|
|
|
|
v-else
|
|
|
|
|
|
class="mr-2 h-5 w-5"
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
stroke-width="1.5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
{{ isLoading ? 'Verifying...' : 'Verify & Create Account' }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Resend Code -->
|
|
|
|
|
|
<div class="text-center">
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-if="countdown > 0"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
disabled
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="cursor-not-allowed text-sm text-gray-400 dark:text-dark-500"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
>
|
|
|
|
|
|
Resend code in {{ countdown }}s
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-else
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
@click="handleResendCode"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
:disabled="
|
|
|
|
|
|
isSendingCode || (turnstileEnabled && showResendTurnstile && !resendTurnstileToken)
|
|
|
|
|
|
"
|
|
|
|
|
|
class="text-sm text-primary-600 transition-colors hover:text-primary-500 disabled:cursor-not-allowed disabled:opacity-50 dark:text-primary-400 dark:hover:text-primary-300"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<span v-if="isSendingCode">{{ t('auth.sendingCode') }}</span>
|
|
|
|
|
|
<span v-else-if="turnstileEnabled && !showResendTurnstile">
|
|
|
|
|
|
{{ t('auth.clickToResend') }}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span v-else>{{ t('auth.resendCode') }}</span>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Footer -->
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<button
|
|
|
|
|
|
@click="handleBack"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="flex items-center gap-2 text-gray-500 transition-colors hover:text-gray-700 dark:text-dark-400 dark:hover:text-gray-300"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg
|
|
|
|
|
|
class="h-4 w-4"
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
stroke-width="1.5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
d="M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
Back to registration
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</AuthLayout>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
|
|
|
|
import { useRouter } from 'vue-router'
|
2025-12-27 10:50:25 +08:00
|
|
|
|
import { useI18n } from 'vue-i18n'
|
2025-12-25 08:41:36 -08:00
|
|
|
|
import { AuthLayout } from '@/components/layout'
|
|
|
|
|
|
import TurnstileWidget from '@/components/TurnstileWidget.vue'
|
|
|
|
|
|
import { useAuthStore, useAppStore } from '@/stores'
|
|
|
|
|
|
import { getPublicSettings, sendVerifyCode } from '@/api/auth'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
2025-12-27 10:50:25 +08:00
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
2025-12-18 13:50:39 +08:00
|
|
|
|
// ==================== Router & Stores ====================
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
|
const appStore = useAppStore()
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// ==================== State ====================
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const isLoading = ref<boolean>(false)
|
|
|
|
|
|
const isSendingCode = ref<boolean>(false)
|
|
|
|
|
|
const errorMessage = ref<string>('')
|
|
|
|
|
|
const codeSent = ref<boolean>(false)
|
|
|
|
|
|
const verifyCode = ref<string>('')
|
|
|
|
|
|
const countdown = ref<number>(0)
|
|
|
|
|
|
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Registration data from sessionStorage
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const email = ref<string>('')
|
|
|
|
|
|
const password = ref<string>('')
|
|
|
|
|
|
const initialTurnstileToken = ref<string>('')
|
|
|
|
|
|
const hasRegisterData = ref<boolean>(false)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Public settings
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const turnstileEnabled = ref<boolean>(false)
|
|
|
|
|
|
const turnstileSiteKey = ref<string>('')
|
|
|
|
|
|
const siteName = ref<string>('Sub2API')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Turnstile for resend
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const turnstileRef = ref<InstanceType<typeof TurnstileWidget> | null>(null)
|
|
|
|
|
|
const resendTurnstileToken = ref<string>('')
|
|
|
|
|
|
const showResendTurnstile = ref<boolean>(false)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
const errors = ref({
|
|
|
|
|
|
code: '',
|
2025-12-25 08:41:36 -08:00
|
|
|
|
turnstile: ''
|
|
|
|
|
|
})
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// ==================== Lifecycle ====================
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
// Load registration data from sessionStorage
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const registerDataStr = sessionStorage.getItem('register_data')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
if (registerDataStr) {
|
|
|
|
|
|
try {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const registerData = JSON.parse(registerDataStr)
|
|
|
|
|
|
email.value = registerData.email || ''
|
|
|
|
|
|
password.value = registerData.password || ''
|
|
|
|
|
|
initialTurnstileToken.value = registerData.turnstile_token || ''
|
|
|
|
|
|
hasRegisterData.value = !!(email.value && password.value)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} catch {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
hasRegisterData.value = false
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Load public settings
|
|
|
|
|
|
try {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const settings = await getPublicSettings()
|
|
|
|
|
|
turnstileEnabled.value = settings.turnstile_enabled
|
|
|
|
|
|
turnstileSiteKey.value = settings.turnstile_site_key || ''
|
|
|
|
|
|
siteName.value = settings.site_name || 'Sub2API'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} catch (error) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
console.error('Failed to load public settings:', error)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Auto-send verification code if we have valid data
|
|
|
|
|
|
if (hasRegisterData.value) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
await sendCode()
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
2025-12-25 08:41:36 -08:00
|
|
|
|
})
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
if (countdownTimer) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
clearInterval(countdownTimer)
|
|
|
|
|
|
countdownTimer = null
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
2025-12-25 08:41:36 -08:00
|
|
|
|
})
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// ==================== Countdown ====================
|
|
|
|
|
|
|
|
|
|
|
|
function startCountdown(seconds: number): void {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
countdown.value = seconds
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (countdownTimer) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
clearInterval(countdownTimer)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
countdownTimer = setInterval(() => {
|
|
|
|
|
|
if (countdown.value > 0) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
countdown.value--
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (countdownTimer) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
clearInterval(countdownTimer)
|
|
|
|
|
|
countdownTimer = null
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-25 08:41:36 -08:00
|
|
|
|
}, 1000)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== Turnstile Handlers ====================
|
|
|
|
|
|
|
|
|
|
|
|
function onTurnstileVerify(token: string): void {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
resendTurnstileToken.value = token
|
|
|
|
|
|
errors.value.turnstile = ''
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onTurnstileExpire(): void {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
resendTurnstileToken.value = ''
|
|
|
|
|
|
errors.value.turnstile = 'Verification expired, please try again'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onTurnstileError(): void {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
resendTurnstileToken.value = ''
|
|
|
|
|
|
errors.value.turnstile = 'Verification failed, please try again'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== Send Code ====================
|
|
|
|
|
|
|
|
|
|
|
|
async function sendCode(): Promise<void> {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
isSendingCode.value = true
|
|
|
|
|
|
errorMessage.value = ''
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await sendVerifyCode({
|
|
|
|
|
|
email: email.value,
|
|
|
|
|
|
// 优先使用重发时新获取的 token(因为初始 token 可能已被使用)
|
2025-12-25 08:41:36 -08:00
|
|
|
|
turnstile_token: resendTurnstileToken.value || initialTurnstileToken.value || undefined
|
|
|
|
|
|
})
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
codeSent.value = true
|
|
|
|
|
|
startCountdown(response.countdown)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Reset turnstile state(token 已使用,清除以避免重复使用)
|
2025-12-25 08:41:36 -08:00
|
|
|
|
initialTurnstileToken.value = ''
|
|
|
|
|
|
showResendTurnstile.value = false
|
|
|
|
|
|
resendTurnstileToken.value = ''
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} catch (error: unknown) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const err = error as { message?: string; response?: { data?: { detail?: string } } }
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (err.response?.data?.detail) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = err.response.data.detail
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} else if (err.message) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = err.message
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} else {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = 'Failed to send verification code. Please try again.'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
appStore.showError(errorMessage.value)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} finally {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
isSendingCode.value = false
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== Handlers ====================
|
|
|
|
|
|
|
|
|
|
|
|
async function handleResendCode(): Promise<void> {
|
|
|
|
|
|
// If turnstile is enabled and we haven't shown it yet, show it
|
|
|
|
|
|
if (turnstileEnabled.value && !showResendTurnstile.value) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
showResendTurnstile.value = true
|
|
|
|
|
|
return
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If turnstile is enabled but no token yet, wait
|
|
|
|
|
|
if (turnstileEnabled.value && !resendTurnstileToken.value) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errors.value.turnstile = 'Please complete the verification'
|
|
|
|
|
|
return
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
await sendCode()
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function validateForm(): boolean {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errors.value.code = ''
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (!verifyCode.value.trim()) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errors.value.code = 'Verification code is required'
|
|
|
|
|
|
return false
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!/^\d{6}$/.test(verifyCode.value.trim())) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errors.value.code = 'Please enter a valid 6-digit code'
|
|
|
|
|
|
return false
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
return true
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function handleVerify(): Promise<void> {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = ''
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (!validateForm()) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
return
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
isLoading.value = true
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// Register with verification code
|
|
|
|
|
|
await authStore.register({
|
|
|
|
|
|
email: email.value,
|
|
|
|
|
|
password: password.value,
|
|
|
|
|
|
verify_code: verifyCode.value.trim(),
|
2025-12-25 08:41:36 -08:00
|
|
|
|
turnstile_token: initialTurnstileToken.value || undefined
|
|
|
|
|
|
})
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Clear session data
|
2025-12-25 08:41:36 -08:00
|
|
|
|
sessionStorage.removeItem('register_data')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Show success toast
|
2025-12-25 08:41:36 -08:00
|
|
|
|
appStore.showSuccess('Account created successfully! Welcome to ' + siteName.value + '.')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Redirect to dashboard
|
2025-12-25 08:41:36 -08:00
|
|
|
|
await router.push('/dashboard')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} catch (error: unknown) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const err = error as { message?: string; response?: { data?: { detail?: string } } }
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (err.response?.data?.detail) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = err.response.data.detail
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} else if (err.message) {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = err.message
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} else {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
errorMessage.value = 'Verification failed. Please try again.'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 08:41:36 -08:00
|
|
|
|
appStore.showError(errorMessage.value)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
} finally {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
isLoading.value = false
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleBack(): void {
|
|
|
|
|
|
// Clear session data
|
2025-12-25 08:41:36 -08:00
|
|
|
|
sessionStorage.removeItem('register_data')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Go back to registration
|
2025-12-25 08:41:36 -08:00
|
|
|
|
router.push('/register')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.fade-enter-active,
|
|
|
|
|
|
.fade-leave-active {
|
|
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.fade-enter-from,
|
|
|
|
|
|
.fade-leave-to {
|
|
|
|
|
|
opacity: 0;
|
|
|
|
|
|
transform: translateY(-8px);
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|