upd: add FriendlyCaptcha as a captcha solution

FriendlyCaptcha is a german captcha solution which is GDPR compliant and has a non-commerical free license
This commit is contained in:
Marie 2024-11-02 02:20:35 +01:00
parent 8824422cb5
commit d786e96c2b
No known key found for this signature in database
GPG key ID: 7ADF6C9CD9A28555
18 changed files with 175 additions and 7 deletions

View file

@ -27,9 +27,12 @@ export type Captcha = {
execute(id: string): void;
reset(id?: string): void;
getResponse(id: string): string;
WidgetInstance(container: string | Node, options: {
readonly [_ in 'sitekey' | 'doneCallback' | 'errorCallback' | 'puzzleEndpoint']?: unknown;
}): void;
};
export type CaptchaProvider = 'hcaptcha' | 'recaptcha' | 'turnstile' | 'mcaptcha';
export type CaptchaProvider = 'hcaptcha' | 'recaptcha' | 'turnstile' | 'mcaptcha' | 'fc';
type CaptchaContainer = {
readonly [_ in CaptchaProvider]?: Captcha;
@ -60,6 +63,7 @@ const variable = computed(() => {
case 'recaptcha': return 'grecaptcha';
case 'turnstile': return 'turnstile';
case 'mcaptcha': return 'mcaptcha';
case 'fc': return 'friendlyChallenge';
}
});
@ -70,6 +74,7 @@ const src = computed(() => {
case 'hcaptcha': return 'https://js.hcaptcha.com/1/api.js?render=explicit&recaptchacompat=off';
case 'recaptcha': return 'https://www.recaptcha.net/recaptcha/api.js?render=explicit';
case 'turnstile': return 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
case 'fc': return 'https://cdn.jsdelivr.net/npm/friendly-challenge@0.9.18/widget.min.js';
case 'mcaptcha': return null;
}
});
@ -110,6 +115,14 @@ async function requestRender() {
key: props.sitekey,
},
});
} else if (variable.value === 'friendlyChallenge' && captchaEl.value instanceof Element) {
new captcha.value.WidgetInstance(captchaEl.value, {
sitekey: props.sitekey,
doneCallback: callback,
errorCallback: callback,
});
// The following line is needed so that the design gets applied without it the captcha will look broken
captchaEl.value.className = 'frc-captcha';
} else {
window.setTimeout(requestRender, 1);
}