mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
feat: support reCAPTCHA v3 captcha provider (#3160)
* feat: support reCAPTCHA v3 captcha provider * fix: modify the implementation of row component style in CaptchaModal.js
This commit is contained in:
parent
9b33800b4c
commit
d4c8193357
@ -26,6 +26,10 @@ func GetCaptchaProvider(captchaType string) CaptchaProvider {
|
|||||||
return NewDefaultCaptchaProvider()
|
return NewDefaultCaptchaProvider()
|
||||||
case "reCAPTCHA":
|
case "reCAPTCHA":
|
||||||
return NewReCaptchaProvider()
|
return NewReCaptchaProvider()
|
||||||
|
case "reCAPTCHA v2":
|
||||||
|
return NewReCaptchaProvider()
|
||||||
|
case "reCAPTCHA v3":
|
||||||
|
return NewReCaptchaProvider()
|
||||||
case "Aliyun Captcha":
|
case "Aliyun Captcha":
|
||||||
return NewAliyunCaptchaProvider()
|
return NewAliyunCaptchaProvider()
|
||||||
case "hCaptcha":
|
case "hCaptcha":
|
||||||
|
@ -287,6 +287,14 @@ export const OtherProviderInfo = {
|
|||||||
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
|
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
|
||||||
url: "https://www.google.com/recaptcha",
|
url: "https://www.google.com/recaptcha",
|
||||||
},
|
},
|
||||||
|
"reCAPTCHA v2": {
|
||||||
|
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
|
||||||
|
url: "https://www.google.com/recaptcha",
|
||||||
|
},
|
||||||
|
"reCAPTCHA v3": {
|
||||||
|
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
|
||||||
|
url: "https://www.google.com/recaptcha",
|
||||||
|
},
|
||||||
"hCaptcha": {
|
"hCaptcha": {
|
||||||
logo: `${StaticBaseUrl}/img/social_hcaptcha.png`,
|
logo: `${StaticBaseUrl}/img/social_hcaptcha.png`,
|
||||||
url: "https://www.hcaptcha.com",
|
url: "https://www.hcaptcha.com",
|
||||||
@ -1088,7 +1096,8 @@ export function getProviderTypeOptions(category) {
|
|||||||
} else if (category === "Captcha") {
|
} else if (category === "Captcha") {
|
||||||
return ([
|
return ([
|
||||||
{id: "Default", name: "Default"},
|
{id: "Default", name: "Default"},
|
||||||
{id: "reCAPTCHA", name: "reCAPTCHA"},
|
{id: "reCAPTCHA v2", name: "reCAPTCHA v2"},
|
||||||
|
{id: "reCAPTCHA v3", name: "reCAPTCHA v3"},
|
||||||
{id: "hCaptcha", name: "hCaptcha"},
|
{id: "hCaptcha", name: "hCaptcha"},
|
||||||
{id: "Aliyun Captcha", name: "Aliyun Captcha"},
|
{id: "Aliyun Captcha", name: "Aliyun Captcha"},
|
||||||
{id: "GEETEST", name: "GEETEST"},
|
{id: "GEETEST", name: "GEETEST"},
|
||||||
|
@ -27,7 +27,8 @@ export const CaptchaWidget = (props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
switch (captchaType) {
|
switch (captchaType) {
|
||||||
case "reCAPTCHA": {
|
case "reCAPTCHA" :
|
||||||
|
case "reCAPTCHA v2": {
|
||||||
const reTimer = setInterval(() => {
|
const reTimer = setInterval(() => {
|
||||||
if (!window.grecaptcha) {
|
if (!window.grecaptcha) {
|
||||||
loadScript("https://recaptcha.net/recaptcha/api.js");
|
loadScript("https://recaptcha.net/recaptcha/api.js");
|
||||||
@ -42,6 +43,32 @@ export const CaptchaWidget = (props) => {
|
|||||||
}, 300);
|
}, 300);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "reCAPTCHA v3": {
|
||||||
|
const reTimer = setInterval(() => {
|
||||||
|
if (!window.grecaptcha) {
|
||||||
|
loadScript(`https://recaptcha.net/recaptcha/api.js?render=${siteKey}`);
|
||||||
|
}
|
||||||
|
if (window.grecaptcha && window.grecaptcha.render) {
|
||||||
|
const clientId = window.grecaptcha.render("captcha", {
|
||||||
|
"sitekey": siteKey,
|
||||||
|
"badge": "inline",
|
||||||
|
"size": "invisible",
|
||||||
|
"callback": onChange,
|
||||||
|
"error-callback": function() {
|
||||||
|
const logoWidth = `${document.getElementById("captcha").offsetWidth + 40}px`;
|
||||||
|
document.getElementsByClassName("grecaptcha-logo")[0].firstChild.style.width = logoWidth;
|
||||||
|
document.getElementsByClassName("grecaptcha-badge")[0].style.width = logoWidth;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
window.grecaptcha.ready(function() {
|
||||||
|
window.grecaptcha.execute(clientId, {action: "submit"});
|
||||||
|
});
|
||||||
|
clearInterval(reTimer);
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "hCaptcha": {
|
case "hCaptcha": {
|
||||||
const hTimer = setInterval(() => {
|
const hTimer = setInterval(() => {
|
||||||
if (!window.hcaptcha) {
|
if (!window.hcaptcha) {
|
||||||
|
@ -115,7 +115,7 @@ export const CaptchaModal = (props) => {
|
|||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Col>
|
<Col>
|
||||||
<Row>
|
<Row justify={"center"}>
|
||||||
<CaptchaWidget
|
<CaptchaWidget
|
||||||
captchaType={captchaType}
|
captchaType={captchaType}
|
||||||
subType={subType}
|
subType={subType}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user