From cfb1206e134eb900c604dfd265842b9b894a207c Mon Sep 17 00:00:00 2001
From: HFO4 <912394456@qq.com>
Date: Sat, 11 Apr 2020 10:02:19 +0800
Subject: [PATCH] Feat: recaptcha
---
package.json | 1 +
src/component/Admin/Setting/Access.js | 66 +++++++++-
src/component/Login/LoginForm.js | 29 ++++-
src/component/Login/ReCaptcha.js | 15 +++
src/component/Login/ReCaptchaWrapper.js | 163 ++++++++++++++++++++++++
src/component/Login/Register.js | 30 ++++-
src/component/Login/Reset.js | 29 ++++-
src/index.js | 4 +-
yarn.lock | 10 +-
9 files changed, 335 insertions(+), 12 deletions(-)
create mode 100644 src/component/Login/ReCaptcha.js
create mode 100644 src/component/Login/ReCaptchaWrapper.js
diff --git a/package.json b/package.json
index 0e2a110..b887a5d 100644
--- a/package.json
+++ b/package.json
@@ -56,6 +56,7 @@
"react-addons-update": "^15.6.2",
"react-app-polyfill": "^1.0.4",
"react-color": "^2.18.0",
+ "react-async-script": "^1.1.1",
"react-content-loader": "^5.0.2",
"react-dev-utils": "^9.1.0",
"react-dnd": "^9.5.1",
diff --git a/src/component/Admin/Setting/Access.js b/src/component/Admin/Setting/Access.js
index 403ae3c..63f8571 100644
--- a/src/component/Admin/Setting/Access.js
+++ b/src/component/Admin/Setting/Access.js
@@ -45,7 +45,10 @@ export default function Access() {
login_captcha: "0",
reg_captcha: "0",
forget_captcha: "0",
- authn_enabled: "0"
+ authn_enabled: "0",
+ captcha_IsUseReCaptcha: "0",
+ captcha_ReCaptchaKey: "defaultKey",
+ captcha_ReCaptchaSecret: "defaultSecret",
});
const [siteURL, setSiteURL] = useState("");
const [groups, setGroups] = useState([]);
@@ -245,6 +248,67 @@ export default function Access() {
+
+
+
+ }
+ label="使用ReCaptcha验证码"
+ />
+
+ 是否使用ReCaptcha验证码
+
+
+
+
+ {options.captcha_IsUseReCaptcha === "1" && (
+ <>
+
+
+
+ Site KEY
+
+
+
+ 应用管理页面获取到的的 网站密钥
+
+
+
+
+
+
+
+ Secret
+
+
+
+ 应用管理页面获取到的的 秘钥
+
+
+
+ >
+ )}
+
({
layout: {
width: "auto",
@@ -102,6 +103,8 @@ function LoginForm() {
const loginCaptcha = useSelector(state => state.siteConfig.loginCaptcha);
const title = useSelector(state => state.siteConfig.title);
const authn = useSelector(state => state.siteConfig.authn);
+ const useReCaptcha = useSelector(state => state.siteConfig.captcha_IsUseReCaptcha);
+ const reCaptchaKey = useSelector(state => state.siteConfig.captcha_ReCaptchaKey);
const dispatch = useDispatch();
const ToggleSnackbar = useCallback(
@@ -140,7 +143,7 @@ function LoginForm() {
useEffect(() => {
setEmail(query.get("username"));
- if (loginCaptcha) {
+ if (loginCaptcha && !useReCaptcha) {
refreshCaptcha();
}
}, [location,loginCaptcha]);
@@ -244,7 +247,9 @@ function LoginForm() {
.catch(error => {
setLoading(false);
ToggleSnackbar("top", "right", error.message, "warning");
- refreshCaptcha();
+ if (!useReCaptcha) {
+ refreshCaptcha();
+ }
});
};
@@ -300,7 +305,7 @@ function LoginForm() {
autoComplete
/>
- {loginCaptcha && (
+ {loginCaptcha && !useReCaptcha && (
@@ -338,6 +343,24 @@ function LoginForm() {
)}
+ {loginCaptcha && useReCaptcha && (
+
+
+
+
+ setCaptcha(value)
+ }
+ id="captcha"
+ name="captcha"
+ />
+
+ {" "}
+
+ )}
+
)}
+ {forgetCaptcha && useReCaptcha && (
+
+
+
+ setInput({
+ ...input,
+ captcha:value
+ })
+ }
+ id="captcha"
+ name="captcha"
+ />
+ {" "}
+
+ )}