🐛 Fixes captcha
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<div class="h-full flex items-center justify-center">
|
||||
<n-card class="max-w-lg text-center" title="Captcha">
|
||||
<div class="flex justify-center my-4">
|
||||
<div v-if="provider === 'cloudflare'" class="cf-turnstile" :data-sitekey="apiKey" :data-callback="onSuccess"></div>
|
||||
<div v-else-if="provider === 'recaptcha'" class="g-recaptcha" :data-sitekey="apiKey" :data-callback="onSuccess"></div>
|
||||
<div v-else-if="provider === 'hcaptcha'" class="h-captcha" :data-sitekey="apiKey" :data-callback="onSuccess"></div>
|
||||
<div class="flex justify-center mb-4 mt-2">
|
||||
<div v-if="provider === 'cloudflare'" class="cf-turnstile" :data-sitekey="apiKey" data-callback="onTurnstileSuccess"></div>
|
||||
<div v-else-if="provider === 'recaptcha'" class="g-recaptcha" :data-sitekey="apiKey" data-callback="onRecaptchaSuccess"></div>
|
||||
<div v-else-if="provider === 'hcaptcha'" class="h-captcha" :data-sitekey="apiKey" data-callback="onHcaptchaSuccess"></div>
|
||||
<div v-else class="alert alert-warning">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
@@ -78,13 +78,33 @@ const loadCaptchaScript = () => {
|
||||
};
|
||||
|
||||
// Handle successful CAPTCHA verification
|
||||
const onSuccess = (token: string) => {
|
||||
// Send token to parent window if in iframe
|
||||
(window as any).onTurnstileSuccess = (token: string) => {
|
||||
if (window.parent !== window) {
|
||||
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
||||
}
|
||||
|
||||
const redirectUri = route.query.redirect_uri as string;
|
||||
if (redirectUri) {
|
||||
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
||||
}
|
||||
};
|
||||
|
||||
(window as any).onRecaptchaSuccess = (token: string) => {
|
||||
if (window.parent !== window) {
|
||||
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
||||
}
|
||||
|
||||
const redirectUri = route.query.redirect_uri as string;
|
||||
if (redirectUri) {
|
||||
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
||||
}
|
||||
};
|
||||
|
||||
(window as any).onHcaptchaSuccess = (token: string) => {
|
||||
if (window.parent !== window) {
|
||||
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
||||
}
|
||||
|
||||
// Handle redirect if redirect_uri is present
|
||||
const redirectUri = route.query.redirect_uri as string;
|
||||
if (redirectUri) {
|
||||
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
||||
|
Reference in New Issue
Block a user