feat: add aliyun captcha (#833)

* feat: add aliyun captcha provider

* Rename App key

* fix typo

* Rename HMACSHA1 & Reused clientId2 and clientSecret2

* Update ProviderEditPage.js

* Delete unused import

Co-authored-by: Gucheng <85475922+nomeguy@users.noreply.github.com>
This commit is contained in:
Resulte Lee
2022-06-29 11:31:32 +08:00
committed by GitHub
parent 8a66448365
commit a0e11cc8a0
9 changed files with 272 additions and 34 deletions

View File

@ -14,7 +14,7 @@
import React, { useEffect } from "react";
export const CaptchaWidget = ({ captchaType, siteKey, onChange }) => {
export const CaptchaWidget = ({ captchaType, subType, siteKey, clientSecret, onChange, clientId2, clientSecret2 }) => {
const loadScript = (src) => {
var tag = document.createElement("script");
tag.async = false;
@ -53,11 +53,34 @@ export const CaptchaWidget = ({ captchaType, siteKey, onChange }) => {
}
}, 300);
break;
case "Aliyun Captcha":
const AWSCTimer = setInterval(() => {
if (!window.AWSC) {
loadScript("https://g.alicdn.com/AWSC/AWSC/awsc.js");
}
if (window.AWSC) {
if (clientSecret2 && clientSecret2 !== "***") {
window.AWSC.use(subType, function (state, module) {
module.init({
appkey: clientSecret2,
scene: clientId2,
renderTo: "captcha",
success: function (data) {
onChange(`SessionId=${data.sessionId}&AccessKeyId=${siteKey}&Scene=${clientId2}&AppKey=${clientSecret2}&Token=${data.token}&Sig=${data.sig}&RemoteIp=192.168.0.1`);
},
});
});
}
clearInterval(AWSCTimer);
}
}, 300);
break;
default:
break;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [captchaType, siteKey]);
}, [captchaType, subType, siteKey, clientSecret, clientId2, clientSecret2]);
return <div id="captcha"></div>;
};