@authing/react-ui-components 3.0.2-beta.5 → 3.0.3
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/lib/index.d.ts +749 -54
- package/lib/index.min.css +2 -2
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.LICENSE.txt +10 -0
- package/package.json +35 -12
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -7
- package/.prettierrc +0 -5
- package/.vscode/settings.json +0 -31
- package/build/asset-manifest.json +0 -26
- package/build/favicon.ico +0 -0
- package/build/index.html +0 -1
- package/build/logo192.png +0 -0
- package/build/logo512.png +0 -0
- package/build/manifest.json +0 -25
- package/build/robots.txt +0 -3
- package/build/static/css/2.51c07e65.chunk.css +0 -3
- package/build/static/css/2.51c07e65.chunk.css.map +0 -1
- package/build/static/css/main.779f221a.chunk.css +0 -2
- package/build/static/css/main.779f221a.chunk.css.map +0 -1
- package/build/static/js/2.bbae9fdb.chunk.js +0 -3
- package/build/static/js/2.bbae9fdb.chunk.js.LICENSE.txt +0 -102
- package/build/static/js/2.bbae9fdb.chunk.js.map +0 -1
- package/build/static/js/3.fd17f196.chunk.js +0 -2
- package/build/static/js/3.fd17f196.chunk.js.map +0 -1
- package/build/static/js/main.5f341531.chunk.js +0 -2
- package/build/static/js/main.5f341531.chunk.js.map +0 -1
- package/build/static/js/runtime-main.ef138021.js +0 -2
- package/build/static/js/runtime-main.ef138021.js.map +0 -1
- package/build/static/media/loading.4a67a5f3.svg +0 -29
- package/components/AuthingDropdown/index.tsx +0 -52
- package/components/AuthingDropdown/style.less +0 -43
- package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
- package/components/AuthingGuard/AppMFALayout/style.less +0 -12
- package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
- package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
- package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
- package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
- package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
- package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
- package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
- package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
- package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
- package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
- package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
- package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
- package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
- package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
- package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
- package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
- package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
- package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
- package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
- package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
- package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
- package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
- package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
- package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
- package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
- package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
- package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
- package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
- package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
- package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
- package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
- package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
- package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
- package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
- package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
- package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
- package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
- package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
- package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
- package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
- package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
- package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
- package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
- package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
- package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
- package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
- package/components/AuthingGuard/Forms/index.ts +0 -13
- package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
- package/components/AuthingGuard/GuardLayout/style.less +0 -111
- package/components/AuthingGuard/Header/index.tsx +0 -25
- package/components/AuthingGuard/Header/style.less +0 -52
- package/components/AuthingGuard/IconFont/iconfont.js +0 -74
- package/components/AuthingGuard/IconFont/index.tsx +0 -19
- package/components/AuthingGuard/IconFont/style.less +0 -6
- package/components/AuthingGuard/IconFont/svg.js +0 -2
- package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
- package/components/AuthingGuard/LoginLayout/style.less +0 -0
- package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
- package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
- package/components/AuthingGuard/MfaLayout/style.less +0 -3
- package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
- package/components/AuthingGuard/RegisterLayout/style.less +0 -0
- package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
- package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
- package/components/AuthingGuard/api/appConfig.ts +0 -146
- package/components/AuthingGuard/api/index.ts +0 -3
- package/components/AuthingGuard/api/sso.ts +0 -29
- package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
- package/components/AuthingGuard/constants.ts +0 -107
- package/components/AuthingGuard/hooks/index.tsx +0 -70
- package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
- package/components/AuthingGuard/index.tsx +0 -126
- package/components/AuthingGuard/style.less +0 -103
- package/components/AuthingGuard/types/Forms.ts +0 -94
- package/components/AuthingGuard/types/GuardConfig.ts +0 -420
- package/components/AuthingGuard/types/GuardState.ts +0 -7
- package/components/AuthingGuard/types/Locales.ts +0 -12
- package/components/AuthingGuard/types/index.ts +0 -4
- package/components/AuthingTabs/index.tsx +0 -98
- package/components/AuthingTabs/style.less +0 -135
- package/components/BindTotp/core/bindSuccess.tsx +0 -72
- package/components/BindTotp/core/securityCode.tsx +0 -108
- package/components/BindTotp/index.tsx +0 -134
- package/components/BindTotp/interface.ts +0 -30
- package/components/BindTotp/styles.less +0 -57
- package/components/ChangeLanguage/index.tsx +0 -35
- package/components/ChangePassword/core/firstLoginReset.tsx +0 -111
- package/components/ChangePassword/core/rotateReset.tsx +0 -114
- package/components/ChangePassword/index.tsx +0 -72
- package/components/CompleteInfo/core/completeInfo.tsx +0 -155
- package/components/CompleteInfo/index.tsx +0 -45
- package/components/CompleteInfo/interface.ts +0 -40
- package/components/CompleteInfo/styles.less +0 -7
- package/components/CopyAbleText/index.tsx +0 -54
- package/components/CopyAbleText/style.less +0 -13
- package/components/DownloadAuthenticator/index.tsx +0 -97
- package/components/DownloadAuthenticator/interface.ts +0 -22
- package/components/DownloadAuthenticator/styles.less +0 -52
- package/components/Error/index.tsx +0 -21
- package/components/Error/interface.ts +0 -9
- package/components/Error/styles.less +0 -12
- package/components/ForgetPassword/core/resetPassword.tsx +0 -162
- package/components/ForgetPassword/index.tsx +0 -78
- package/components/ForgetPassword/interface.ts +0 -32
- package/components/Guard/Guard.tsx +0 -295
- package/components/Guard/authClient.ts +0 -44
- package/components/Guard/config.ts +0 -19
- package/components/Guard/event.ts +0 -52
- package/components/Guard/index.tsx +0 -4
- package/components/Guard/module.ts +0 -20
- package/components/Guard/stateMachine.ts +0 -152
- package/components/Guard/styles.less +0 -461
- package/components/IconFont/iconfont.js +0 -74
- package/components/IconFont/index.tsx +0 -16
- package/components/IconFont/style.less +0 -6
- package/components/IconFont/svg.js +0 -2
- package/components/ImagePro/index.tsx +0 -53
- package/components/ImagePro/styles.less +0 -40
- package/components/InputNumber/index.tsx +0 -33
- package/components/Login/codemap.ts +0 -49
- package/components/Login/core/withAD.tsx +0 -9
- package/components/Login/core/withAppQrcode.tsx +0 -49
- package/components/Login/core/withLDAP.tsx +0 -146
- package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
- package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -30
- package/components/Login/core/withPassword/InputAccount.tsx +0 -64
- package/components/Login/core/withPassword/index.tsx +0 -173
- package/components/Login/core/withPhonecode.tsx +0 -122
- package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
- package/components/Login/core/withWechatmpQrcode.tsx +0 -53
- package/components/Login/index.tsx +0 -374
- package/components/Login/props.ts +0 -74
- package/components/Login/socialLogin/index.tsx +0 -407
- package/components/Login/socialLogin/style.less +0 -69
- package/components/Login/styles.less +0 -53
- package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
- package/components/MFA/VerifyCodeInput/index.tsx +0 -145
- package/components/MFA/VerifyCodeInput/style.less +0 -35
- package/components/MFA/codemap.ts +0 -24
- package/components/MFA/core/email.tsx +0 -203
- package/components/MFA/core/face.tsx +0 -297
- package/components/MFA/core/face_deps.tsx +0 -37
- package/components/MFA/core/sms.tsx +0 -203
- package/components/MFA/core/totp.tsx +0 -122
- package/components/MFA/index.tsx +0 -143
- package/components/MFA/mfaMethods/index.tsx +0 -88
- package/components/MFA/mfaMethods/style.less +0 -39
- package/components/MFA/props.ts +0 -51
- package/components/MFA/styles.less +0 -100
- package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
- package/components/NeedHelpView/index.tsx +0 -47
- package/components/RecoveryCode/core/useCode.tsx +0 -71
- package/components/RecoveryCode/index.tsx +0 -27
- package/components/RecoveryCode/interface.ts +0 -31
- package/components/RecoveryCode/style.less +0 -13
- package/components/Register/codemap.ts +0 -12
- package/components/Register/components/Agreements/index.tsx +0 -81
- package/components/Register/components/Agreements/style.less +0 -44
- package/components/Register/core/WithEmail.tsx +0 -242
- package/components/Register/core/WithPhone.tsx +0 -184
- package/components/Register/index.tsx +0 -139
- package/components/Register/props.ts +0 -50
- package/components/SendCode/SendCodeBtn.tsx +0 -96
- package/components/SendCode/index.tsx +0 -94
- package/components/SendCode/style.less +0 -31
- package/components/ShieldSpin/index.tsx +0 -27
- package/components/ShieldSpin/loading.svg +0 -29
- package/components/SubmitButton/index.tsx +0 -50
- package/components/SubmitSuccess/index.tsx +0 -66
- package/components/SubmitSuccess/interface.ts +0 -17
- package/components/Type/index.ts +0 -52
- package/components/ValidatorRules/ValidatorFormItem.tsx +0 -139
- package/components/ValidatorRules/index.ts +0 -20
- package/components/VerifyCodeInput/index.tsx +0 -76
- package/components/VerifyCodeInput/style.less +0 -24
- package/components/_utils/GuardErrorCode.ts +0 -9
- package/components/_utils/clipboard.ts +0 -27
- package/components/_utils/config.ts +0 -116
- package/components/_utils/guradHttp.ts +0 -101
- package/components/_utils/hooks/index.ts +0 -64
- package/components/_utils/http.ts +0 -85
- package/components/_utils/index.ts +0 -326
- package/components/_utils/locales/en/common.json +0 -229
- package/components/_utils/locales/en/index.ts +0 -6
- package/components/_utils/locales/en/login.json +0 -96
- package/components/_utils/locales/en/map.json +0 -4
- package/components/_utils/locales/en/user.json +0 -82
- package/components/_utils/locales/index.ts +0 -45
- package/components/_utils/locales/zh/common.json +0 -229
- package/components/_utils/locales/zh/index.ts +0 -6
- package/components/_utils/locales/zh/login.json +0 -96
- package/components/_utils/locales/zh/map.json +0 -4
- package/components/_utils/locales/zh/user.json +0 -83
- package/components/_utils/popupCenter.ts +0 -48
- package/components/assets/images/error.png +0 -0
- package/components/context/base.tsx +0 -28
- package/components/context/global/context.tsx +0 -39
- package/components/context/global/reducer.tsx +0 -56
- package/components/context/module/context.tsx +0 -23
- package/components/index.ts +0 -12
- package/config/antdReplacer.js +0 -51
- package/config/env.js +0 -104
- package/config/getHttpsConfig.js +0 -66
- package/config/jest/cssTransform.js +0 -14
- package/config/jest/fileTransform.js +0 -40
- package/config/modules.js +0 -134
- package/config/paths.js +0 -71
- package/config/pnpTs.js +0 -35
- package/config/webpack.config.js +0 -835
- package/config/webpackDevServer.config.js +0 -130
- package/examples.tsx +0 -87
- package/index.js +0 -1
- package/logo.svg +0 -7
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/react-app-env.d.ts +0 -71
- package/reportWebVitals.ts +0 -15
- package/scripts/build.js +0 -208
- package/scripts/lib.js +0 -200
- package/scripts/publish.js +0 -57
- package/scripts/start.js +0 -162
- package/scripts/test.js +0 -49
- package/setupTests.ts +0 -5
- package/tsconfig.json +0 -30
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useMemo,
|
|
5
|
-
useReducer,
|
|
6
|
-
useState,
|
|
7
|
-
} from 'react'
|
|
8
|
-
import { ConfigProvider, message, Modal } from 'antd'
|
|
9
|
-
|
|
10
|
-
import { GuardLoginView } from '../Login'
|
|
11
|
-
|
|
12
|
-
import { initAuthClient } from './authClient'
|
|
13
|
-
import { GuardEvents, guardEventsFilter } from './event'
|
|
14
|
-
import { initConfig } from '../_utils/config'
|
|
15
|
-
import { insertStyles } from '../_utils'
|
|
16
|
-
import { getGuardHttp, GuardHttp, initGuardHttp } from '../_utils/guradHttp'
|
|
17
|
-
import { initI18n } from '..//_utils/locales'
|
|
18
|
-
import { IG2FCProps } from '../Type'
|
|
19
|
-
import { getDefaultGuardLocalConfig, GuardLocalConfig } from './config'
|
|
20
|
-
import { ShieldSpin } from '../ShieldSpin'
|
|
21
|
-
import { GuardModuleType } from './module'
|
|
22
|
-
import { GuardMFAView } from '../MFA'
|
|
23
|
-
import { GuardRegisterView } from '../Register'
|
|
24
|
-
import { GuardDownloadATView } from '../DownloadAuthenticator'
|
|
25
|
-
import {
|
|
26
|
-
GuardStateMachine,
|
|
27
|
-
initGuardStateMachine,
|
|
28
|
-
useHistoryHijack,
|
|
29
|
-
} from './stateMachine'
|
|
30
|
-
import { GuardBindTotpView } from '../BindTotp'
|
|
31
|
-
import { GuardForgetPassword } from '../ForgetPassword'
|
|
32
|
-
import { GuardChangePassword } from '../ChangePassword'
|
|
33
|
-
import { GuardNeedHelpView } from '../NeedHelpView'
|
|
34
|
-
import { GuardCompleteInfoView } from '../CompleteInfo'
|
|
35
|
-
import { GuardRecoveryCodeView } from '../RecoveryCode'
|
|
36
|
-
import './styles.less'
|
|
37
|
-
import { IconFont } from '../AuthingGuard/IconFont'
|
|
38
|
-
import { GuardErrorView } from '../Error'
|
|
39
|
-
import { AuthenticationClient, GuardMode } from '..'
|
|
40
|
-
import { GuardSubmitSuccessView } from '../SubmitSuccess'
|
|
41
|
-
|
|
42
|
-
const PREFIX_CLS = 'authing-ant'
|
|
43
|
-
|
|
44
|
-
message.config({
|
|
45
|
-
prefixCls: `${PREFIX_CLS}-message`,
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const ComponentsMapping: Record<
|
|
49
|
-
GuardModuleType,
|
|
50
|
-
(props: GuardViewProps) => React.ReactNode
|
|
51
|
-
> = {
|
|
52
|
-
[GuardModuleType.ERROR]: (props) => <GuardErrorView {...props} />,
|
|
53
|
-
[GuardModuleType.LOGIN]: (props) => <GuardLoginView {...props} />,
|
|
54
|
-
[GuardModuleType.MFA]: (props) => <GuardMFAView {...props} />,
|
|
55
|
-
[GuardModuleType.REGISTER]: (props) => <GuardRegisterView {...props} />,
|
|
56
|
-
[GuardModuleType.DOWNLOAD_AT]: (props) => <GuardDownloadATView {...props} />,
|
|
57
|
-
[GuardModuleType.FORGET_PWD]: (props) => <GuardForgetPassword {...props} />,
|
|
58
|
-
[GuardModuleType.CHANGE_PWD]: (props) => <GuardChangePassword {...props} />,
|
|
59
|
-
[GuardModuleType.BIND_TOTP]: (props) => <GuardBindTotpView {...props} />,
|
|
60
|
-
[GuardModuleType.ANY_QUESTIONS]: (props) => <GuardNeedHelpView {...props} />,
|
|
61
|
-
[GuardModuleType.COMPLETE_INFO]: (props) => (
|
|
62
|
-
<GuardCompleteInfoView {...props} />
|
|
63
|
-
),
|
|
64
|
-
[GuardModuleType.RECOVERY_CODE]: (props) => (
|
|
65
|
-
<GuardRecoveryCodeView {...props} />
|
|
66
|
-
),
|
|
67
|
-
[GuardModuleType.SUBMIT_SUCCESS]: (props) => (
|
|
68
|
-
<GuardSubmitSuccessView {...props} />
|
|
69
|
-
),
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 首页 init 数据
|
|
73
|
-
const initState: ModuleState = {
|
|
74
|
-
moduleName: GuardModuleType.LOGIN,
|
|
75
|
-
initData: {},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface GuardProps extends GuardEvents, IG2FCProps {
|
|
79
|
-
tenantId?: string
|
|
80
|
-
config?: Partial<GuardLocalConfig>
|
|
81
|
-
visible?: boolean
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
interface GuardViewProps extends GuardProps {
|
|
85
|
-
config: GuardLocalConfig
|
|
86
|
-
initData: any
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
interface IBaseAction<T = string, P = any> {
|
|
90
|
-
type: T & string
|
|
91
|
-
payload?: Partial<P>
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface ModuleState {
|
|
95
|
-
moduleName: GuardModuleType
|
|
96
|
-
initData: any
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const Guard = (props: GuardProps) => {
|
|
100
|
-
const { appId, tenantId, config } = props
|
|
101
|
-
|
|
102
|
-
// 初始化 Loading 标识
|
|
103
|
-
const [initSettingEnd, setInitSettingEnd] = useState(false)
|
|
104
|
-
|
|
105
|
-
const [initError, setInitError] = useState(false)
|
|
106
|
-
const [errorData, setErrorData] = useState<any>()
|
|
107
|
-
|
|
108
|
-
// Config
|
|
109
|
-
const [GuardLocalConfig, setGuardLocalConfig] = useState<GuardLocalConfig>()
|
|
110
|
-
|
|
111
|
-
const [events, setEvents] = useState<GuardEvents>()
|
|
112
|
-
const [authClint, setAuthClint] = useState<AuthenticationClient>()
|
|
113
|
-
const [httpClint, setHttpClint] = useState<GuardHttp>()
|
|
114
|
-
|
|
115
|
-
// 状态机
|
|
116
|
-
const [
|
|
117
|
-
guardStateMachine,
|
|
118
|
-
setGuardStateMachine,
|
|
119
|
-
] = useState<GuardStateMachine>()
|
|
120
|
-
|
|
121
|
-
// 劫持浏览器 History
|
|
122
|
-
const [historyNext] = useHistoryHijack(guardStateMachine?.back)
|
|
123
|
-
|
|
124
|
-
// modules 定义
|
|
125
|
-
const moduleReducer: (
|
|
126
|
-
state: ModuleState,
|
|
127
|
-
action: IBaseAction<GuardModuleType, ModuleState>
|
|
128
|
-
) => ModuleState = (state, { type, payload }) => {
|
|
129
|
-
return {
|
|
130
|
-
moduleName: type,
|
|
131
|
-
initData: payload?.initData,
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Modules Reducer
|
|
136
|
-
const [moduleState, changeModule] = useReducer(moduleReducer, initState)
|
|
137
|
-
|
|
138
|
-
// 切换 Module
|
|
139
|
-
const onChangeModule = (moduleName: GuardModuleType, initData: any = {}) => {
|
|
140
|
-
changeModule({
|
|
141
|
-
type: moduleName,
|
|
142
|
-
payload: {
|
|
143
|
-
initData: initData ?? {},
|
|
144
|
-
},
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// HttpClint
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
if (!appId) return
|
|
151
|
-
|
|
152
|
-
const httpClient = initGuardHttp(
|
|
153
|
-
config?.host ?? getDefaultGuardLocalConfig().host
|
|
154
|
-
)
|
|
155
|
-
httpClient.setAppId(appId)
|
|
156
|
-
tenantId && httpClient.setTenantId(tenantId)
|
|
157
|
-
setHttpClint(httpClient)
|
|
158
|
-
}, [appId, config?.host, tenantId])
|
|
159
|
-
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
if (httpClint && GuardLocalConfig && GuardLocalConfig.__appHost__) {
|
|
162
|
-
httpClint?.setBaseUrl(GuardLocalConfig.__appHost__)
|
|
163
|
-
}
|
|
164
|
-
}, [GuardLocalConfig, httpClint])
|
|
165
|
-
|
|
166
|
-
// I18n
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
// TODO 国际化 这部分有点小问题 等待优化
|
|
169
|
-
initI18n({}, config?.lang)
|
|
170
|
-
}, [config?.lang])
|
|
171
|
-
|
|
172
|
-
// AuthClient
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
if (appId && GuardLocalConfig) {
|
|
175
|
-
const authClint = initAuthClient(GuardLocalConfig, appId, tenantId)
|
|
176
|
-
setAuthClint(authClint)
|
|
177
|
-
}
|
|
178
|
-
}, [GuardLocalConfig, appId, tenantId])
|
|
179
|
-
|
|
180
|
-
// initEvents
|
|
181
|
-
useEffect(() => {
|
|
182
|
-
const events = guardEventsFilter(props)
|
|
183
|
-
setEvents(events)
|
|
184
|
-
}, [props])
|
|
185
|
-
|
|
186
|
-
// 状态机相关
|
|
187
|
-
useEffect(() => {
|
|
188
|
-
const guardStateMachine = initGuardStateMachine(onChangeModule, initState)
|
|
189
|
-
setGuardStateMachine(guardStateMachine)
|
|
190
|
-
}, [])
|
|
191
|
-
|
|
192
|
-
// 设置 config
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
if (guardStateMachine && GuardLocalConfig)
|
|
195
|
-
guardStateMachine.setConfig(GuardLocalConfig)
|
|
196
|
-
}, [GuardLocalConfig, guardStateMachine])
|
|
197
|
-
|
|
198
|
-
const initPublicConfig = useCallback(async () => {
|
|
199
|
-
if (!config && !appId) return
|
|
200
|
-
try {
|
|
201
|
-
// Config 初始化
|
|
202
|
-
const { config: mergedConfig, publicConfig } = await initConfig(
|
|
203
|
-
appId,
|
|
204
|
-
config ?? {},
|
|
205
|
-
getDefaultGuardLocalConfig()
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
setGuardLocalConfig(mergedConfig)
|
|
209
|
-
|
|
210
|
-
getGuardHttp().setUserpoolId(publicConfig.userPoolId)
|
|
211
|
-
} catch (error: any) {
|
|
212
|
-
setErrorData(error)
|
|
213
|
-
setInitError(true)
|
|
214
|
-
} finally {
|
|
215
|
-
// 初始化 结束
|
|
216
|
-
setInitSettingEnd(true)
|
|
217
|
-
}
|
|
218
|
-
}, [appId, config])
|
|
219
|
-
|
|
220
|
-
useEffect(() => {
|
|
221
|
-
initPublicConfig()
|
|
222
|
-
}, [initPublicConfig])
|
|
223
|
-
|
|
224
|
-
useEffect(() => {
|
|
225
|
-
if (GuardLocalConfig && GuardLocalConfig.contentCss)
|
|
226
|
-
insertStyles(GuardLocalConfig.contentCss)
|
|
227
|
-
}, [GuardLocalConfig])
|
|
228
|
-
|
|
229
|
-
useEffect(() => {
|
|
230
|
-
if (GuardLocalConfig && authClint) events?.onLoad?.(authClint)
|
|
231
|
-
}, [GuardLocalConfig, authClint, events])
|
|
232
|
-
|
|
233
|
-
useEffect(() => {
|
|
234
|
-
if (initError) {
|
|
235
|
-
events?.onLoadError?.(errorData)
|
|
236
|
-
}
|
|
237
|
-
}, [errorData, events, initError])
|
|
238
|
-
|
|
239
|
-
const renderModule = useMemo(() => {
|
|
240
|
-
if (initError)
|
|
241
|
-
return <GuardErrorView initData={{ messages: errorData?.message }} />
|
|
242
|
-
if (initSettingEnd && GuardLocalConfig) {
|
|
243
|
-
return ComponentsMapping[moduleState.moduleName]({
|
|
244
|
-
appId,
|
|
245
|
-
initData: moduleState.initData,
|
|
246
|
-
config: GuardLocalConfig,
|
|
247
|
-
...events,
|
|
248
|
-
__changeModule: (moduleName, initData) => {
|
|
249
|
-
historyNext(initData)
|
|
250
|
-
guardStateMachine?.next(moduleName, initData)
|
|
251
|
-
},
|
|
252
|
-
})
|
|
253
|
-
} else {
|
|
254
|
-
return (
|
|
255
|
-
<div className="g2-init-setting-loading">
|
|
256
|
-
<ShieldSpin size={100} />
|
|
257
|
-
</div>
|
|
258
|
-
)
|
|
259
|
-
}
|
|
260
|
-
}, [
|
|
261
|
-
initSettingEnd,
|
|
262
|
-
GuardLocalConfig,
|
|
263
|
-
initError,
|
|
264
|
-
errorData?.message,
|
|
265
|
-
moduleState.moduleName,
|
|
266
|
-
moduleState.initData,
|
|
267
|
-
appId,
|
|
268
|
-
events,
|
|
269
|
-
historyNext,
|
|
270
|
-
guardStateMachine,
|
|
271
|
-
])
|
|
272
|
-
|
|
273
|
-
return (
|
|
274
|
-
// TODO 这部分缺失 Loging 态
|
|
275
|
-
<ConfigProvider prefixCls={PREFIX_CLS}>
|
|
276
|
-
{config?.mode === GuardMode.Modal ? (
|
|
277
|
-
<Modal
|
|
278
|
-
className="authing-g2-render-module-modal"
|
|
279
|
-
closeIcon={
|
|
280
|
-
<IconFont type="authing-close-line" className="g2-modal-close" />
|
|
281
|
-
}
|
|
282
|
-
visible={props.visible}
|
|
283
|
-
onCancel={props.onClose}
|
|
284
|
-
keyboard={config.escCloseable}
|
|
285
|
-
maskClosable={false} //点击蒙层,是否允许关闭
|
|
286
|
-
getContainer={config.target ? config.target : false}
|
|
287
|
-
>
|
|
288
|
-
<div className="authing-g2-render-module">{renderModule}</div>
|
|
289
|
-
</Modal>
|
|
290
|
-
) : (
|
|
291
|
-
<div className="authing-g2-render-module">{renderModule}</div>
|
|
292
|
-
)}
|
|
293
|
-
</ConfigProvider>
|
|
294
|
-
)
|
|
295
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { AuthenticationClient } from 'authing-js-sdk'
|
|
2
|
-
|
|
3
|
-
import packageConfig from '../../package.json'
|
|
4
|
-
import { GuardLocalConfig } from './config'
|
|
5
|
-
|
|
6
|
-
let authClient: AuthenticationClient
|
|
7
|
-
|
|
8
|
-
export const initAuthClient = (
|
|
9
|
-
config: GuardLocalConfig,
|
|
10
|
-
appId: string,
|
|
11
|
-
tenantId?: string
|
|
12
|
-
) => {
|
|
13
|
-
const host = config.__appHost__ ?? config.host
|
|
14
|
-
const lang = config.lang
|
|
15
|
-
|
|
16
|
-
if (!authClient) {
|
|
17
|
-
try {
|
|
18
|
-
authClient = new AuthenticationClient({
|
|
19
|
-
appHost: host,
|
|
20
|
-
tenantId: tenantId,
|
|
21
|
-
appId,
|
|
22
|
-
lang,
|
|
23
|
-
requestFrom: `Guard-${packageConfig.framework}@${packageConfig.version}`,
|
|
24
|
-
onError: (code, msg: any) => {
|
|
25
|
-
console.error(code, msg)
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
} catch (error) {
|
|
29
|
-
throw error
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return authClient
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const getAuthClient = () => {
|
|
37
|
-
if (!authClient) {
|
|
38
|
-
throw new Error('Please initialize AuthClient')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return authClient
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const useAuthClient = () => getAuthClient()
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { getDefaultLoginConfig, LoginConfig } from '../Login/props'
|
|
2
|
-
import { getDefaultRegisterConfig, RegisterConfig } from '../Register/props'
|
|
3
|
-
|
|
4
|
-
export interface GuardComponentConifg extends Partial<GuardLocalConfig> {}
|
|
5
|
-
|
|
6
|
-
export interface GuardLocalConfig extends RegisterConfig, LoginConfig {}
|
|
7
|
-
|
|
8
|
-
let defaultConfig: GuardLocalConfig
|
|
9
|
-
|
|
10
|
-
export const getDefaultGuardLocalConfig = (): GuardLocalConfig => {
|
|
11
|
-
if (!defaultConfig) {
|
|
12
|
-
defaultConfig = {
|
|
13
|
-
...getDefaultLoginConfig(),
|
|
14
|
-
...getDefaultRegisterConfig(),
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return defaultConfig
|
|
19
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { message } from 'antd'
|
|
2
|
-
import { CompleteInfoEvents } from '../CompleteInfo/interface'
|
|
3
|
-
import { ForgetPasswordEvents } from '../ForgetPassword/interface'
|
|
4
|
-
import { LoginEvents } from '../Login/props'
|
|
5
|
-
import { RegisterEvents } from '../Register/props'
|
|
6
|
-
import { i18n } from '../_utils/locales'
|
|
7
|
-
|
|
8
|
-
export interface GuardEvents
|
|
9
|
-
extends LoginEvents,
|
|
10
|
-
RegisterEvents,
|
|
11
|
-
CompleteInfoEvents,
|
|
12
|
-
ForgetPasswordEvents {}
|
|
13
|
-
|
|
14
|
-
export const guardEventsFilter = (props: any) => {
|
|
15
|
-
const events: GuardEvents = {}
|
|
16
|
-
const eventsName = Object.keys(props).filter((name) => name.startsWith('on'))
|
|
17
|
-
eventsName.forEach((eventName) => {
|
|
18
|
-
events[eventName as keyof GuardEvents] = props[eventName]
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
return guardEventsHijacking(events)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const eventsMapping: Partial<GuardEvents> = {
|
|
25
|
-
onLogin: (...props) => {
|
|
26
|
-
message.success(i18n.t('common.LoginSuccess'))
|
|
27
|
-
return props
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
onRegister: (...props) => {
|
|
31
|
-
message.success(i18n.t('common.registrationSuccess'))
|
|
32
|
-
return props
|
|
33
|
-
},
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const guardEventsHijacking = (events: GuardEvents): GuardEvents => {
|
|
37
|
-
const newEvents: GuardEvents = {}
|
|
38
|
-
Object.keys(eventsMapping).forEach((eventsKey) => {
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
newEvents[eventsKey] = (...props) => {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
const newProps = eventsMapping[eventsKey](...props)
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
events[eventsKey]?.(...newProps)
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
...events,
|
|
50
|
-
...newEvents,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export enum GuardModuleType {
|
|
2
|
-
ERROR = 'error',
|
|
3
|
-
LOGIN = 'login',
|
|
4
|
-
REGISTER = 'register',
|
|
5
|
-
MFA = 'mfa',
|
|
6
|
-
FORGET_PWD = 'forgetPassword',
|
|
7
|
-
CHANGE_PWD = 'changePassword',
|
|
8
|
-
DOWNLOAD_AT = 'downloadAT',
|
|
9
|
-
BIND_TOTP = 'bindTotp',
|
|
10
|
-
ANY_QUESTIONS = 'anyQuestions',
|
|
11
|
-
COMPLETE_INFO = 'completeInfo',
|
|
12
|
-
RECOVERY_CODE = 'recoveryCode',
|
|
13
|
-
SUBMIT_SUCCESS = 'submitSuccess',
|
|
14
|
-
}
|
|
15
|
-
export interface GuardModuleAction {
|
|
16
|
-
action: string
|
|
17
|
-
module?: GuardModuleType
|
|
18
|
-
message?: string
|
|
19
|
-
initData?: any
|
|
20
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
import { GuardComponentConifg, GuardLocalConfig } from './config'
|
|
3
|
-
import { GuardModuleType } from './module'
|
|
4
|
-
const window: Window = require('global/window')
|
|
5
|
-
|
|
6
|
-
export interface ModuleState {
|
|
7
|
-
moduleName: GuardModuleType
|
|
8
|
-
initData?: any
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum ActionType {
|
|
12
|
-
ChangeModule = 'ChangeModule',
|
|
13
|
-
Back = 'Back',
|
|
14
|
-
Init = 'Init',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface StateMachineLog {
|
|
18
|
-
action: ActionType
|
|
19
|
-
date: number
|
|
20
|
-
dataSource: ModuleState
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type ChangeModuleEvent = (
|
|
24
|
-
nextModelu: GuardModuleType,
|
|
25
|
-
initData?: any
|
|
26
|
-
) => void
|
|
27
|
-
|
|
28
|
-
let guardStateMachine: GuardStateMachine
|
|
29
|
-
|
|
30
|
-
export class GuardStateMachine {
|
|
31
|
-
// 计数器
|
|
32
|
-
private order: number = 0
|
|
33
|
-
|
|
34
|
-
// 总体的配置信息
|
|
35
|
-
private config: GuardComponentConifg = {}
|
|
36
|
-
|
|
37
|
-
// 历史记录
|
|
38
|
-
private moduleStateHistory: ModuleState[] = []
|
|
39
|
-
|
|
40
|
-
private changeMouleEvent: ChangeModuleEvent
|
|
41
|
-
|
|
42
|
-
// Log
|
|
43
|
-
private stateMachineLog: Record<number, StateMachineLog> = {}
|
|
44
|
-
|
|
45
|
-
constructor(changeMouleEvent: ChangeModuleEvent, initData: ModuleState) {
|
|
46
|
-
this.changeMouleEvent = changeMouleEvent
|
|
47
|
-
|
|
48
|
-
this.historyPush(initData, ActionType.Init)
|
|
49
|
-
}
|
|
50
|
-
globalWindow = (): Window | undefined =>
|
|
51
|
-
typeof window !== undefined ? window : undefined
|
|
52
|
-
|
|
53
|
-
next = (nextModelu: GuardModuleType, initData: any) => {
|
|
54
|
-
const moduleData: ModuleState = {
|
|
55
|
-
moduleName: nextModelu,
|
|
56
|
-
initData,
|
|
57
|
-
}
|
|
58
|
-
this.changeMouleEvent(nextModelu, initData)
|
|
59
|
-
|
|
60
|
-
this.historyPush(moduleData)
|
|
61
|
-
console.log('next Log', this.stateMachineLog)
|
|
62
|
-
console.log('next History', this.moduleStateHistory)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
back = (initData: any = {}) => {
|
|
66
|
-
if (this.moduleStateHistory.length <= 1) return
|
|
67
|
-
|
|
68
|
-
const backModule = this.moduleStateHistory[1]
|
|
69
|
-
this.changeMouleEvent(backModule.moduleName, {
|
|
70
|
-
...initData,
|
|
71
|
-
...backModule.initData,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
this.moduleStateHistory.splice(0, 1)
|
|
75
|
-
console.log('back Log', this.stateMachineLog)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 业务终点 Log 发送
|
|
79
|
-
end = () => {
|
|
80
|
-
console.log('业务终点 Log', this.stateMachineLog)
|
|
81
|
-
|
|
82
|
-
// TODO 请求
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
historyPush = (
|
|
86
|
-
data: ModuleState,
|
|
87
|
-
actionType: ActionType = ActionType.ChangeModule
|
|
88
|
-
) => {
|
|
89
|
-
this.moduleStateHistory.unshift(data)
|
|
90
|
-
|
|
91
|
-
this.stateMachineLog[this.order++] = {
|
|
92
|
-
action: actionType,
|
|
93
|
-
date: new Date().getTime(),
|
|
94
|
-
dataSource: data,
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (this.moduleStateHistory.length > 10)
|
|
98
|
-
this.moduleStateHistory.splice(10, this.moduleStateHistory.length - 10)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
historyBack = (data: ModuleState) => {
|
|
102
|
-
if (this.moduleStateHistory.length <= 1) return
|
|
103
|
-
|
|
104
|
-
this.moduleStateHistory.splice(0, 1)
|
|
105
|
-
|
|
106
|
-
this.stateMachineLog[this.order++] = {
|
|
107
|
-
action: ActionType.Back,
|
|
108
|
-
date: new Date().getTime(),
|
|
109
|
-
dataSource: data,
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
setConfig = (config: GuardLocalConfig) => {
|
|
114
|
-
this.config = config
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export const useHistoryHijack = (back?: () => void) => {
|
|
119
|
-
const next = (state: any = {}) => {
|
|
120
|
-
window?.history.pushState(state, '', window?.location.href)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
const onPopstate = () => {
|
|
125
|
-
back?.()
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
back && window?.addEventListener('popstate', onPopstate)
|
|
129
|
-
|
|
130
|
-
return () => {
|
|
131
|
-
back && window.removeEventListener('popstate', onPopstate)
|
|
132
|
-
}
|
|
133
|
-
}, [back])
|
|
134
|
-
|
|
135
|
-
return [next]
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export const initGuardStateMachine = (
|
|
139
|
-
changeMouleEvent: ChangeModuleEvent,
|
|
140
|
-
initData: ModuleState
|
|
141
|
-
) => {
|
|
142
|
-
guardStateMachine = new GuardStateMachine(changeMouleEvent, initData)
|
|
143
|
-
return guardStateMachine
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export const getGuardStateMachine = () => {
|
|
147
|
-
if (!guardStateMachine) throw new Error('Please initialize GuardStateMachine')
|
|
148
|
-
|
|
149
|
-
return guardStateMachine
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export const useGuardStateMachine = () => getGuardStateMachine()
|