@springmicro/auth 0.1.9 → 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Index-652aeb8c-BTQ1rBi7.js +2818 -0
- package/dist/Index-c419311f-BOZhAAW3.js +1054 -0
- package/dist/Web3Auth-hACKSouN.js +32769 -0
- package/dist/alphawallet-B7eovdf-.js +26 -0
- package/dist/apexwallet-ysP20G9D.js +93 -0
- package/dist/atoken-BBnNTzcz.js +27 -0
- package/dist/bifrostwallet-CNNBO92h.js +11 -0
- package/dist/binance-DvPgAzCw.js +14 -0
- package/dist/bitget-DZOUrwgy.js +4 -0
- package/dist/bitpie-C_uxmEzw.js +25 -0
- package/dist/bitski-DpzkHNkv.js +4 -0
- package/dist/blockwallet-BL69cqkA.js +8 -0
- package/dist/brave-DnRzMQYW.js +35 -0
- package/dist/ccip-c78d2f16-DLcRlwod.js +165 -0
- package/dist/coin98wallet-CkFdOvXt.js +4 -0
- package/dist/coinbase-CaGNx5if.js +9 -0
- package/dist/core-9rK8tWud.js +7 -0
- package/dist/defiwallet-0AsgJBSy.js +10 -0
- package/dist/detected-CX_JZaUk.js +6 -0
- package/dist/echooo-CmaetT_Z.js +14 -0
- package/dist/enkrypt-BibtwvK7.js +20 -0
- package/dist/exodus-BxzkDWWP.js +4 -0
- package/dist/fordefi-CvKyVwhI.js +6 -0
- package/dist/foxwallet-D7c_LDTf.js +4 -0
- package/dist/frame-CDfNmjUy.js +7 -0
- package/dist/frontier-DqKNSj2z.js +8 -0
- package/dist/huobiwallet-CxSwqa5L.js +14 -0
- package/dist/hyperpay-nmHE3WqM.js +7 -0
- package/dist/icon-2Zqy7pqQ.js +8 -0
- package/dist/icon-CGWI1Ies.js +43 -0
- package/dist/icon-C_O4nprO.js +9 -0
- package/dist/icon-DbgmZCnU.js +9 -0
- package/dist/icon-cAd7RhSC.js +9 -0
- package/dist/icon-duCa3gfT.js +11 -0
- package/dist/imtoken-yENtOTS3.js +17 -0
- package/dist/index-021f6a62-Zz543EDB.js +2583 -0
- package/dist/index-40a497ea-Bn2mC0r7.js +1010 -0
- package/dist/index-BHkXn9Ss.js +4010 -0
- package/dist/index-BaYEABY7.js +7089 -0
- package/dist/index-BtLU53lm.js +6023 -0
- package/dist/index-CynP9H3X.js +6188 -0
- package/dist/index-Dg8m-Szw.js +31 -0
- package/dist/index-Dt6M8ha9.js +161 -0
- package/dist/index-DtJfAdfq.js +5822 -0
- package/dist/index-klU8YB0c.js +1983 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +5 -43
- package/dist/index.umd.cjs +1937 -1
- package/dist/infinitywallet-C8J4FUYw.js +42 -0
- package/dist/kayros-AIrUK1za.js +27 -0
- package/dist/lif3wallet-C5D6r8pg.js +41 -0
- package/dist/liquality-nbCtErVq.js +16 -0
- package/dist/mathwallet-CWkivCXo.js +50 -0
- package/dist/meetone-kKmvI8md.js +13 -0
- package/dist/metamask-BN7yiDV1.js +64 -0
- package/dist/mykey-CQZ6UcLH.js +13 -0
- package/dist/number-BXHWhlom.js +1529 -0
- package/dist/okxwallet-CJLVogh2.js +8 -0
- package/dist/oneInch-CciyZ4Pz.js +72 -0
- package/dist/onekey-Dal8kYjU.js +9 -0
- package/dist/opera-DnKg-TJU.js +24 -0
- package/dist/ownbit-BshJUVuW.js +18 -0
- package/dist/phantom-CJ8dIcov.js +35 -0
- package/dist/rabby-D4thTcd6.js +27 -0
- package/dist/rainbow-mXld6yWV.js +69 -0
- package/dist/roninwallet-ZyYrd-D1.js +9 -0
- package/dist/safeheron-Eg1Jb29V.js +23 -0
- package/dist/safepal-DVIKy94N.js +105 -0
- package/dist/sequence-BS2IbtDg.js +70 -0
- package/dist/stablewallet-jyB079Wb.js +20 -0
- package/dist/status-FrAvQjfn.js +4 -0
- package/dist/subwallet-DMvFqKyY.js +25 -0
- package/dist/talisman-Bp8zUXqB.js +16 -0
- package/dist/tallywallet-B4OS9nIr.js +16 -0
- package/dist/tokenary-C7jjcbQa.js +18 -0
- package/dist/tokenpocket-9ZRPmAFA.js +28 -0
- package/dist/tp-V2em5bdl.js +13 -0
- package/dist/transactionRequest-be6a8ea9-CUKWo5mx.js +1117 -0
- package/dist/trust-gPypS1O7.js +11 -0
- package/dist/xdefi-COVIyGz4.js +38 -0
- package/dist/zeal-DxHbDqm0.js +9 -0
- package/dist/zerion-BfW0UElc.js +8 -0
- package/dist/zodiacpilot-CrId6F4w.js +6 -0
- package/package.json +35 -15
- package/src/auth/config.ts +0 -2
- package/src/components/SignUp.tsx +442 -0
- package/src/components/forms/AgreementModal.tsx +88 -0
- package/src/components/forms/CaptchaController.tsx +94 -0
- package/src/components/forms/CaptchaModal.jsx +171 -0
- package/src/components/forms/CaptchaWidget.jsx +146 -0
- package/src/components/forms/PasswordChecker.ts +88 -0
- package/src/components/forms/SendCodeInput.tsx +149 -0
- package/src/components/forms/SignUpFormItem.tsx +704 -0
- package/src/components/forms/util/application-api.ts +155 -0
- package/src/components/forms/util/auth-api.ts +198 -0
- package/src/components/forms/util/auth-util.tsx +346 -0
- package/src/components/forms/util/core.ts +493 -0
- package/src/components/forms/util/invitation-api.ts +132 -0
- package/src/components/forms/util/provider.tsx +603 -0
- package/src/components/forms/util/user-api.ts +303 -0
- package/src/components/provider/AdfsLoginButton.jsx +38 -0
- package/src/components/provider/AlipayLoginButton.jsx +38 -0
- package/src/components/provider/AppleLoginButton.jsx +38 -0
- package/src/components/provider/AzureADB2CLoginButton.jsx +38 -0
- package/src/components/provider/AzureADLoginButton.jsx +38 -0
- package/src/components/provider/BaiduLoginButton.jsx +38 -0
- package/src/components/provider/BilibiliLoginButton.jsx +37 -0
- package/src/components/provider/CasdoorLoginButton.jsx +38 -0
- package/src/components/provider/DingTalkLoginButton.jsx +37 -0
- package/src/components/provider/DouyinLoginButton.jsx +38 -0
- package/src/components/provider/FacebookLoginButton.jsx +37 -0
- package/src/components/provider/GitHubLoginButton.jsx +37 -0
- package/src/components/provider/GitLabLoginButton.jsx +38 -0
- package/src/components/provider/GiteeLoginButton.jsx +34 -0
- package/src/components/provider/GoogleLoginButton.jsx +68 -0
- package/src/components/provider/InfoflowLoginButton.jsx +38 -0
- package/src/components/provider/LarkLoginButton.jsx +38 -0
- package/src/components/provider/LinkedInLoginButton.jsx +37 -0
- package/src/components/provider/LoginButton.jsx +33 -0
- package/src/components/provider/OktaLoginButton.jsx +38 -0
- package/src/components/provider/Provider.jsx +3 -0
- package/src/components/provider/ProviderButton.jsx +327 -0
- package/src/components/provider/QqLoginButton.jsx +31 -0
- package/src/components/provider/SelfLoginButton.jsx +47 -0
- package/src/components/provider/SlackLoginButton.jsx +38 -0
- package/src/components/provider/SteamLoginButton.jsx +38 -0
- package/src/components/provider/WeComLoginButton.jsx +34 -0
- package/src/components/provider/Web3Auth.jsx +365 -0
- package/src/components/provider/WechatLoginButton.jsx +37 -0
- package/src/components/provider/WeiboLoginButton.jsx +34 -0
- package/src/components/util.tsx +173 -0
- package/src/i18n/en/signup.json +48 -0
- package/src/i18n/index.ts +17 -0
- package/src/index.tsx +6 -1
- package/vite.config.ts +33 -25
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { SignUpFormState } from "../SignUp";
|
|
3
|
+
import type { Application } from "./util/provider";
|
|
4
|
+
|
|
5
|
+
export type AgreementModalProps = {
|
|
6
|
+
application: Application;
|
|
7
|
+
state: SignUpFormState;
|
|
8
|
+
setState: React.Dispatch<React.SetStateAction<SignUpFormState>>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function AgreementModal({
|
|
12
|
+
application,
|
|
13
|
+
state,
|
|
14
|
+
setState,
|
|
15
|
+
}: AgreementModalProps) {
|
|
16
|
+
const [visible, setVisible] = React.useState(false);
|
|
17
|
+
const dialogRef = React.useRef<HTMLDialogElement | null>(null);
|
|
18
|
+
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (!dialogRef.current) {
|
|
21
|
+
dialogRef.current = document.getElementById(
|
|
22
|
+
"agreementDialog"
|
|
23
|
+
) as HTMLDialogElement | null;
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
if (dialogRef.current) {
|
|
29
|
+
if (visible) {
|
|
30
|
+
dialogRef.current.showModal();
|
|
31
|
+
} else {
|
|
32
|
+
dialogRef.current.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, [visible]);
|
|
36
|
+
|
|
37
|
+
const handleCancel = () => {
|
|
38
|
+
setState({ ...state, agreement: false });
|
|
39
|
+
setVisible(false);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleOk = () => {
|
|
43
|
+
setState({ ...state, agreement: true });
|
|
44
|
+
setVisible(false);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleOpen = () => {
|
|
48
|
+
setVisible(true);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
<dialog id="agreementDialog" className="modal">
|
|
54
|
+
<div className="modal-box">
|
|
55
|
+
<div className="mt-4 mb-8">
|
|
56
|
+
<iframe
|
|
57
|
+
src={application.termsOfUse}
|
|
58
|
+
width="100%"
|
|
59
|
+
height="300px"
|
|
60
|
+
sandbox="allow-scripts"
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
<div className="modal-action">
|
|
64
|
+
<form method="dialog" className="modal-backdrop">
|
|
65
|
+
{/* if there is a button in form, it will close the modal */}
|
|
66
|
+
<button>Close</button>
|
|
67
|
+
</form>
|
|
68
|
+
<form method="dialog" className="flex gap-3">
|
|
69
|
+
<button className="btn" onClick={handleCancel} key="closebtn">
|
|
70
|
+
Cancel
|
|
71
|
+
</button>
|
|
72
|
+
<button
|
|
73
|
+
className="btn btn-primary"
|
|
74
|
+
// disabled={isOkDisabled}
|
|
75
|
+
onClick={handleOk}
|
|
76
|
+
key="okbtn"
|
|
77
|
+
>
|
|
78
|
+
OK
|
|
79
|
+
</button>
|
|
80
|
+
</form>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</dialog>
|
|
84
|
+
<input checked={!!state.agreement} type="checkbox" readOnly />
|
|
85
|
+
<button onClick={handleOpen}>Open Terms</button>
|
|
86
|
+
</>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CaptchaModal } from "./CaptchaModal";
|
|
3
|
+
import * as AuthBackend from "./util/auth-api";
|
|
4
|
+
|
|
5
|
+
type CaptchaState = {
|
|
6
|
+
values: any;
|
|
7
|
+
openCaptchaModal: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default function CaptchaController() {
|
|
11
|
+
const [state, setState] = React.useState<CaptchaState>({
|
|
12
|
+
values: {},
|
|
13
|
+
openCaptchaModal: false,
|
|
14
|
+
});
|
|
15
|
+
const dialogRef = React.useRef<HTMLElement | null>(null);
|
|
16
|
+
|
|
17
|
+
const handleClick = () => {
|
|
18
|
+
if (dialogRef.current) {
|
|
19
|
+
if (!state.openCaptchaModal) {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
dialogRef.current.showModal();
|
|
22
|
+
} else {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
dialogRef.current.close();
|
|
25
|
+
}
|
|
26
|
+
setState({ ...state, openCaptchaModal: !state.openCaptchaModal });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const captchaCallback = (v: any) => {
|
|
31
|
+
console.log(v);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const onOk = (
|
|
35
|
+
captchaType: string,
|
|
36
|
+
captchaToken: string,
|
|
37
|
+
clientSecret: string
|
|
38
|
+
) => {
|
|
39
|
+
if (dialogRef.current) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
dialogRef.current.close();
|
|
42
|
+
const values = state.values;
|
|
43
|
+
values["captchaType"] = captchaType;
|
|
44
|
+
values["captchaToken"] = captchaToken;
|
|
45
|
+
values["clientSecret"] = clientSecret;
|
|
46
|
+
AuthBackend.getCaptchaStatus(values).then((res) => {
|
|
47
|
+
if (res.status === "ok") {
|
|
48
|
+
// errors
|
|
49
|
+
if (res.data) {
|
|
50
|
+
setState({
|
|
51
|
+
openCaptchaModal: true,
|
|
52
|
+
values: values,
|
|
53
|
+
});
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
captchaCallback(values);
|
|
58
|
+
});
|
|
59
|
+
setState({ ...state, openCaptchaModal: false });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const onCancel = () => {
|
|
64
|
+
if (dialogRef.current) {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
dialogRef.current.close();
|
|
67
|
+
setState({ ...state, openCaptchaModal: false });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
dialogRef.current = document.getElementById("captcha-modal");
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<CaptchaModal
|
|
78
|
+
visible={state.openCaptchaModal}
|
|
79
|
+
owner="admin"
|
|
80
|
+
name="provider_captcha_default"
|
|
81
|
+
isCurrentProvider={true}
|
|
82
|
+
onCancel={onCancel}
|
|
83
|
+
onOk={onOk}
|
|
84
|
+
/>
|
|
85
|
+
<button
|
|
86
|
+
className="btn btn-primary"
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
onClick={handleClick}
|
|
89
|
+
>
|
|
90
|
+
Captcha
|
|
91
|
+
</button>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Copyright 2022 The Casdoor Authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import React, { useEffect } from "react";
|
|
16
|
+
import * as UserBackend from "./util/user-api";
|
|
17
|
+
import { CaptchaWidget } from "./CaptchaWidget";
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
19
|
+
|
|
20
|
+
export const CaptchaModal = (props) => {
|
|
21
|
+
const { t } = useTranslation();
|
|
22
|
+
const { owner, name, visible, onOk, onCancel, isCurrentProvider } = props;
|
|
23
|
+
|
|
24
|
+
const [captchaType, setCaptchaType] = React.useState("none");
|
|
25
|
+
const [clientId, setClientId] = React.useState("");
|
|
26
|
+
const [clientSecret, setClientSecret] = React.useState("");
|
|
27
|
+
const [subType, setSubType] = React.useState("");
|
|
28
|
+
const [clientId2, setClientId2] = React.useState("");
|
|
29
|
+
const [clientSecret2, setClientSecret2] = React.useState("");
|
|
30
|
+
|
|
31
|
+
const [open, setOpen] = React.useState(false);
|
|
32
|
+
const [captchaImg, setCaptchaImg] = React.useState("");
|
|
33
|
+
const [captchaToken, setCaptchaToken] = React.useState("");
|
|
34
|
+
|
|
35
|
+
const defaultInputRef = React.useRef(null);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (visible) {
|
|
39
|
+
loadCaptcha();
|
|
40
|
+
} else {
|
|
41
|
+
handleCancel();
|
|
42
|
+
setOpen(false);
|
|
43
|
+
}
|
|
44
|
+
}, [visible]);
|
|
45
|
+
|
|
46
|
+
const handleOk = () => {
|
|
47
|
+
onOk?.(captchaType, captchaToken, clientSecret);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleCancel = () => {
|
|
51
|
+
setCaptchaToken("");
|
|
52
|
+
onCancel?.();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const loadCaptcha = () => {
|
|
56
|
+
UserBackend.getCaptcha(owner, name, isCurrentProvider).then((res) => {
|
|
57
|
+
if (res.type === "none") {
|
|
58
|
+
handleOk();
|
|
59
|
+
} else if (res.type === "Default") {
|
|
60
|
+
setOpen(true);
|
|
61
|
+
setClientSecret(res.captchaId);
|
|
62
|
+
setCaptchaImg(res.captchaImage);
|
|
63
|
+
setCaptchaType("Default");
|
|
64
|
+
} else {
|
|
65
|
+
setOpen(true);
|
|
66
|
+
setCaptchaType(res.type);
|
|
67
|
+
setClientId(res.clientId);
|
|
68
|
+
setClientSecret(res.clientSecret);
|
|
69
|
+
setSubType(res.subType);
|
|
70
|
+
setClientId2(res.clientId2);
|
|
71
|
+
setClientSecret2(res.clientSecret2);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const renderDefaultCaptcha = () => {
|
|
77
|
+
return (
|
|
78
|
+
<div className="flex flex-col items-center">
|
|
79
|
+
<div
|
|
80
|
+
className="bg-no-repeat mb-4 border border-current rounded w-[200px] h-[80px]"
|
|
81
|
+
style={{
|
|
82
|
+
backgroundImage: `url('data:image/png;base64,${captchaImg}')`,
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
<input
|
|
86
|
+
className="input input-bordered w-[200px]"
|
|
87
|
+
type="text"
|
|
88
|
+
ref={defaultInputRef}
|
|
89
|
+
value={captchaToken}
|
|
90
|
+
// prefix={<SafetyOutlined />}
|
|
91
|
+
placeholder={t("general.captcha")}
|
|
92
|
+
onKeyDown={(e) => (e.key === "Enter" ? handleOk() : null)}
|
|
93
|
+
onChange={(e) => setCaptchaToken(e.target.value)}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const onChange = (token) => {
|
|
100
|
+
setCaptchaToken(token);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const renderCaptcha = () => {
|
|
104
|
+
if (captchaType === "Default") {
|
|
105
|
+
return renderDefaultCaptcha();
|
|
106
|
+
} else {
|
|
107
|
+
return (
|
|
108
|
+
<div className="flex justify-center">
|
|
109
|
+
<CaptchaWidget
|
|
110
|
+
captchaType={captchaType}
|
|
111
|
+
subType={subType}
|
|
112
|
+
siteKey={clientId}
|
|
113
|
+
clientSecret={clientSecret}
|
|
114
|
+
onChange={onChange}
|
|
115
|
+
clientId2={clientId2}
|
|
116
|
+
clientSecret2={clientSecret2}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const renderFooter = () => {
|
|
124
|
+
let isOkDisabled = false;
|
|
125
|
+
if (captchaType === "Default") {
|
|
126
|
+
const regex = /^\d{5}$/;
|
|
127
|
+
if (!regex.test(captchaToken)) {
|
|
128
|
+
isOkDisabled = true;
|
|
129
|
+
}
|
|
130
|
+
} else if (captchaToken === "") {
|
|
131
|
+
isOkDisabled = true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return [
|
|
135
|
+
<button className="btn" onClick={handleCancel} key="closebtn">
|
|
136
|
+
Cancel
|
|
137
|
+
</button>,
|
|
138
|
+
<button
|
|
139
|
+
className="btn btn-primary"
|
|
140
|
+
disabled={isOkDisabled}
|
|
141
|
+
onClick={handleOk}
|
|
142
|
+
key="okbtn"
|
|
143
|
+
>
|
|
144
|
+
OK
|
|
145
|
+
</button>,
|
|
146
|
+
];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<dialog id="captcha-modal" className="modal">
|
|
151
|
+
<div className="modal-box">
|
|
152
|
+
<div className="mt-4 mb-8">{renderCaptcha()}</div>
|
|
153
|
+
<div className="modal-action">
|
|
154
|
+
<form method="dialog" className="modal-backdrop">
|
|
155
|
+
{/* if there is a button in form, it will close the modal */}
|
|
156
|
+
<button>Close</button>
|
|
157
|
+
</form>
|
|
158
|
+
<form method="dialog" className="flex gap-3">
|
|
159
|
+
{renderFooter()}
|
|
160
|
+
</form>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
</dialog>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const CaptchaRule = {
|
|
168
|
+
Always: "Always",
|
|
169
|
+
Never: "Never",
|
|
170
|
+
Dynamic: "Dynamic",
|
|
171
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Copyright 2022 The Casdoor Authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import React, { useEffect } from "react";
|
|
16
|
+
|
|
17
|
+
export const CaptchaWidget = (props) => {
|
|
18
|
+
const {
|
|
19
|
+
captchaType,
|
|
20
|
+
subType,
|
|
21
|
+
siteKey,
|
|
22
|
+
clientSecret,
|
|
23
|
+
clientId2,
|
|
24
|
+
clientSecret2,
|
|
25
|
+
onChange,
|
|
26
|
+
} = props;
|
|
27
|
+
|
|
28
|
+
const loadScript = (src) => {
|
|
29
|
+
const tag = document.createElement("script");
|
|
30
|
+
tag.async = false;
|
|
31
|
+
tag.src = src;
|
|
32
|
+
const body = document.getElementsByTagName("body")[0];
|
|
33
|
+
body.appendChild(tag);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
switch (captchaType) {
|
|
38
|
+
case "reCAPTCHA": {
|
|
39
|
+
const reTimer = setInterval(() => {
|
|
40
|
+
if (!window.grecaptcha) {
|
|
41
|
+
loadScript("https://recaptcha.net/recaptcha/api.js");
|
|
42
|
+
}
|
|
43
|
+
if (window.grecaptcha && window.grecaptcha.render) {
|
|
44
|
+
window.grecaptcha.render("captcha", {
|
|
45
|
+
sitekey: siteKey,
|
|
46
|
+
callback: onChange,
|
|
47
|
+
});
|
|
48
|
+
clearInterval(reTimer);
|
|
49
|
+
}
|
|
50
|
+
}, 300);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "hCaptcha": {
|
|
54
|
+
const hTimer = setInterval(() => {
|
|
55
|
+
if (!window.hcaptcha) {
|
|
56
|
+
loadScript("https://js.hcaptcha.com/1/api.js");
|
|
57
|
+
}
|
|
58
|
+
if (window.hcaptcha && window.hcaptcha.render) {
|
|
59
|
+
window.hcaptcha.render("captcha", {
|
|
60
|
+
sitekey: siteKey,
|
|
61
|
+
callback: onChange,
|
|
62
|
+
});
|
|
63
|
+
clearInterval(hTimer);
|
|
64
|
+
}
|
|
65
|
+
}, 300);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "Aliyun Captcha": {
|
|
69
|
+
const AWSCTimer = setInterval(() => {
|
|
70
|
+
if (!window.AWSC) {
|
|
71
|
+
loadScript("https://g.alicdn.com/AWSC/AWSC/awsc.js");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (window.AWSC) {
|
|
75
|
+
if (clientSecret2 && clientSecret2 !== "***") {
|
|
76
|
+
window.AWSC.use(subType, function (state, module) {
|
|
77
|
+
module.init({
|
|
78
|
+
appkey: clientSecret2,
|
|
79
|
+
scene: clientId2,
|
|
80
|
+
renderTo: "captcha",
|
|
81
|
+
success: function (data) {
|
|
82
|
+
onChange(
|
|
83
|
+
`SessionId=${data.sessionId}&AccessKeyId=${siteKey}&Scene=${clientId2}&AppKey=${clientSecret2}&Token=${data.token}&Sig=${data.sig}&RemoteIp=192.168.0.1`
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
clearInterval(AWSCTimer);
|
|
90
|
+
}
|
|
91
|
+
}, 300);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "GEETEST": {
|
|
95
|
+
let getLock = false;
|
|
96
|
+
const gTimer = setInterval(() => {
|
|
97
|
+
if (!window.initGeetest4) {
|
|
98
|
+
loadScript("https://static.geetest.com/v4/gt4.js");
|
|
99
|
+
}
|
|
100
|
+
if (window.initGeetest4 && siteKey && !getLock) {
|
|
101
|
+
const captchaId = String(siteKey);
|
|
102
|
+
window.initGeetest4(
|
|
103
|
+
{
|
|
104
|
+
captchaId,
|
|
105
|
+
product: "float",
|
|
106
|
+
},
|
|
107
|
+
function (captchaObj) {
|
|
108
|
+
if (!getLock) {
|
|
109
|
+
captchaObj.appendTo("#captcha");
|
|
110
|
+
getLock = true;
|
|
111
|
+
}
|
|
112
|
+
captchaObj.onSuccess(function () {
|
|
113
|
+
const result = captchaObj.getValidate();
|
|
114
|
+
onChange(
|
|
115
|
+
`lot_number=${result.lot_number}&captcha_output=${result.captcha_output}&pass_token=${result.pass_token}&gen_time=${result.gen_time}&captcha_id=${siteKey}`
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
clearInterval(gTimer);
|
|
121
|
+
}
|
|
122
|
+
}, 500);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case "Cloudflare Turnstile": {
|
|
126
|
+
const tTimer = setInterval(() => {
|
|
127
|
+
if (!window.turnstile) {
|
|
128
|
+
loadScript("https://challenges.cloudflare.com/turnstile/v0/api.js");
|
|
129
|
+
}
|
|
130
|
+
if (window.turnstile && window.turnstile.render) {
|
|
131
|
+
window.turnstile.render("#captcha", {
|
|
132
|
+
sitekey: siteKey,
|
|
133
|
+
callback: onChange,
|
|
134
|
+
});
|
|
135
|
+
clearInterval(tTimer);
|
|
136
|
+
}
|
|
137
|
+
}, 300);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
default:
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}, [captchaType, subType, siteKey, clientSecret, clientId2, clientSecret2]);
|
|
144
|
+
|
|
145
|
+
return <div id="captcha" />;
|
|
146
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import i18next from "i18next";
|
|
16
|
+
|
|
17
|
+
function isValidOption_AtLeast6(password: string) {
|
|
18
|
+
if (password.length < 6) {
|
|
19
|
+
return i18next.t("user:The password must have at least 6 characters");
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isValidOption_AtLeast8(password: string) {
|
|
25
|
+
if (password.length < 8) {
|
|
26
|
+
return i18next.t("user:The password must have at least 8 characters");
|
|
27
|
+
}
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isValidOption_Aa123(password: string) {
|
|
32
|
+
const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).+$/;
|
|
33
|
+
if (!regex.test(password)) {
|
|
34
|
+
return i18next.t(
|
|
35
|
+
"user:The password must contain at least one uppercase letter, one lowercase letter and one digit"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isValidOption_SpecialChar(password: string) {
|
|
42
|
+
const regex = /^(?=.*[!-/:-@[-`{-~]).+$/;
|
|
43
|
+
if (!regex.test(password)) {
|
|
44
|
+
return i18next.t(
|
|
45
|
+
"user:The password must contain at least one special character"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isValidOption_NoRepeat(password: string) {
|
|
52
|
+
const regex = /(.)\1+/;
|
|
53
|
+
if (regex.test(password)) {
|
|
54
|
+
return i18next.t(
|
|
55
|
+
"user:The password must not contain any repeated characters"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function checkPasswordComplexity(password: string, options: any) {
|
|
62
|
+
if (password.length === 0) {
|
|
63
|
+
return i18next.t("login:Please input your password!");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!options || options.length === 0) {
|
|
67
|
+
options = ["AtLeast6"];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const checkers = {
|
|
71
|
+
AtLeast6: isValidOption_AtLeast6,
|
|
72
|
+
AtLeast8: isValidOption_AtLeast8,
|
|
73
|
+
Aa123: isValidOption_Aa123,
|
|
74
|
+
SpecialChar: isValidOption_SpecialChar,
|
|
75
|
+
NoRepeat: isValidOption_NoRepeat,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (const option of options) {
|
|
79
|
+
const checkerFunc = checkers[option as keyof typeof checkers];
|
|
80
|
+
if (checkerFunc) {
|
|
81
|
+
const errorMsg = checkerFunc(password);
|
|
82
|
+
if (errorMsg !== "") {
|
|
83
|
+
return errorMsg;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return "";
|
|
88
|
+
}
|