Skip to content

Commit d4c8193

Browse files
authored
feat: support reCAPTCHA v3 captcha provider (casdoor#3160)
* feat: support reCAPTCHA v3 captcha provider * fix: modify the implementation of row component style in CaptchaModal.js
1 parent 9b33800 commit d4c8193

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

captcha/provider.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func GetCaptchaProvider(captchaType string) CaptchaProvider {
2626
return NewDefaultCaptchaProvider()
2727
case "reCAPTCHA":
2828
return NewReCaptchaProvider()
29+
case "reCAPTCHA v2":
30+
return NewReCaptchaProvider()
31+
case "reCAPTCHA v3":
32+
return NewReCaptchaProvider()
2933
case "Aliyun Captcha":
3034
return NewAliyunCaptchaProvider()
3135
case "hCaptcha":

web/src/Setting.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ export const OtherProviderInfo = {
287287
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
288288
url: "https://www.google.com/recaptcha",
289289
},
290+
"reCAPTCHA v2": {
291+
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
292+
url: "https://www.google.com/recaptcha",
293+
},
294+
"reCAPTCHA v3": {
295+
logo: `${StaticBaseUrl}/img/social_recaptcha.png`,
296+
url: "https://www.google.com/recaptcha",
297+
},
290298
"hCaptcha": {
291299
logo: `${StaticBaseUrl}/img/social_hcaptcha.png`,
292300
url: "https://www.hcaptcha.com",
@@ -1088,7 +1096,8 @@ export function getProviderTypeOptions(category) {
10881096
} else if (category === "Captcha") {
10891097
return ([
10901098
{id: "Default", name: "Default"},
1091-
{id: "reCAPTCHA", name: "reCAPTCHA"},
1099+
{id: "reCAPTCHA v2", name: "reCAPTCHA v2"},
1100+
{id: "reCAPTCHA v3", name: "reCAPTCHA v3"},
10921101
{id: "hCaptcha", name: "hCaptcha"},
10931102
{id: "Aliyun Captcha", name: "Aliyun Captcha"},
10941103
{id: "GEETEST", name: "GEETEST"},

web/src/common/CaptchaWidget.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export const CaptchaWidget = (props) => {
2727

2828
useEffect(() => {
2929
switch (captchaType) {
30-
case "reCAPTCHA": {
30+
case "reCAPTCHA" :
31+
case "reCAPTCHA v2": {
3132
const reTimer = setInterval(() => {
3233
if (!window.grecaptcha) {
3334
loadScript("https://recaptcha.net/recaptcha/api.js");
@@ -42,6 +43,32 @@ export const CaptchaWidget = (props) => {
4243
}, 300);
4344
break;
4445
}
46+
case "reCAPTCHA v3": {
47+
const reTimer = setInterval(() => {
48+
if (!window.grecaptcha) {
49+
loadScript(`https://recaptcha.net/recaptcha/api.js?render=${siteKey}`);
50+
}
51+
if (window.grecaptcha && window.grecaptcha.render) {
52+
const clientId = window.grecaptcha.render("captcha", {
53+
"sitekey": siteKey,
54+
"badge": "inline",
55+
"size": "invisible",
56+
"callback": onChange,
57+
"error-callback": function() {
58+
const logoWidth = `${document.getElementById("captcha").offsetWidth + 40}px`;
59+
document.getElementsByClassName("grecaptcha-logo")[0].firstChild.style.width = logoWidth;
60+
document.getElementsByClassName("grecaptcha-badge")[0].style.width = logoWidth;
61+
},
62+
});
63+
64+
window.grecaptcha.ready(function() {
65+
window.grecaptcha.execute(clientId, {action: "submit"});
66+
});
67+
clearInterval(reTimer);
68+
}
69+
}, 300);
70+
break;
71+
}
4572
case "hCaptcha": {
4673
const hTimer = setInterval(() => {
4774
if (!window.hcaptcha) {

web/src/common/modal/CaptchaModal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const CaptchaModal = (props) => {
115115
} else {
116116
return (
117117
<Col>
118-
<Row>
118+
<Row justify={"center"}>
119119
<CaptchaWidget
120120
captchaType={captchaType}
121121
subType={subType}

0 commit comments

Comments
 (0)