@authing/react-ui-components 3.0.2-beta.5 → 3.1.1-rc.1

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.
Files changed (249) hide show
  1. package/.vscode/settings.json +1 -1
  2. package/LICENSE +21 -0
  3. package/config/env.js +26 -24
  4. package/config/paths.js +3 -3
  5. package/config/webpack.config.js +29 -7
  6. package/lib/index.d.ts +211 -1252
  7. package/lib/index.min.css +1 -2
  8. package/lib/index.min.js +1 -1
  9. package/lib/index.min.js.LICENSE.txt +0 -32
  10. package/package.json +14 -20
  11. package/scripts/build.js +83 -79
  12. package/scripts/start.js +73 -69
  13. package/scripts/test.js +23 -19
  14. package/{components → src/common}/AuthingDropdown/index.tsx +1 -1
  15. package/{components → src/common}/AuthingDropdown/style.less +0 -0
  16. package/{components → src/common}/AuthingTabs/index.tsx +1 -1
  17. package/{components → src/common}/AuthingTabs/style.less +0 -0
  18. package/{components → src/common}/CopyAbleText/index.tsx +1 -1
  19. package/{components → src/common}/CopyAbleText/style.less +0 -0
  20. package/{components → src/common}/VerifyCodeInput/index.tsx +0 -0
  21. package/{components → src/common}/VerifyCodeInput/style.less +0 -0
  22. package/{components → src/components}/AuthingGuard/AppMFALayout/index.tsx +2 -2
  23. package/{components → src/components}/AuthingGuard/AppMFALayout/style.less +0 -0
  24. package/{components → src/components}/AuthingGuard/CompleteUserInfoLayout/index.tsx +1 -1
  25. package/{components → src/components}/AuthingGuard/CompleteUserInfoLayout/style.less +0 -0
  26. package/{components → src/components}/AuthingGuard/Forms/ADLoginForm/index.tsx +2 -2
  27. package/{components → src/components}/AuthingGuard/Forms/Agreements/index.tsx +1 -1
  28. package/{components → src/components}/AuthingGuard/Forms/Agreements/style.less +0 -0
  29. package/{components → src/components}/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +3 -3
  30. package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +4 -2
  31. package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +2 -2
  32. package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +1 -1
  33. package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  34. package/{components → src/components}/AuthingGuard/Forms/EmailRegisterForm/index.tsx +2 -2
  35. package/{components → src/components}/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  36. package/{components → src/components}/AuthingGuard/Forms/LdapLoginForm/index.tsx +4 -9
  37. package/{components → src/components}/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  38. package/{components → src/components}/AuthingGuard/Forms/LoginFormFooter/index.tsx +1 -1
  39. package/{components → src/components}/AuthingGuard/Forms/LoginFormFooter/style.less +0 -0
  40. package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +2 -2
  41. package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +1 -1
  42. package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +1 -1
  43. package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -0
  44. package/{components → src/components}/AuthingGuard/Forms/MfaVerifyForm/index.tsx +2 -2
  45. package/{components → src/components}/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -0
  46. package/{components → src/components}/AuthingGuard/Forms/PasswordLoginForm/index.tsx +3 -3
  47. package/{components → src/components}/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +2 -2
  48. package/{components → src/components}/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +2 -2
  49. package/{components → src/components}/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +4 -2
  50. package/{components → src/components}/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -0
  51. package/{components → src/components}/AuthingGuard/Forms/RegisterFormFooter/index.tsx +1 -1
  52. package/{components → src/components}/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  53. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +1 -1
  54. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +2 -2
  55. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +2 -2
  56. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +2 -2
  57. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +1 -1
  58. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/index.tsx +1 -1
  59. package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/style.less +0 -0
  60. package/{components → src/components}/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -0
  61. package/{components → src/components}/AuthingGuard/Forms/SendPhoneCode/index.tsx +2 -2
  62. package/{components → src/components}/AuthingGuard/Forms/SendPhoneCode/style.less +0 -0
  63. package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +2 -2
  64. package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +2 -2
  65. package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +1 -1
  66. package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -0
  67. package/{components → src/components}/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +7 -7
  68. package/{components → src/components}/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -0
  69. package/{components → src/components}/AuthingGuard/Forms/UploadImage/index.tsx +1 -1
  70. package/{components → src/components}/AuthingGuard/Forms/index.ts +0 -0
  71. package/{components → src/components}/AuthingGuard/GuardLayout/index.tsx +17 -3
  72. package/{components → src/components}/AuthingGuard/GuardLayout/style.less +0 -0
  73. package/{components → src/components}/AuthingGuard/Header/index.tsx +6 -3
  74. package/{components → src/components}/AuthingGuard/Header/style.less +23 -11
  75. package/{components → src/components}/AuthingGuard/IconFont/iconfont.js +0 -0
  76. package/{components → src/components}/AuthingGuard/IconFont/index.tsx +1 -1
  77. package/{components → src/components}/AuthingGuard/IconFont/style.less +0 -0
  78. package/{components → src/components}/AuthingGuard/IconFont/svg.js +0 -0
  79. package/{components → src/components}/AuthingGuard/LoginLayout/index.tsx +69 -25
  80. package/{components → src/components}/AuthingGuard/LoginLayout/style.less +0 -0
  81. package/{components → src/components}/AuthingGuard/MfaLayout/Steps.ts +0 -0
  82. package/{components → src/components}/AuthingGuard/MfaLayout/index.tsx +1 -1
  83. package/{components → src/components}/AuthingGuard/MfaLayout/style.less +0 -0
  84. package/{components → src/components}/AuthingGuard/RegisterLayout/index.tsx +2 -2
  85. package/{components → src/components}/AuthingGuard/RegisterLayout/style.less +0 -0
  86. package/{components → src/components}/AuthingGuard/ResetPwdLayout/index.tsx +1 -1
  87. package/{components → src/components}/AuthingGuard/ToggleLang/index.tsx +2 -2
  88. package/{components → src/components}/AuthingGuard/api/appConfig.ts +22 -14
  89. package/{components/_utils → src/components/AuthingGuard/api}/http.ts +33 -30
  90. package/{components → src/components}/AuthingGuard/api/index.ts +0 -0
  91. package/{components → src/components}/AuthingGuard/api/sso.ts +1 -1
  92. package/{components → src/components}/AuthingGuard/api/userPoolConfig.ts +3 -2
  93. package/{components → src/components}/AuthingGuard/constants.ts +2 -2
  94. package/{components → src/components}/AuthingGuard/hooks/index.tsx +0 -0
  95. package/{components → src/components}/AuthingGuard/hooks/useScreenSize.tsx +0 -0
  96. package/{components → src/components}/AuthingGuard/index.tsx +11 -3
  97. package/{components/_utils → src/components/AuthingGuard}/locales/en/common.json +26 -70
  98. package/{components/_utils → src/components/AuthingGuard}/locales/en/index.ts +0 -0
  99. package/{components/_utils → src/components/AuthingGuard}/locales/en/login.json +19 -21
  100. package/{components/_utils → src/components/AuthingGuard}/locales/en/map.json +0 -0
  101. package/{components/_utils → src/components/AuthingGuard}/locales/en/user.json +3 -4
  102. package/{components/_utils → src/components/AuthingGuard}/locales/index.ts +2 -2
  103. package/{components/_utils → src/components/AuthingGuard}/locales/zh/common.json +9 -53
  104. package/{components/_utils → src/components/AuthingGuard}/locales/zh/index.ts +0 -0
  105. package/{components/_utils → src/components/AuthingGuard}/locales/zh/login.json +4 -6
  106. package/{components/_utils → src/components/AuthingGuard}/locales/zh/map.json +0 -0
  107. package/{components/_utils → src/components/AuthingGuard}/locales/zh/user.json +1 -3
  108. package/{components → src/components}/AuthingGuard/style.less +5 -0
  109. package/{components → src/components}/AuthingGuard/types/Forms.ts +2 -1
  110. package/{components → src/components}/AuthingGuard/types/GuardConfig.ts +5 -1
  111. package/{components → src/components}/AuthingGuard/types/GuardState.ts +1 -1
  112. package/{components → src/components}/AuthingGuard/types/Locales.ts +0 -0
  113. package/{components → src/components}/AuthingGuard/types/index.ts +0 -0
  114. package/src/components/index.ts +7 -0
  115. package/{components → src}/context/base.tsx +0 -0
  116. package/{components → src}/context/global/context.tsx +0 -0
  117. package/{components → src}/context/global/reducer.tsx +2 -2
  118. package/src/index.tsx +142 -0
  119. package/{logo.svg → src/logo.svg} +0 -0
  120. package/{react-app-env.d.ts → src/react-app-env.d.ts} +0 -0
  121. package/{reportWebVitals.ts → src/reportWebVitals.ts} +0 -0
  122. package/{setupTests.ts → src/setupTests.ts} +0 -0
  123. package/{components/_utils → src/utils}/clipboard.ts +1 -1
  124. package/{components/_utils → src/utils}/index.ts +3 -149
  125. package/{components/_utils → src/utils}/popupCenter.ts +0 -0
  126. package/tsconfig.json +2 -8
  127. package/build/asset-manifest.json +0 -26
  128. package/build/favicon.ico +0 -0
  129. package/build/index.html +0 -1
  130. package/build/logo192.png +0 -0
  131. package/build/logo512.png +0 -0
  132. package/build/manifest.json +0 -25
  133. package/build/robots.txt +0 -3
  134. package/build/static/css/2.51c07e65.chunk.css +0 -3
  135. package/build/static/css/2.51c07e65.chunk.css.map +0 -1
  136. package/build/static/css/main.779f221a.chunk.css +0 -2
  137. package/build/static/css/main.779f221a.chunk.css.map +0 -1
  138. package/build/static/js/2.bbae9fdb.chunk.js +0 -3
  139. package/build/static/js/2.bbae9fdb.chunk.js.LICENSE.txt +0 -102
  140. package/build/static/js/2.bbae9fdb.chunk.js.map +0 -1
  141. package/build/static/js/3.fd17f196.chunk.js +0 -2
  142. package/build/static/js/3.fd17f196.chunk.js.map +0 -1
  143. package/build/static/js/main.5f341531.chunk.js +0 -2
  144. package/build/static/js/main.5f341531.chunk.js.map +0 -1
  145. package/build/static/js/runtime-main.ef138021.js +0 -2
  146. package/build/static/js/runtime-main.ef138021.js.map +0 -1
  147. package/build/static/media/loading.4a67a5f3.svg +0 -29
  148. package/components/BindTotp/core/bindSuccess.tsx +0 -72
  149. package/components/BindTotp/core/securityCode.tsx +0 -108
  150. package/components/BindTotp/index.tsx +0 -134
  151. package/components/BindTotp/interface.ts +0 -30
  152. package/components/BindTotp/styles.less +0 -57
  153. package/components/ChangeLanguage/index.tsx +0 -35
  154. package/components/ChangePassword/core/firstLoginReset.tsx +0 -111
  155. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  156. package/components/ChangePassword/index.tsx +0 -72
  157. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  158. package/components/CompleteInfo/index.tsx +0 -45
  159. package/components/CompleteInfo/interface.ts +0 -40
  160. package/components/CompleteInfo/styles.less +0 -7
  161. package/components/DownloadAuthenticator/index.tsx +0 -97
  162. package/components/DownloadAuthenticator/interface.ts +0 -22
  163. package/components/DownloadAuthenticator/styles.less +0 -52
  164. package/components/Error/index.tsx +0 -21
  165. package/components/Error/interface.ts +0 -9
  166. package/components/Error/styles.less +0 -12
  167. package/components/ForgetPassword/core/resetPassword.tsx +0 -162
  168. package/components/ForgetPassword/index.tsx +0 -78
  169. package/components/ForgetPassword/interface.ts +0 -32
  170. package/components/Guard/Guard.tsx +0 -295
  171. package/components/Guard/authClient.ts +0 -44
  172. package/components/Guard/config.ts +0 -19
  173. package/components/Guard/event.ts +0 -52
  174. package/components/Guard/index.tsx +0 -4
  175. package/components/Guard/module.ts +0 -20
  176. package/components/Guard/stateMachine.ts +0 -152
  177. package/components/Guard/styles.less +0 -461
  178. package/components/IconFont/iconfont.js +0 -74
  179. package/components/IconFont/index.tsx +0 -16
  180. package/components/IconFont/style.less +0 -6
  181. package/components/IconFont/svg.js +0 -2
  182. package/components/ImagePro/index.tsx +0 -53
  183. package/components/ImagePro/styles.less +0 -40
  184. package/components/InputNumber/index.tsx +0 -33
  185. package/components/Login/codemap.ts +0 -49
  186. package/components/Login/core/withAD.tsx +0 -9
  187. package/components/Login/core/withAppQrcode.tsx +0 -49
  188. package/components/Login/core/withLDAP.tsx +0 -146
  189. package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
  190. package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -30
  191. package/components/Login/core/withPassword/InputAccount.tsx +0 -64
  192. package/components/Login/core/withPassword/index.tsx +0 -173
  193. package/components/Login/core/withPhonecode.tsx +0 -122
  194. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  195. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  196. package/components/Login/index.tsx +0 -374
  197. package/components/Login/props.ts +0 -74
  198. package/components/Login/socialLogin/index.tsx +0 -407
  199. package/components/Login/socialLogin/style.less +0 -69
  200. package/components/Login/styles.less +0 -53
  201. package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
  202. package/components/MFA/VerifyCodeInput/index.tsx +0 -145
  203. package/components/MFA/VerifyCodeInput/style.less +0 -35
  204. package/components/MFA/codemap.ts +0 -24
  205. package/components/MFA/core/email.tsx +0 -203
  206. package/components/MFA/core/face.tsx +0 -297
  207. package/components/MFA/core/face_deps.tsx +0 -37
  208. package/components/MFA/core/sms.tsx +0 -203
  209. package/components/MFA/core/totp.tsx +0 -122
  210. package/components/MFA/index.tsx +0 -143
  211. package/components/MFA/mfaMethods/index.tsx +0 -88
  212. package/components/MFA/mfaMethods/style.less +0 -39
  213. package/components/MFA/props.ts +0 -51
  214. package/components/MFA/styles.less +0 -100
  215. package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
  216. package/components/NeedHelpView/index.tsx +0 -47
  217. package/components/RecoveryCode/core/useCode.tsx +0 -71
  218. package/components/RecoveryCode/index.tsx +0 -27
  219. package/components/RecoveryCode/interface.ts +0 -31
  220. package/components/RecoveryCode/style.less +0 -13
  221. package/components/Register/codemap.ts +0 -12
  222. package/components/Register/components/Agreements/index.tsx +0 -81
  223. package/components/Register/components/Agreements/style.less +0 -44
  224. package/components/Register/core/WithEmail.tsx +0 -242
  225. package/components/Register/core/WithPhone.tsx +0 -184
  226. package/components/Register/index.tsx +0 -139
  227. package/components/Register/props.ts +0 -50
  228. package/components/SendCode/SendCodeBtn.tsx +0 -96
  229. package/components/SendCode/index.tsx +0 -94
  230. package/components/SendCode/style.less +0 -31
  231. package/components/ShieldSpin/index.tsx +0 -27
  232. package/components/ShieldSpin/loading.svg +0 -29
  233. package/components/SubmitButton/index.tsx +0 -50
  234. package/components/SubmitSuccess/index.tsx +0 -66
  235. package/components/SubmitSuccess/interface.ts +0 -17
  236. package/components/Type/index.ts +0 -52
  237. package/components/ValidatorRules/ValidatorFormItem.tsx +0 -139
  238. package/components/ValidatorRules/index.ts +0 -20
  239. package/components/_utils/GuardErrorCode.ts +0 -9
  240. package/components/_utils/config.ts +0 -116
  241. package/components/_utils/guradHttp.ts +0 -101
  242. package/components/_utils/hooks/index.ts +0 -64
  243. package/components/assets/images/error.png +0 -0
  244. package/components/context/module/context.tsx +0 -23
  245. package/components/index.ts +0 -12
  246. package/examples.tsx +0 -87
  247. package/index.js +0 -1
  248. package/lib/static/media/loading.4a67a5f3.svg +0 -29
  249. package/scripts/publish.js +0 -57
@@ -1,162 +0,0 @@
1
- import React, { useRef, useState } from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { Form, Input } from 'antd'
4
- import { StoreValue } from 'antd/lib/form/interface'
5
-
6
- import { UserOutlined, SafetyOutlined, LockOutlined } from '@ant-design/icons'
7
- import { SendCode } from '../../SendCode'
8
-
9
- import { useAuthClient } from '../../Guard/authClient'
10
- import { fieldRequiredRule, getPasswordValidate, validate } from '../../_utils'
11
- import SubmitButton from '../../SubmitButton'
12
-
13
- interface ResetPasswordProps {
14
- onReset: any
15
- publicConfig: any
16
- onSend: (type: 'email' | 'phone') => void
17
- onSendError: (type: 'email' | 'phone', error: any) => void
18
- }
19
- export const ResetPassword = (props: ResetPasswordProps) => {
20
- const { t } = useTranslation()
21
- let [form] = Form.useForm()
22
- let [identify, setIdentify] = useState('')
23
- let [codeMethod, setCodeMethod] = useState<'phone' | 'email'>('phone')
24
- let client = useAuthClient()
25
- let submitButtonRef = useRef<any>(null)
26
-
27
- const verifyCodeLength = props.publicConfig.verifyCodeLength ?? 4
28
-
29
- const onFinish = async (values: any) => {
30
- let identify = values.identify
31
- let code = values.code
32
- let newPassword = values.password
33
- let context = new Promise(() => {})
34
-
35
- if (codeMethod === 'email') {
36
- context = client.resetPasswordByEmailCode(identify, code, newPassword)
37
- }
38
- if (codeMethod === 'phone') {
39
- context = client.resetPasswordByPhoneCode(identify, code, newPassword)
40
- }
41
-
42
- context
43
- .then((r) => {
44
- props.onSend(codeMethod)
45
- props.onReset(r)
46
- })
47
- .catch((e) => {
48
- props.onSendError(codeMethod, e)
49
- props.onReset(e)
50
- })
51
- }
52
-
53
- return (
54
- <div className="authing-g2-login-phone-code">
55
- <Form
56
- name="resetPassword"
57
- form={form}
58
- onFinish={onFinish}
59
- onFinishFailed={() => {
60
- submitButtonRef?.current?.onError()
61
- }}
62
- autoComplete="off"
63
- >
64
- <Form.Item
65
- className="authing-g2-input-form"
66
- name="identify"
67
- validateFirst={true}
68
- rules={[
69
- ...fieldRequiredRule(t('common.account')),
70
- {
71
- validator: async (_, value: StoreValue) => {
72
- if (!value) {
73
- return
74
- }
75
- if (validate('email', value) || validate('phone', value)) {
76
- return
77
- } else {
78
- throw new Error(t('login.inputCorrectPhoneOrEmail'))
79
- }
80
- },
81
- },
82
- ]}
83
- >
84
- <Input
85
- className="authing-g2-input"
86
- autoComplete="tel"
87
- size="large"
88
- placeholder={t('login.inputPhoneOrEmail')}
89
- value={identify}
90
- onChange={(e) => {
91
- let v = e.target.value
92
- setIdentify(v)
93
- if (validate('email', v)) {
94
- setCodeMethod('email')
95
- }
96
- if (validate('phone', v)) {
97
- setCodeMethod('phone')
98
- }
99
- }}
100
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
101
- />
102
- </Form.Item>
103
- <Form.Item
104
- className="authing-g2-input-form"
105
- name="code"
106
- rules={[...fieldRequiredRule(t('common.captchaCode'))]}
107
- >
108
- <SendCode
109
- className="authing-g2-input"
110
- autoComplete="one-time-code"
111
- size="large"
112
- placeholder={t('common.inputFourVerifyCode', {
113
- length: verifyCodeLength,
114
- })}
115
- prefix={<SafetyOutlined style={{ color: '#878A95' }} />}
116
- maxLength={verifyCodeLength}
117
- method={codeMethod}
118
- data={identify}
119
- onSendCodeBefore={async () => {
120
- await form.validateFields(['identify'])
121
- }}
122
-
123
- // form={form}
124
- />
125
- </Form.Item>
126
- <Form.Item
127
- className="authing-g2-input-form"
128
- name="password"
129
- validateFirst={true}
130
- rules={[
131
- {
132
- validator(_, value) {
133
- if ((value ?? '') && value.indexOf(' ') !== -1) {
134
- return Promise.reject(t('common.checkPasswordHasSpace'))
135
- }
136
- return Promise.resolve()
137
- },
138
- },
139
- ...getPasswordValidate(
140
- props.publicConfig?.passwordStrength,
141
- props.publicConfig?.customPasswordStrength
142
- ),
143
- ]}
144
- >
145
- <Input.Password
146
- className="authing-g2-input"
147
- size="large"
148
- placeholder={t('user.inputNewPwd')}
149
- prefix={<LockOutlined style={{ color: '#878A95' }} />}
150
- />
151
- </Form.Item>
152
- <Form.Item className="authing-g2-input-form submit-form">
153
- <SubmitButton
154
- className="forget-password"
155
- text={t('common.confirm')}
156
- ref={submitButtonRef}
157
- />
158
- </Form.Item>
159
- </Form>
160
- </div>
161
- )
162
- }
@@ -1,78 +0,0 @@
1
- import React from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { message } from 'antd'
4
-
5
- import { GuardModuleType } from '../Guard/module'
6
- import { ResetPassword } from './core/resetPassword'
7
-
8
- import { ImagePro } from '../ImagePro'
9
- import { ForgetPasswordViewProps } from './interface'
10
- import { useAuthClient } from '../Guard/authClient'
11
- import { CommonMessage } from '..'
12
-
13
- export const GuardForgetPassword: React.FC<ForgetPasswordViewProps> = (
14
- props
15
- ) => {
16
- const { t } = useTranslation()
17
- let publicConfig = props.config.__publicConfig__
18
- const authClient = useAuthClient()
19
-
20
- const onReset = (res: any) => {
21
- let code = res.code
22
- if (code !== 200) {
23
- props.onPwdResetError?.(res, authClient)
24
- message.error(res.message)
25
- return
26
- }
27
- props.onPwdReset?.(authClient)
28
- // 返回登录
29
- const initData = {
30
- title: t('common.resetSuccess'),
31
- message: t('common.resetSuccessMessage'),
32
- }
33
- props.__changeModule?.(GuardModuleType.SUBMIT_SUCCESS, { ...initData })
34
- }
35
-
36
- const onSend = (type: 'phone' | 'email') => {
37
- if (type === 'phone') props.onPwdPhoneSend?.(authClient)
38
- if (type === 'email') props.onPwdEmailSend?.(authClient)
39
- }
40
- const onSendError = (type: 'phone' | 'email', error: any) => {
41
- if (type === 'phone')
42
- props.onPwdPhoneSendError?.(error as CommonMessage, authClient)
43
- if (type === 'email')
44
- props.onPwdEmailSendError?.(error as CommonMessage, authClient)
45
- }
46
-
47
- return (
48
- <div className="g2-view-container">
49
- <div className="g2-view-header">
50
- <ImagePro
51
- src={props.config?.logo}
52
- size={48}
53
- borderRadius={4}
54
- alt=""
55
- className="icon"
56
- />
57
- <div className="title">{t('login.resetPwd')}</div>
58
- <div className="title-explain">{t('user.resetpasswordText1')}</div>
59
- </div>
60
- <div className="g2-view-tabs">
61
- <ResetPassword
62
- onReset={onReset}
63
- publicConfig={publicConfig}
64
- onSend={onSend}
65
- onSendError={onSendError}
66
- />
67
- </div>
68
- <div className="g2-tips-line">
69
- <div
70
- className="link-like back-to-login"
71
- onClick={() => props.__changeModule?.(GuardModuleType.LOGIN)}
72
- >
73
- {t('common.backLoginPage')}
74
- </div>
75
- </div>
76
- </div>
77
- )
78
- }
@@ -1,32 +0,0 @@
1
- import { AuthenticationClient, CommonMessage } from '..'
2
- import { IG2Config, IG2Events, IG2FCProps, IG2FCViewProps } from '../Type'
3
-
4
- export interface ForgetPasswordEvents extends IG2Events {
5
- onPwdEmailSend?: (authClient: AuthenticationClient) => void
6
- onPwdEmailSendError?: (
7
- error: CommonMessage,
8
- authClient: AuthenticationClient
9
- ) => void
10
- onPwdPhoneSend?: (authClient: AuthenticationClient) => void
11
- onPwdPhoneSendError?: (
12
- error: CommonMessage,
13
- authClient: AuthenticationClient
14
- ) => void
15
- onPwdReset?: (authClient: AuthenticationClient) => void
16
- onPwdResetError?: (
17
- error: CommonMessage,
18
- authClient: AuthenticationClient
19
- ) => void
20
- }
21
-
22
- export interface ForgetPasswordConfig extends IG2Config {}
23
-
24
- export interface ForgetPasswordProps extends IG2FCProps, ForgetPasswordEvents {
25
- config: Partial<IG2Config>
26
- }
27
-
28
- export interface ForgetPasswordViewProps
29
- extends ForgetPasswordProps,
30
- IG2FCViewProps {
31
- config: IG2Config
32
- }
@@ -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,4 +0,0 @@
1
- export * from './Guard'
2
- export * from './module'
3
- export * from './event'
4
- export * from './config'