@authing/react-ui-components 3.0.0-alpha → 3.0.0-rc.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.
Files changed (232) hide show
  1. package/lib/index.d.ts +781 -110
  2. package/lib/index.min.css +2 -2
  3. package/lib/index.min.js +1 -1
  4. package/lib/index.min.js.LICENSE.txt +2 -0
  5. package/package.json +34 -12
  6. package/.eslintignore +0 -6
  7. package/.eslintrc.js +0 -7
  8. package/.prettierrc +0 -5
  9. package/.vscode/settings.json +0 -31
  10. package/build/favicon.ico +0 -0
  11. package/build/logo192.png +0 -0
  12. package/build/logo512.png +0 -0
  13. package/build/manifest.json +0 -25
  14. package/build/robots.txt +0 -3
  15. package/components/AuthingDropdown/index.tsx +0 -52
  16. package/components/AuthingDropdown/style.less +0 -43
  17. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  18. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  19. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  20. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  21. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  22. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  23. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  24. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  25. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  26. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  27. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  28. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  29. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  30. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  31. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  32. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  33. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  34. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  35. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  36. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  37. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  38. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  39. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  40. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  41. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  42. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  43. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  44. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  45. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  46. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  47. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  48. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  49. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  50. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  51. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  52. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  53. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  54. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  55. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  56. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  57. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  58. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  59. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  60. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  61. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  62. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  63. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  64. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  65. package/components/AuthingGuard/Forms/index.ts +0 -13
  66. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  67. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  68. package/components/AuthingGuard/Header/index.tsx +0 -25
  69. package/components/AuthingGuard/Header/style.less +0 -52
  70. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  71. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  72. package/components/AuthingGuard/IconFont/style.less +0 -6
  73. package/components/AuthingGuard/IconFont/svg.js +0 -2
  74. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  75. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  76. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  77. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  78. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  79. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  80. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  81. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  82. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  83. package/components/AuthingGuard/api/appConfig.ts +0 -146
  84. package/components/AuthingGuard/api/index.ts +0 -3
  85. package/components/AuthingGuard/api/sso.ts +0 -29
  86. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  87. package/components/AuthingGuard/constants.ts +0 -105
  88. package/components/AuthingGuard/hooks/index.tsx +0 -70
  89. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  90. package/components/AuthingGuard/index.tsx +0 -126
  91. package/components/AuthingGuard/style.less +0 -103
  92. package/components/AuthingGuard/types/Forms.ts +0 -94
  93. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  94. package/components/AuthingGuard/types/GuardState.ts +0 -7
  95. package/components/AuthingGuard/types/Locales.ts +0 -12
  96. package/components/AuthingGuard/types/index.ts +0 -4
  97. package/components/AuthingTabs/index.tsx +0 -98
  98. package/components/AuthingTabs/style.less +0 -135
  99. package/components/BindTotp/core/bindSuccess.tsx +0 -61
  100. package/components/BindTotp/core/securityCode.tsx +0 -119
  101. package/components/BindTotp/index.tsx +0 -134
  102. package/components/BindTotp/props.ts +0 -30
  103. package/components/BindTotp/styles.less +0 -56
  104. package/components/ChangeLanguage/index.tsx +0 -35
  105. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  106. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  107. package/components/ChangePassword/index.tsx +0 -59
  108. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  109. package/components/CompleteInfo/index.tsx +0 -45
  110. package/components/CompleteInfo/props.ts +0 -40
  111. package/components/CompleteInfo/styles.less +0 -7
  112. package/components/CompleteUserInfo/index.tsx +0 -49
  113. package/components/CompleteUserInfo/props.ts +0 -25
  114. package/components/ComponentsRender/index.back +0 -64
  115. package/components/CopyAbleText/index.tsx +0 -54
  116. package/components/CopyAbleText/style.less +0 -13
  117. package/components/DownloadAuthenticator/index.tsx +0 -97
  118. package/components/DownloadAuthenticator/props.ts +0 -22
  119. package/components/DownloadAuthenticator/styles.less +0 -52
  120. package/components/ForgetPassword/core/resetPassword.tsx +0 -150
  121. package/components/ForgetPassword/index.tsx +0 -51
  122. package/components/Guard/Guard.tsx +0 -226
  123. package/components/Guard/authClient.ts +0 -55
  124. package/components/Guard/config.ts +0 -19
  125. package/components/Guard/event.ts +0 -18
  126. package/components/Guard/index.tsx +0 -10
  127. package/components/Guard/module.ts +0 -19
  128. package/components/Guard/stateMachine.ts +0 -133
  129. package/components/Guard/styles.less +0 -444
  130. package/components/IconFont/iconfont.js +0 -74
  131. package/components/IconFont/index.tsx +0 -16
  132. package/components/IconFont/style.less +0 -6
  133. package/components/IconFont/svg.js +0 -2
  134. package/components/ImagePro/index.tsx +0 -52
  135. package/components/ImagePro/styles.less +0 -40
  136. package/components/Login/codemap.ts +0 -35
  137. package/components/Login/core/withAD.tsx +0 -9
  138. package/components/Login/core/withAppQrcode.tsx +0 -49
  139. package/components/Login/core/withLDAP.tsx +0 -145
  140. package/components/Login/core/withPassword.tsx +0 -176
  141. package/components/Login/core/withPhonecode.tsx +0 -135
  142. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  143. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  144. package/components/Login/index.tsx +0 -359
  145. package/components/Login/props.ts +0 -90
  146. package/components/Login/socialLogin/index.tsx +0 -413
  147. package/components/Login/socialLogin/style.less +0 -61
  148. package/components/Login/styles.less +0 -53
  149. package/components/MFA/codemap.ts +0 -21
  150. package/components/MFA/core/email.tsx +0 -226
  151. package/components/MFA/core/face.tsx +0 -297
  152. package/components/MFA/core/face_deps.tsx +0 -37
  153. package/components/MFA/core/sms.tsx +0 -222
  154. package/components/MFA/core/totp.tsx +0 -137
  155. package/components/MFA/index.tsx +0 -135
  156. package/components/MFA/mfaMethods/index.tsx +0 -81
  157. package/components/MFA/mfaMethods/style.less +0 -39
  158. package/components/MFA/props.ts +0 -51
  159. package/components/MFA/styles.less +0 -92
  160. package/components/NeedHelpView/core/describeQuestions.tsx +0 -227
  161. package/components/NeedHelpView/index.tsx +0 -99
  162. package/components/RecoveryCode/core/useCode.tsx +0 -71
  163. package/components/RecoveryCode/index.tsx +0 -27
  164. package/components/RecoveryCode/interface.ts +0 -31
  165. package/components/RecoveryCode/style.less +0 -13
  166. package/components/Register/codemap.ts +0 -16
  167. package/components/Register/components/Agreements/index.tsx +0 -81
  168. package/components/Register/components/Agreements/style.less +0 -44
  169. package/components/Register/core/WithEmail.tsx +0 -250
  170. package/components/Register/core/WithPhone.tsx +0 -190
  171. package/components/Register/index.tsx +0 -122
  172. package/components/Register/props.ts +0 -50
  173. package/components/SendCode/SendCodeBtn.tsx +0 -96
  174. package/components/SendCode/index.tsx +0 -98
  175. package/components/SendCode/style.less +0 -31
  176. package/components/ShieldSpin/index.tsx +0 -27
  177. package/components/ShieldSpin/loading.svg +0 -29
  178. package/components/SubmitButton/index.tsx +0 -50
  179. package/components/Type/index.ts +0 -61
  180. package/components/VerifyCodeInput/index.tsx +0 -76
  181. package/components/VerifyCodeInput/style.less +0 -24
  182. package/components/_utils/GuardErrorCode.ts +0 -8
  183. package/components/_utils/clipboard.ts +0 -27
  184. package/components/_utils/config.ts +0 -123
  185. package/components/_utils/guradHttp.ts +0 -93
  186. package/components/_utils/hooks/index.ts +0 -56
  187. package/components/_utils/http.ts +0 -85
  188. package/components/_utils/index.ts +0 -310
  189. package/components/_utils/locales/en/common.json +0 -218
  190. package/components/_utils/locales/en/index.ts +0 -6
  191. package/components/_utils/locales/en/login.json +0 -95
  192. package/components/_utils/locales/en/map.json +0 -4
  193. package/components/_utils/locales/en/user.json +0 -82
  194. package/components/_utils/locales/index.ts +0 -45
  195. package/components/_utils/locales/zh/common.json +0 -218
  196. package/components/_utils/locales/zh/index.ts +0 -6
  197. package/components/_utils/locales/zh/login.json +0 -95
  198. package/components/_utils/locales/zh/map.json +0 -4
  199. package/components/_utils/locales/zh/user.json +0 -82
  200. package/components/_utils/popupCenter.ts +0 -48
  201. package/components/context/base.tsx +0 -28
  202. package/components/context/global/context.tsx +0 -39
  203. package/components/context/global/reducer.tsx +0 -56
  204. package/components/context/module/context.tsx +0 -23
  205. package/components/index.ts +0 -10
  206. package/config/antdReplacer.js +0 -51
  207. package/config/env.js +0 -104
  208. package/config/getHttpsConfig.js +0 -66
  209. package/config/jest/cssTransform.js +0 -14
  210. package/config/jest/fileTransform.js +0 -40
  211. package/config/modules.js +0 -134
  212. package/config/paths.js +0 -71
  213. package/config/pnpTs.js +0 -35
  214. package/config/webpack.config.js +0 -835
  215. package/config/webpackDevServer.config.js +0 -130
  216. package/examples.tsx +0 -100
  217. package/index.js +0 -1
  218. package/logo.svg +0 -7
  219. package/public/favicon.ico +0 -0
  220. package/public/index.html +0 -43
  221. package/public/logo192.png +0 -0
  222. package/public/logo512.png +0 -0
  223. package/public/manifest.json +0 -25
  224. package/public/robots.txt +0 -3
  225. package/react-app-env.d.ts +0 -71
  226. package/reportWebVitals.ts +0 -15
  227. package/scripts/build.js +0 -208
  228. package/scripts/lib.js +0 -200
  229. package/scripts/start.js +0 -162
  230. package/scripts/test.js +0 -49
  231. package/setupTests.ts +0 -5
  232. package/tsconfig.json +0 -30
@@ -1,139 +0,0 @@
1
- import { Button, Form, Input, message, Spin } from 'antd'
2
- import { useForm } from 'antd/lib/form/Form'
3
- import React, { FC, useEffect, useState } from 'react'
4
- import { useGuardContext } from '../../../context/global/context'
5
- import { User } from 'authing-js-sdk'
6
- import { UploadImage } from '../UploadImage'
7
- import { requestClient } from '../../../_utils/http'
8
- import { CompleteUserInfoFormProps } from '../../types'
9
- import { useTranslation } from 'react-i18next'
10
- import { i18n } from '../../../_utils/locales'
11
-
12
- export const CompleteUserInfoForm: FC<CompleteUserInfoFormProps> = ({
13
- onSuccess,
14
- }) => {
15
- const { t } = useTranslation()
16
- const [rawForm] = useForm()
17
- const [submitting, setSubmitting] = useState(false)
18
-
19
- const [loading, setLoading] = useState(false)
20
-
21
- const {
22
- state: { config, authClient, guardEvents, userPoolId },
23
- } = useGuardContext()
24
-
25
- const { extendsFields } = config
26
-
27
- const [, setUser] = useState<User | null>()
28
- const [definitions, setDefinitions] = useState<any[]>([])
29
-
30
- const onFinish = async (values: any) => {
31
- const internalFields: any = {}
32
- const userFields: any[] = []
33
- Object.entries(values).forEach(([key, value]) => {
34
- const [type, nameOrId] = key.split(' ')
35
- if (type === 'internal') {
36
- internalFields[nameOrId] = value
37
- } else if (type === 'user') {
38
- userFields.push({ nameOrId, value })
39
- }
40
- })
41
-
42
- const udfs = userFields.map(({ nameOrId, value }) => ({
43
- definition: definitions.find((def) => def.id === nameOrId),
44
- value,
45
- }))
46
-
47
- try {
48
- const user = await authClient.updateProfile(internalFields)
49
-
50
- setUser(user)
51
-
52
- await requestClient.post(
53
- `/api/v2/udfs/values`,
54
- {
55
- udfs,
56
- },
57
- {
58
- headers: {
59
- authorization: user?.token,
60
- 'x-authing-userpool-id': userPoolId,
61
- },
62
- }
63
- )
64
-
65
- message.success(t('common.saveSuccess'))
66
- guardEvents.onRegisterInfoCompleted?.(user, udfs, authClient)
67
- onSuccess?.(user)
68
- } catch (e) {
69
- guardEvents.onRegisterInfoCompletedError?.(e, udfs, authClient)
70
- setSubmitting(false)
71
- } finally {
72
- setSubmitting(false)
73
- }
74
- }
75
-
76
- useEffect(() => {
77
- setLoading(true)
78
- ;(async () => {
79
- const user = await authClient.getCurrentUser()
80
- setUser(user)
81
- const { data } = await requestClient.get<any>(
82
- '/api/v2/udfs/definitions',
83
- undefined,
84
- {
85
- headers: {
86
- authorization: user?.token!,
87
- 'x-authing-userpool-id': userPoolId,
88
- },
89
- }
90
- )
91
- setDefinitions(data)
92
- setLoading(false)
93
- })()
94
- }, [authClient, userPoolId])
95
-
96
- const onFinishFailed = () => {}
97
-
98
- const INPUT_MAP: Record<string, React.ReactNode | undefined> = {
99
- image: <UploadImage />,
100
- }
101
-
102
- const formFields = extendsFields.map((def) => {
103
- const key = `${def.type} ${def.type === 'internal' ? def.name : def.id}`
104
-
105
- const label = i18n.language === 'zh-CN' ? def.label : def.name
106
-
107
- return (
108
- <Form.Item key={key} name={key} label={label} style={{ marginBottom: 8 }}>
109
- {INPUT_MAP[def.inputType] || (
110
- <Input type={def.inputType} size="large" />
111
- )}
112
- </Form.Item>
113
- )
114
- })
115
-
116
- return (
117
- <Spin spinning={loading}>
118
- <Form
119
- layout="vertical"
120
- form={rawForm}
121
- onSubmitCapture={() => setSubmitting(true)}
122
- onFinishFailed={onFinishFailed}
123
- onFinish={onFinish}
124
- >
125
- {formFields}
126
-
127
- <Button
128
- size="large"
129
- loading={submitting}
130
- type="primary"
131
- block
132
- htmlType="submit"
133
- >
134
- {t('common.problem.form.submit')}
135
- </Button>
136
- </Form>
137
- </Spin>
138
- )
139
- }
@@ -1,84 +0,0 @@
1
- import React, { FC, useState } from 'react'
2
- import { Button, Form, Input, message } from 'antd'
3
- import { useGuardContext } from '../../../context/global/context'
4
- import { MFACheckEmailFormProps } from '../../types'
5
- import './style.less'
6
- import { useTranslation } from 'react-i18next'
7
- import { VALIDATE_PATTERN } from '../../../_utils'
8
-
9
- export const CheckEmailForm: FC<MFACheckEmailFormProps> = ({
10
- onSuccess,
11
- mfaToken,
12
- }) => {
13
- const {
14
- state: { authClient },
15
- } = useGuardContext()
16
-
17
- const { t } = useTranslation()
18
-
19
- const [rawForm] = Form.useForm()
20
-
21
- const [loading, setLoading] = useState(false)
22
-
23
- const onFinish = async ({ email }: any) => {
24
- try {
25
- const bindable = await authClient.mfa.phoneOrEmailBindable({
26
- mfaToken,
27
- email,
28
- })
29
- if (!bindable) {
30
- message.error(
31
- t('common.unBindEmaileDoc', {
32
- email: email,
33
- })
34
- )
35
- return
36
- }
37
- onSuccess(email!)
38
- } catch (e) {
39
- // do nothing
40
- } finally {
41
- setLoading(false)
42
- }
43
- }
44
-
45
- return (
46
- <>
47
- <h3 className="authing-guard-mfa-title">{t('common.bindEmail')}</h3>
48
- <p className="authing-guard-mfa-tips">{t('common.bindEmailDoc')}</p>
49
- <Form
50
- form={rawForm}
51
- onSubmitCapture={() => setLoading(true)}
52
- onFinish={onFinish}
53
- onFinishFailed={() => setLoading(false)}
54
- >
55
- <Form.Item
56
- name="email"
57
- rules={[
58
- {
59
- required: true,
60
- message: t('login.inputEmail'),
61
- },
62
- {
63
- pattern: VALIDATE_PATTERN.email,
64
- message: t('login.emailError'),
65
- },
66
- ]}
67
- >
68
- <Input placeholder={t('login.inputEmail')}></Input>
69
- </Form.Item>
70
-
71
- <Button
72
- className="authing-guard-mfa-confirm-btn"
73
- loading={loading}
74
- block
75
- htmlType="submit"
76
- type="primary"
77
- size="large"
78
- >
79
- {t('common.sure')}
80
- </Button>
81
- </Form>
82
- </>
83
- )
84
- }
@@ -1,116 +0,0 @@
1
- import { EmailScene, User } from 'authing-js-sdk'
2
- import React, { FC, useState } from 'react'
3
- import { Button, Form } from 'antd'
4
-
5
- import { VerifyCodeInput } from '../../../VerifyCodeInput'
6
- import { useGuardContext } from '../../../context/global/context'
7
- import { EmailMFAVerifyFormProps } from '../../../../components/AuthingGuard/types'
8
-
9
- import './style.less'
10
- import { SendCodeBtn } from '../SendPhoneCode/SendCodeBtn'
11
- import { useTranslation } from 'react-i18next'
12
-
13
- const CODE_LEN = 4
14
-
15
- export const VerifyCodeForm: FC<EmailMFAVerifyFormProps> = ({
16
- onSuccess,
17
- onFail,
18
- email,
19
- mfaToken,
20
- sendCodeRef,
21
- }) => {
22
- const {
23
- state: { authClient },
24
- } = useGuardContext()
25
-
26
- const { t } = useTranslation()
27
-
28
- const [rawForm] = Form.useForm()
29
-
30
- const [MfaCode, setMFACode] = useState(new Array(CODE_LEN).fill(''))
31
- const [loading, setLoading] = useState(false)
32
-
33
- const [sending, setSending] = useState(false)
34
- const [sent, setSent] = useState(false)
35
-
36
- const onFinish = async (values: any) => {
37
- try {
38
- const user: User = await authClient.mfa.verifyAppEmailMfa({
39
- mfaToken,
40
- email: email!,
41
- code: MfaCode.join(''),
42
- })
43
- onSuccess && onSuccess(user)
44
- } catch (e) {
45
- onFail?.(e)
46
- } finally {
47
- setLoading(false)
48
- }
49
- }
50
-
51
- const sendVerifyCode = async () => {
52
- try {
53
- setSending(true)
54
- await authClient.sendEmail(email!, EmailScene.MfaVerify)
55
- setSent(true)
56
- return true
57
- } catch (e) {
58
- return false
59
- } finally {
60
- setSending(false)
61
- }
62
- }
63
-
64
- return (
65
- <>
66
- <h3 className="authing-guard-mfa-title">{t('login.inputEmailCode')}</h3>
67
- <p className="authing-guard-mfa-tips">
68
- {sending
69
- ? t('login.sendingVerifyCode')
70
- : sent
71
- ? `${t('login.verifyCodeSended')} ${email}`
72
- : t('login.clickSent')}
73
- </p>
74
- <Form
75
- form={rawForm}
76
- onSubmitCapture={() => setLoading(true)}
77
- onFinish={onFinish}
78
- onFinishFailed={() => setLoading(false)}
79
- >
80
- <Form.Item
81
- name="mfaCode"
82
- rules={[
83
- {
84
- validateTrigger: [],
85
- validator() {
86
- if (MfaCode.some((item) => !item)) {
87
- return Promise.reject(t('login.inputFullMfaCode'))
88
- }
89
- return Promise.resolve()
90
- },
91
- },
92
- ]}
93
- >
94
- <VerifyCodeInput
95
- length={CODE_LEN}
96
- verifyCode={MfaCode}
97
- setVerifyCode={setMFACode}
98
- />
99
- </Form.Item>
100
-
101
- <SendCodeBtn btnRef={sendCodeRef} beforeSend={() => sendVerifyCode()} />
102
-
103
- <Button
104
- className="authing-guard-mfa-confirm-btn"
105
- loading={loading}
106
- block
107
- htmlType="submit"
108
- type="primary"
109
- size="large"
110
- >
111
- {t('common.sure')}
112
- </Button>
113
- </Form>
114
- </>
115
- )
116
- }
@@ -1,40 +0,0 @@
1
- import React, { FC, useRef, useState } from 'react'
2
- import { useGuardContext } from '../../../context/global/context'
3
- import { CheckEmailForm } from './CheckEmailForm'
4
- import { VerifyCodeForm } from './VerifyCodeForm'
5
- import { SmsMFAFormProps } from '../../types'
6
-
7
- export const EmailMfaVerifyForm: FC<SmsMFAFormProps> = ({
8
- onSuccess,
9
- onFail,
10
- }) => {
11
- const {
12
- state: {
13
- mfaData: { mfaToken, email: userEmail },
14
- },
15
- } = useGuardContext()
16
- const [email, setEmail] = useState(userEmail)
17
- const sendCodeRef = useRef<HTMLButtonElement>(null)
18
-
19
- return (
20
- <>
21
- {email ? (
22
- <VerifyCodeForm
23
- sendCodeRef={sendCodeRef}
24
- onSuccess={onSuccess}
25
- onFail={onFail}
26
- email={email!}
27
- mfaToken={mfaToken}
28
- ></VerifyCodeForm>
29
- ) : (
30
- <CheckEmailForm
31
- mfaToken={mfaToken}
32
- onSuccess={(email) => {
33
- setEmail(email)
34
- sendCodeRef.current?.click()
35
- }}
36
- ></CheckEmailForm>
37
- )}
38
- </>
39
- )
40
- }
@@ -1,181 +0,0 @@
1
- import React, { forwardRef, useImperativeHandle, useState } from 'react'
2
- import { Input, Form, message } from 'antd'
3
- import { FormInstance } from 'antd/lib/form'
4
- import { UserOutlined, LockOutlined } from '@ant-design/icons'
5
-
6
- import {
7
- getDeviceName,
8
- getRequiredRules,
9
- getUserRegisterParams,
10
- VALIDATE_PATTERN,
11
- } from '../../../_utils'
12
- import { useGuardContext } from '../../../context/global/context'
13
- import {
14
- EmailRegisterFormProps,
15
- RegisterMethods,
16
- } from '../../../../components/AuthingGuard/types'
17
- import { RegisterFormFooter } from '../../../../components/AuthingGuard/Forms/RegisterFormFooter'
18
- import { useTranslation } from 'react-i18next'
19
- import { Agreements } from '../Agreements'
20
-
21
- export const EmailRegisterForm = forwardRef<
22
- FormInstance,
23
- EmailRegisterFormProps
24
- >(({ onSuccess, onFail, onValidateFail }, ref) => {
25
- const { t } = useTranslation()
26
- const {
27
- state: { authClient, config, guardEvents },
28
- } = useGuardContext()
29
-
30
- const { agreements, agreementEnabled } = config
31
-
32
- const [rawForm] = Form.useForm()
33
-
34
- const [loading, setLoading] = useState(false)
35
-
36
- const onFinishFailed = (errorInfo: any) => {
37
- setLoading(false)
38
- onValidateFail && onValidateFail(errorInfo)
39
- }
40
-
41
- const [acceptedAgreements, setAcceptedAgreements] = useState(false)
42
-
43
- /** 表单是否被提交校验过 */
44
- const [validated, setValidated] = useState(false)
45
-
46
- const onFinish = async (values: any) => {
47
- if (guardEvents.onBeforeRegister) {
48
- try {
49
- const canRegister = await guardEvents.onBeforeRegister(
50
- {
51
- type: RegisterMethods.Email,
52
- data: {
53
- email: values.email,
54
- password: values.password,
55
- },
56
- },
57
- authClient
58
- )
59
-
60
- if (!canRegister) {
61
- setLoading(false)
62
- return
63
- }
64
- } catch (e) {
65
- if (typeof e === 'string') {
66
- message.error(e)
67
- } else {
68
- message.error(e.message)
69
- }
70
- setLoading(false)
71
- return
72
- }
73
- }
74
-
75
- try {
76
- await rawForm.validateFields()
77
-
78
- setValidated(true)
79
-
80
- if (agreementEnabled && agreements?.length && !acceptedAgreements) {
81
- return
82
- }
83
-
84
- const { email, password } = values
85
- // 注册并获取登录态
86
- const user = await authClient.registerByEmail(
87
- email,
88
- password,
89
- {
90
- browser:
91
- typeof navigator !== 'undefined' ? navigator.userAgent : null,
92
- device: getDeviceName(),
93
- },
94
- {
95
- generateToken: true,
96
- params: getUserRegisterParams(),
97
- }
98
- )
99
- onSuccess && onSuccess(user)
100
- } catch (error) {
101
- onFail && onFail(error)
102
- } finally {
103
- setLoading(false)
104
- }
105
- }
106
-
107
- useImperativeHandle(ref, () => rawForm)
108
-
109
- const formItems = [
110
- {
111
- component: (
112
- <Input
113
- autoComplete="email"
114
- size="large"
115
- placeholder={t('login.inputEmail')}
116
- prefix={<UserOutlined style={{ color: '#ddd' }} />}
117
- />
118
- ),
119
- name: 'email',
120
- rules: getRequiredRules(t('common.emailNotNull')).concat({
121
- pattern: VALIDATE_PATTERN.email,
122
- message: t('login.emailError'),
123
- }),
124
- },
125
- {
126
- component: (
127
- <Input.Password
128
- size="large"
129
- placeholder={t('common.setPassword')}
130
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
131
- />
132
- ),
133
- name: 'password',
134
- rules: getRequiredRules(t('common.passwordNotNull')),
135
- },
136
- {
137
- component: (
138
- <Input.Password
139
- size="large"
140
- placeholder={t('login.inputPwdAgain')}
141
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
142
- />
143
- ),
144
- name: 'new-password',
145
- rules: getRequiredRules(t('common.repeatPassword')).concat({
146
- validator: (rule, value) => {
147
- if (value !== rawForm.getFieldValue('password')) {
148
- return Promise.reject(t('common.repeatPasswordDoc'))
149
- } else {
150
- return Promise.resolve()
151
- }
152
- },
153
- }),
154
- },
155
- ]
156
-
157
- return (
158
- <Form
159
- form={rawForm}
160
- onFinish={onFinish}
161
- onSubmitCapture={() => setLoading(true)}
162
- onFinishFailed={onFinishFailed}
163
- >
164
- {formItems.map((item) => (
165
- <Form.Item key={item.name} name={item.name} rules={item.rules}>
166
- {item.component}
167
- </Form.Item>
168
- ))}
169
-
170
- {config.agreementEnabled && Boolean(agreements?.length) && (
171
- <Agreements
172
- onChange={setAcceptedAgreements}
173
- agreements={agreements}
174
- showError={validated}
175
- />
176
- )}
177
-
178
- <RegisterFormFooter loading={loading} />
179
- </Form>
180
- )
181
- })