From a0a73f9142eaa723a74ce7ede4125c760ded12c7 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Fri, 25 Apr 2025 23:50:58 +0800 Subject: [PATCH] update --- packages/frontend/src/locales/en.json | 3 +- packages/frontend/src/locales/zh.json | 3 +- packages/frontend/src/views/LoginView.vue | 62 ++++++++++------------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/packages/frontend/src/locales/en.json b/packages/frontend/src/locales/en.json index 51457e5..3aa3bae 100644 --- a/packages/frontend/src/locales/en.json +++ b/packages/frontend/src/locales/en.json @@ -103,7 +103,8 @@ "error": { "captchaLoadFailed": "Failed to load CAPTCHA. Please try refreshing.", "captchaRequired": "Please complete the CAPTCHA verification." - } + }, + "recaptchaV3Notice": "This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply." }, "connections": { "addConnection": "Add New Connection", diff --git a/packages/frontend/src/locales/zh.json b/packages/frontend/src/locales/zh.json index efb9e74..5407fae 100644 --- a/packages/frontend/src/locales/zh.json +++ b/packages/frontend/src/locales/zh.json @@ -103,7 +103,8 @@ "error": { "captchaLoadFailed": "加载 CAPTCHA 失败,请尝试刷新页面。", "captchaRequired": "请完成 CAPTCHA 验证。" - } + }, + "recaptchaV3Notice": "此网站受 reCAPTCHA 保护,并适用 Google 隐私政策和服务条款。" }, "connections": { "addConnection": "添加新连接", diff --git a/packages/frontend/src/views/LoginView.vue b/packages/frontend/src/views/LoginView.vue index ff4852a..2ee4335 100644 --- a/packages/frontend/src/views/LoginView.vue +++ b/packages/frontend/src/views/LoginView.vue @@ -4,7 +4,8 @@ import { storeToRefs } from 'pinia'; import { useI18n } from 'vue-i18n'; import { useAuthStore } from '../stores/auth.store'; import VueHcaptcha from '@hcaptcha/vue3-hcaptcha'; // <-- Import hCaptcha component -import { useReCaptcha } from 'vue-recaptcha-v3'; // <-- Import reCAPTCHA v3 hook +// import { useReCaptcha } from 'vue-recaptcha-v3'; // <-- v3 hook, not needed for v2 widget +// TODO: Import a reCAPTCHA v2 component, e.g., import VueRecaptchaV2 from 'vue-recaptcha-v2'; const { t } = useI18n(); const authStore = useAuthStore(); @@ -21,9 +22,8 @@ const rememberMe = ref(false); // 新增:记住我状态,默认为 false const captchaToken = ref(null); // NEW: Store CAPTCHA token const captchaError = ref(null); // NEW: Store CAPTCHA specific error const hcaptchaWidget = ref | null>(null); // NEW: Ref for hCaptcha component instance - -// --- reCAPTCHA v3 Initialization --- -const recaptchaInstance = useReCaptcha(); // Get the instance, might be undefined +// const recaptchaInstance = useReCaptcha(); // v3 instance, not needed for v2 widget +const recaptchaV2Widget = ref(null); // NEW: Ref for reCAPTCHA v2 component instance (replace 'any' with actual type) // --- CAPTCHA Event Handlers --- @@ -46,7 +46,8 @@ const resetCaptchaWidget = () => { captchaToken.value = null; // Reset hCaptcha if it exists hcaptchaWidget.value?.reset(); - // reCAPTCHA v3 doesn't typically need explicit reset in the same way + // Reset reCAPTCHA v2 if it exists and component supports it + // recaptchaV2Widget.value?.reset(); // Assuming the component has a reset method }; // --- End CAPTCHA Event Handlers --- @@ -56,30 +57,11 @@ const handleSubmit = async () => { captchaError.value = null; // Clear previous CAPTCHA error // --- CAPTCHA Execution & Check --- + // For v2/hCaptcha, the token should already be set by the component's @verify event if (publicCaptchaConfig.value?.enabled && !loginRequires2FA.value) { - // If reCAPTCHA v3, execute it now to get the token - if (publicCaptchaConfig.value.provider === 'recaptcha') { - // Check if instance and methods are available - if (recaptchaInstance?.recaptchaLoaded && recaptchaInstance?.executeRecaptcha) { - try { - await recaptchaInstance.recaptchaLoaded(); // Ensure library is loaded - const token = await recaptchaInstance.executeRecaptcha('login'); // Execute with action 'login' - console.log('reCAPTCHA v3 token obtained:', token); - captchaToken.value = token; // Store the obtained token - } catch (reError: any) { - console.error('reCAPTCHA v3 execution failed:', reError); - captchaError.value = t('login.error.captchaLoadFailed'); - return; // Stop submission if reCAPTCHA execution fails - } - } else { - // Handle case where reCAPTCHA is not ready/initialized - console.error('reCAPTCHA v3 not initialized or ready.'); - captchaError.value = t('login.error.captchaLoadFailed'); // Or a more specific error - return; - } - } + // No programmatic execution needed for v2/hCaptcha here. - // Check if token exists (for both hCaptcha and reCAPTCHA) + // Check if token exists (obtained via @verify callback from either component) if (!captchaToken.value) { captchaError.value = t('login.error.captchaRequired'); return; // Stop submission if CAPTCHA is required but not completed/obtained @@ -169,9 +151,9 @@ onMounted(() => {
- + + -
{ theme="auto" >
- -
-

- {{ t('login.recaptchaV3Notice') }} + +

+ + +
+ 此处需要集成 Google reCAPTCHA v2 组件。 +
+

+ {{ t('login.recaptchaV3Notice') }}

-