@authing/react-ui-components 3.0.2-Beta.0 → 3.0.2-beta.10

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 (262) hide show
  1. package/lib/index.d.ts +466 -45
  2. package/lib/index.min.css +2 -2
  3. package/lib/index.min.js +1 -1
  4. package/package.json +26 -10
  5. package/.eslintignore +0 -6
  6. package/.eslintrc.js +0 -7
  7. package/.prettierrc +0 -5
  8. package/.vscode/settings.json +0 -31
  9. package/build/asset-manifest.json +0 -26
  10. package/build/favicon.ico +0 -0
  11. package/build/index.html +0 -1
  12. package/build/logo192.png +0 -0
  13. package/build/logo512.png +0 -0
  14. package/build/manifest.json +0 -25
  15. package/build/robots.txt +0 -3
  16. package/build/static/css/2.9512539b.chunk.css +0 -3
  17. package/build/static/css/2.9512539b.chunk.css.map +0 -1
  18. package/build/static/css/main.0ff9e24a.chunk.css +0 -2
  19. package/build/static/css/main.0ff9e24a.chunk.css.map +0 -1
  20. package/build/static/js/2.1105ecfb.chunk.js +0 -3
  21. package/build/static/js/2.1105ecfb.chunk.js.LICENSE.txt +0 -102
  22. package/build/static/js/2.1105ecfb.chunk.js.map +0 -1
  23. package/build/static/js/3.fd17f196.chunk.js +0 -2
  24. package/build/static/js/3.fd17f196.chunk.js.map +0 -1
  25. package/build/static/js/main.a47645ff.chunk.js +0 -2
  26. package/build/static/js/main.a47645ff.chunk.js.map +0 -1
  27. package/build/static/js/runtime-main.ef138021.js +0 -2
  28. package/build/static/js/runtime-main.ef138021.js.map +0 -1
  29. package/build/static/media/loading.4a67a5f3.svg +0 -29
  30. package/components/AuthingDropdown/index.tsx +0 -52
  31. package/components/AuthingDropdown/style.less +0 -43
  32. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  33. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  34. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  35. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  36. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  37. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  38. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  39. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  40. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  41. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  42. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  43. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  44. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  45. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  46. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  47. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  48. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  49. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  50. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  51. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  52. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  53. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  54. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  55. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  56. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  57. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  58. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  59. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  60. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  61. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  62. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  63. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  64. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  65. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  66. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  67. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  68. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  69. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  70. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  71. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  72. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  73. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  74. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  75. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  76. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  77. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  78. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  79. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  80. package/components/AuthingGuard/Forms/index.ts +0 -13
  81. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  82. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  83. package/components/AuthingGuard/Header/index.tsx +0 -25
  84. package/components/AuthingGuard/Header/style.less +0 -52
  85. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  86. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  87. package/components/AuthingGuard/IconFont/style.less +0 -6
  88. package/components/AuthingGuard/IconFont/svg.js +0 -2
  89. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  90. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  91. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  92. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  93. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  94. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  95. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  96. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  97. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  98. package/components/AuthingGuard/api/appConfig.ts +0 -146
  99. package/components/AuthingGuard/api/index.ts +0 -3
  100. package/components/AuthingGuard/api/sso.ts +0 -29
  101. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  102. package/components/AuthingGuard/constants.ts +0 -107
  103. package/components/AuthingGuard/hooks/index.tsx +0 -70
  104. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  105. package/components/AuthingGuard/index.tsx +0 -126
  106. package/components/AuthingGuard/style.less +0 -103
  107. package/components/AuthingGuard/types/Forms.ts +0 -94
  108. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  109. package/components/AuthingGuard/types/GuardState.ts +0 -7
  110. package/components/AuthingGuard/types/Locales.ts +0 -12
  111. package/components/AuthingGuard/types/index.ts +0 -4
  112. package/components/AuthingTabs/index.tsx +0 -98
  113. package/components/AuthingTabs/style.less +0 -135
  114. package/components/BindTotp/core/bindSuccess.tsx +0 -73
  115. package/components/BindTotp/core/securityCode.tsx +0 -108
  116. package/components/BindTotp/index.tsx +0 -134
  117. package/components/BindTotp/interface.ts +0 -30
  118. package/components/BindTotp/styles.less +0 -57
  119. package/components/ChangeLanguage/index.tsx +0 -35
  120. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  121. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  122. package/components/ChangePassword/index.tsx +0 -59
  123. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  124. package/components/CompleteInfo/index.tsx +0 -45
  125. package/components/CompleteInfo/interface.ts +0 -40
  126. package/components/CompleteInfo/styles.less +0 -7
  127. package/components/CopyAbleText/index.tsx +0 -54
  128. package/components/CopyAbleText/style.less +0 -13
  129. package/components/DownloadAuthenticator/index.tsx +0 -97
  130. package/components/DownloadAuthenticator/interface.ts +0 -22
  131. package/components/DownloadAuthenticator/styles.less +0 -52
  132. package/components/Error/index.tsx +0 -21
  133. package/components/Error/interface.ts +0 -9
  134. package/components/Error/styles.less +0 -12
  135. package/components/ForgetPassword/core/resetPassword.tsx +0 -162
  136. package/components/ForgetPassword/index.tsx +0 -78
  137. package/components/ForgetPassword/interface.ts +0 -32
  138. package/components/Guard/Guard.tsx +0 -255
  139. package/components/Guard/authClient.ts +0 -46
  140. package/components/Guard/config.ts +0 -19
  141. package/components/Guard/event.ts +0 -52
  142. package/components/Guard/index.tsx +0 -4
  143. package/components/Guard/module.ts +0 -20
  144. package/components/Guard/stateMachine.ts +0 -133
  145. package/components/Guard/styles.less +0 -461
  146. package/components/IconFont/iconfont.js +0 -74
  147. package/components/IconFont/index.tsx +0 -16
  148. package/components/IconFont/style.less +0 -6
  149. package/components/IconFont/svg.js +0 -2
  150. package/components/ImagePro/index.tsx +0 -53
  151. package/components/ImagePro/styles.less +0 -40
  152. package/components/InputNumber/index.tsx +0 -33
  153. package/components/Login/codemap.ts +0 -47
  154. package/components/Login/core/withAD.tsx +0 -9
  155. package/components/Login/core/withAppQrcode.tsx +0 -49
  156. package/components/Login/core/withLDAP.tsx +0 -146
  157. package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
  158. package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -31
  159. package/components/Login/core/withPassword/InputAccount.tsx +0 -64
  160. package/components/Login/core/withPassword/index.tsx +0 -173
  161. package/components/Login/core/withPhonecode.tsx +0 -122
  162. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  163. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  164. package/components/Login/index.tsx +0 -373
  165. package/components/Login/props.ts +0 -74
  166. package/components/Login/socialLogin/index.tsx +0 -407
  167. package/components/Login/socialLogin/style.less +0 -69
  168. package/components/Login/styles.less +0 -53
  169. package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
  170. package/components/MFA/VerifyCodeInput/index.tsx +0 -145
  171. package/components/MFA/VerifyCodeInput/style.less +0 -35
  172. package/components/MFA/codemap.ts +0 -24
  173. package/components/MFA/core/email.tsx +0 -203
  174. package/components/MFA/core/face.tsx +0 -297
  175. package/components/MFA/core/face_deps.tsx +0 -37
  176. package/components/MFA/core/sms.tsx +0 -204
  177. package/components/MFA/core/totp.tsx +0 -122
  178. package/components/MFA/index.tsx +0 -143
  179. package/components/MFA/mfaMethods/index.tsx +0 -88
  180. package/components/MFA/mfaMethods/style.less +0 -39
  181. package/components/MFA/props.ts +0 -51
  182. package/components/MFA/styles.less +0 -100
  183. package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
  184. package/components/NeedHelpView/index.tsx +0 -47
  185. package/components/RecoveryCode/core/useCode.tsx +0 -71
  186. package/components/RecoveryCode/index.tsx +0 -27
  187. package/components/RecoveryCode/interface.ts +0 -31
  188. package/components/RecoveryCode/style.less +0 -13
  189. package/components/Register/codemap.ts +0 -12
  190. package/components/Register/components/Agreements/index.tsx +0 -81
  191. package/components/Register/components/Agreements/style.less +0 -44
  192. package/components/Register/core/WithEmail.tsx +0 -239
  193. package/components/Register/core/WithPhone.tsx +0 -184
  194. package/components/Register/index.tsx +0 -138
  195. package/components/Register/props.ts +0 -50
  196. package/components/SendCode/SendCodeBtn.tsx +0 -96
  197. package/components/SendCode/index.tsx +0 -94
  198. package/components/SendCode/style.less +0 -31
  199. package/components/ShieldSpin/index.tsx +0 -27
  200. package/components/ShieldSpin/loading.svg +0 -29
  201. package/components/SubmitButton/index.tsx +0 -50
  202. package/components/SubmitSuccess/index.tsx +0 -66
  203. package/components/SubmitSuccess/interface.ts +0 -17
  204. package/components/Type/index.ts +0 -52
  205. package/components/ValidatorRules/EmailFormItem.tsx +0 -95
  206. package/components/ValidatorRules/PhoneFormItem.tsx +0 -100
  207. package/components/ValidatorRules/index.ts +0 -14
  208. package/components/VerifyCodeInput/index.tsx +0 -76
  209. package/components/VerifyCodeInput/style.less +0 -24
  210. package/components/_utils/GuardErrorCode.ts +0 -9
  211. package/components/_utils/clipboard.ts +0 -27
  212. package/components/_utils/config.ts +0 -118
  213. package/components/_utils/guradHttp.ts +0 -97
  214. package/components/_utils/hooks/index.ts +0 -64
  215. package/components/_utils/http.ts +0 -85
  216. package/components/_utils/index.ts +0 -322
  217. package/components/_utils/locales/en/common.json +0 -227
  218. package/components/_utils/locales/en/index.ts +0 -6
  219. package/components/_utils/locales/en/login.json +0 -96
  220. package/components/_utils/locales/en/map.json +0 -4
  221. package/components/_utils/locales/en/user.json +0 -82
  222. package/components/_utils/locales/index.ts +0 -45
  223. package/components/_utils/locales/zh/common.json +0 -227
  224. package/components/_utils/locales/zh/index.ts +0 -6
  225. package/components/_utils/locales/zh/login.json +0 -96
  226. package/components/_utils/locales/zh/map.json +0 -4
  227. package/components/_utils/locales/zh/user.json +0 -82
  228. package/components/_utils/popupCenter.ts +0 -48
  229. package/components/assets/images/error.png +0 -0
  230. package/components/context/base.tsx +0 -28
  231. package/components/context/global/context.tsx +0 -39
  232. package/components/context/global/reducer.tsx +0 -56
  233. package/components/context/module/context.tsx +0 -23
  234. package/components/index.ts +0 -12
  235. package/config/antdReplacer.js +0 -51
  236. package/config/env.js +0 -104
  237. package/config/getHttpsConfig.js +0 -66
  238. package/config/jest/cssTransform.js +0 -14
  239. package/config/jest/fileTransform.js +0 -40
  240. package/config/modules.js +0 -134
  241. package/config/paths.js +0 -71
  242. package/config/pnpTs.js +0 -35
  243. package/config/webpack.config.js +0 -835
  244. package/config/webpackDevServer.config.js +0 -130
  245. package/examples.tsx +0 -82
  246. package/index.js +0 -1
  247. package/logo.svg +0 -7
  248. package/public/favicon.ico +0 -0
  249. package/public/index.html +0 -43
  250. package/public/logo192.png +0 -0
  251. package/public/logo512.png +0 -0
  252. package/public/manifest.json +0 -25
  253. package/public/robots.txt +0 -3
  254. package/react-app-env.d.ts +0 -71
  255. package/reportWebVitals.ts +0 -15
  256. package/scripts/build.js +0 -208
  257. package/scripts/lib.js +0 -200
  258. package/scripts/publish.js +0 -57
  259. package/scripts/start.js +0 -162
  260. package/scripts/test.js +0 -49
  261. package/setupTests.ts +0 -5
  262. package/tsconfig.json +0 -30
@@ -1,86 +0,0 @@
1
- import { Input, Form, Button } from 'antd'
2
- import React, { FC, useState } from 'react'
3
- import { LockOutlined } from '@ant-design/icons'
4
- import { getRequiredRules } from '../../../_utils'
5
- import { useGuardContext } from '../../../context/global/context'
6
- import { User } from 'authing-js-sdk'
7
- import { useTranslation } from 'react-i18next'
8
-
9
- export const MfaResetStep1: FC<{
10
- mfaToken: string
11
- onSuccess: (
12
- user: User & {
13
- recoveryCode: string
14
- }
15
- ) => void
16
- goVerify: () => void
17
- onFail?: (error: any) => void
18
- }> = ({ mfaToken, onSuccess, goVerify, onFail }) => {
19
- const [loading, setLoading] = useState(false)
20
- const { t } = useTranslation()
21
-
22
- const {
23
- state: { authClient },
24
- } = useGuardContext()
25
-
26
- const onFinish = async (values: any) => {
27
- try {
28
- const user = await authClient.mfa.verifyTotpRecoveryCode({
29
- recoveryCode: values.recoverCode,
30
- mfaToken,
31
- })
32
- onSuccess(
33
- user as User & {
34
- recoveryCode: string
35
- }
36
- )
37
- } catch (e) {
38
- onFail?.(e)
39
- } finally {
40
- setLoading(false)
41
- }
42
- }
43
-
44
- return (
45
- <Form
46
- onSubmitCapture={() => setLoading(true)}
47
- onFinishFailed={() => setLoading(false)}
48
- onFinish={onFinish}
49
- >
50
- <Form.Item
51
- rules={getRequiredRules(t('common.recoverCodeNotNull'))}
52
- name="recoverCode"
53
- >
54
- <Input
55
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
56
- placeholder={t('login.inputRecoverCode')}
57
- size="large"
58
- ></Input>
59
- </Form.Item>
60
-
61
- <Button
62
- className="authing-guard-mfa-confirm-btn"
63
- loading={loading}
64
- htmlType="submit"
65
- block
66
- type="primary"
67
- size="large"
68
- >
69
- {t('common.sure')}
70
- </Button>
71
-
72
- <div className="authing-guard-form-actions">
73
- <div className="authing-guard-tip-btn-comb">
74
- <Button
75
- htmlType="button"
76
- onClick={goVerify}
77
- className="authing-guard-text-btn"
78
- type="text"
79
- >
80
- {t('login.findedSafetyCode')}
81
- </Button>
82
- </div>
83
- </div>
84
- </Form>
85
- )
86
- }
@@ -1,53 +0,0 @@
1
- import React, { FC } from 'react'
2
-
3
- import { Button, Checkbox, Form } from 'antd'
4
- import { CopyAbleText } from '../../../CopyAbleText'
5
- import { useTranslation } from 'react-i18next'
6
-
7
- export interface MfaResetStep2Props {
8
- recoverCode: string
9
- onFinish: () => void
10
- }
11
-
12
- export const MfaResetStep2: FC<MfaResetStep2Props> = ({
13
- recoverCode,
14
- onFinish,
15
- }) => {
16
- const { t } = useTranslation()
17
- return (
18
- <Form onFinish={onFinish}>
19
- <CopyAbleText className="authing-guard-secret-block">
20
- {recoverCode}
21
- </CopyAbleText>
22
- <Form.Item
23
- valuePropName="checked"
24
- rules={[
25
- {
26
- validateTrigger: [],
27
- validator(r, v) {
28
- return new Promise((resolve, reject) => {
29
- if (!v) {
30
- reject(t('login.confirmSavedCode'))
31
- }
32
- resolve(true)
33
- })
34
- },
35
- },
36
- ]}
37
- name="MfaCopyRecoverCode"
38
- >
39
- <Checkbox>{t('login.rememberedSecret')}</Checkbox>
40
- </Form.Item>
41
-
42
- <Button
43
- className="authing-guard-mfa-confirm-btn"
44
- htmlType="submit"
45
- block
46
- type="primary"
47
- size="large"
48
- >
49
- {t('common.sure')}
50
- </Button>
51
- </Form>
52
- )
53
- }
@@ -1,65 +0,0 @@
1
- import { User } from 'authing-js-sdk'
2
- import React, { FC, useState } from 'react'
3
-
4
- import { MfaResetStep1 } from './Step1'
5
- import { MfaResetStep2 } from './Step2'
6
- import { useGuardContext } from '../../../context/global/context'
7
- import { MfaResetForm } from '../../../../components/AuthingGuard/types'
8
-
9
- import './style.less'
10
- import { useTranslation } from 'react-i18next'
11
-
12
- export const MfaResetCodeForm: FC<MfaResetForm> = ({
13
- goVerify,
14
- onSuccess,
15
- onFail,
16
- }) => {
17
- const { t } = useTranslation()
18
-
19
- const {
20
- state: {
21
- mfaData: { mfaToken },
22
- },
23
- } = useGuardContext()
24
-
25
- const [step, setStep] = useState(1)
26
- const [user, setUser] = useState<User | null>(null)
27
- const [recoverCode, setRecoverCode] = useState('')
28
-
29
- const onReset = (
30
- user: User & {
31
- recoveryCode: string
32
- }
33
- ) => {
34
- setStep(2)
35
- setUser(user)
36
- setRecoverCode(user.recoveryCode)
37
- }
38
-
39
- const stepMap: Record<number, JSX.Element | undefined> = {
40
- 1: (
41
- <MfaResetStep1
42
- onFail={onFail}
43
- goVerify={goVerify}
44
- onSuccess={onReset}
45
- mfaToken={mfaToken}
46
- />
47
- ),
48
- 2: (
49
- <MfaResetStep2
50
- onFinish={() => onSuccess?.(user!)}
51
- recoverCode={recoverCode}
52
- />
53
- ),
54
- }
55
-
56
- return (
57
- <>
58
- <h2 className="authing-guard-mfa-reset-title">
59
- {t('common.useRecoverCode')}
60
- </h2>
61
- <p className="authing-guard-mfa-reset-tips">{t('login.mfaAfterReset')}</p>
62
- {stepMap[step]}
63
- </>
64
- )
65
- }
@@ -1,20 +0,0 @@
1
- .authing-guard-secret-block {
2
- border: 1px solid #ddd;
3
- justify-content: center;
4
- border-radius: 2px;
5
- padding: 12px 0;
6
- text-align: center;
7
- }
8
-
9
- .authing-guard-mfa-reset-title {
10
- color: #181818;
11
- font-size: 18px;
12
- font-weight: 600;
13
- text-align: center;
14
- margin: 0;
15
- }
16
-
17
- .authing-guard-mfa-reset-tips {
18
- margin: 38px 0;
19
- text-align: center;
20
- }
@@ -1,105 +0,0 @@
1
- import { 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 { MfaVerifyForm } from '../../../../components/AuthingGuard/types'
8
-
9
- import './style.less'
10
- import { useTranslation } from 'react-i18next'
11
-
12
- const CODE_LEN = 6
13
-
14
- export const MFAVerifyForm: FC<MfaVerifyForm> = ({
15
- onSuccess,
16
- onFail,
17
- goReset,
18
- }) => {
19
- const {
20
- state: {
21
- authClient,
22
- mfaData: { mfaToken },
23
- },
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 onFinish = async (values: any) => {
34
- try {
35
- const user: User = await authClient.mfa.verifyTotpMfa({
36
- mfaToken,
37
- totp: MfaCode.join(''),
38
- })
39
- onSuccess && onSuccess(user)
40
- } catch (e) {
41
- onFail?.(e)
42
- } finally {
43
- setLoading(false)
44
- }
45
- }
46
-
47
- return (
48
- <>
49
- <h3 className="authing-guard-mfa-title">
50
- {t('login.accPwdLoginVerify')}
51
- </h3>
52
- <p className="authing-guard-mfa-tips">{t('login.inputSixCode')}</p>
53
- <Form
54
- form={rawForm}
55
- onSubmitCapture={() => setLoading(true)}
56
- onFinish={onFinish}
57
- onFinishFailed={() => setLoading(false)}
58
- >
59
- <Form.Item
60
- name="mfaCode"
61
- rules={[
62
- {
63
- validateTrigger: [],
64
- validator() {
65
- if (MfaCode.some((item) => !item)) {
66
- return Promise.reject(t('login.inputFullMfaCode'))
67
- }
68
- return Promise.resolve()
69
- },
70
- },
71
- ]}
72
- >
73
- <VerifyCodeInput verifyCode={MfaCode} setVerifyCode={setMFACode} />
74
- </Form.Item>
75
-
76
- <Button
77
- className="authing-guard-mfa-confirm-btn"
78
- loading={loading}
79
- block
80
- htmlType="submit"
81
- type="primary"
82
- size="large"
83
- >
84
- {t('common.sure')}
85
- </Button>
86
-
87
- <div className="authing-guard-form-actions">
88
- <div className="authing-guard-tip-btn-comb">
89
- <span className="authing-guard-tip">
90
- {t('common.hasLooseSaftyCode')}
91
- </span>
92
- <Button
93
- htmlType="button"
94
- onClick={goReset}
95
- className="authing-guard-text-btn"
96
- type="text"
97
- >
98
- {t('common.useRecoverCode')}
99
- </Button>
100
- </div>
101
- </div>
102
- </Form>
103
- </>
104
- )
105
- }
@@ -1,12 +0,0 @@
1
- .authing-guard-mfa-title {
2
- color: #181818;
3
- font-size: 18px;
4
- font-weight: 600;
5
- text-align: center;
6
- margin: 0;
7
- }
8
-
9
- .authing-guard-mfa-tips {
10
- margin: 38px 0;
11
- text-align: center;
12
- }
@@ -1,261 +0,0 @@
1
- import { Input, Form, Alert, message as Message, message } from 'antd'
2
- import { FormInstance, Rule } from 'antd/lib/form'
3
- import { UserOutlined, LockOutlined } from '@ant-design/icons'
4
- import React, {
5
- forwardRef,
6
- useImperativeHandle,
7
- useMemo,
8
- useState,
9
- } from 'react'
10
-
11
- import { getRequiredRules, getUserRegisterParams } from '../../../_utils'
12
- import { useGuardContext } from '../../../context/global/context'
13
- import { NEED_CAPTCHA } from '../../../../components/AuthingGuard/constants'
14
- import {
15
- LoginMethods,
16
- PasswordLoginFormProps,
17
- User,
18
- } from '../../../../components/AuthingGuard/types'
19
- import { LoginFormFooter } from '../../../../components/AuthingGuard/Forms/LoginFormFooter'
20
- import { useTranslation } from 'react-i18next'
21
- import { PasswordLoginMethods } from '../../api'
22
- import { requestClient } from '../../../_utils/http'
23
-
24
- export const PasswordLoginForm = forwardRef<
25
- FormInstance,
26
- PasswordLoginFormProps
27
- >(({ onSuccess, onValidateFail, onFail }, ref) => {
28
- const { state, getValue } = useGuardContext()
29
- const { t } = useTranslation()
30
-
31
- const { config, authClient, realHost, userPoolId, appId, guardEvents } = state
32
- const autoRegister = config.autoRegister
33
-
34
- const captchaUrl = `${realHost}/api/v2/security/captcha`
35
- const getCaptchaUrl = () => `${captchaUrl}?r=${+new Date()}`
36
-
37
- const [rawForm] = Form.useForm()
38
-
39
- const [needCaptcha, setNeedCaptcha] = useState(false)
40
- const [verifyCodeUrl, setVerifyCodeUrl] = useState<string | null>(null)
41
- const [loading, setLoading] = useState(false)
42
-
43
- const onFinishFailed = (errorInfo: any) => {
44
- setLoading(false)
45
- onValidateFail && onValidateFail(errorInfo)
46
- }
47
-
48
- const loginMethodsText = useMemo<
49
- Record<
50
- PasswordLoginMethods,
51
- {
52
- t: string
53
- sort: number
54
- }
55
- >
56
- >(
57
- () => ({
58
- 'email-password': {
59
- t: t('common.email'),
60
- sort: 2,
61
- },
62
- 'phone-password': {
63
- t: t('common.phoneNumber'),
64
- sort: 1,
65
- },
66
- 'username-password': {
67
- t: t('common.username'),
68
- sort: 0,
69
- },
70
- }),
71
- [t]
72
- )
73
-
74
- const usernamePlaceholder = useMemo(
75
- () =>
76
- t('login.inputAccount', {
77
- text: config.passwordLoginMethods
78
- ?.map((item) => loginMethodsText[item])
79
- .sort((a, b) => a.sort - b.sort)
80
- .map((item) => item.t)
81
- .join(' / '),
82
- }),
83
- [config.passwordLoginMethods, loginMethodsText, t]
84
- )
85
-
86
- const identityRules = useMemo(() => {
87
- const rules: Rule[] = getRequiredRules(t('common.accNotNull'))
88
-
89
- const loginMethods = config.passwordLoginMethods
90
-
91
- if (
92
- loginMethods?.includes('email-password') &&
93
- loginMethods?.length === 1
94
- ) {
95
- rules.push({
96
- type: 'email',
97
- message: t('common.emailFormatError'),
98
- })
99
- }
100
-
101
- return rules
102
- }, [config, t])
103
-
104
- const login = async (values: any) => {
105
- const identity = values.identity && values.identity.trim()
106
- const password = values.password && values.password.trim()
107
- const captchaCode = values.captchaCode && values.captchaCode.trim()
108
-
109
- const encrypt = authClient.options.encryptFunction
110
-
111
- const { publicKey, autoRegister } = getValue('config')
112
- const { code, data, message } = await requestClient.post<User>(
113
- '/api/v2/login/account',
114
- {
115
- account: identity,
116
- password: await encrypt!(password, publicKey),
117
- captchaCode,
118
- customData: getUserRegisterParams(),
119
- autoRegister: autoRegister,
120
- },
121
- {
122
- headers: {
123
- 'x-authing-userpool-id': userPoolId,
124
- 'x-authing-app-id': appId,
125
- },
126
- }
127
- )
128
-
129
- if (code === 200) {
130
- return data
131
- } else {
132
- Message.error(message)
133
- // eslint-disable-next-line no-throw-literal
134
- throw {
135
- code,
136
- message,
137
- data,
138
- }
139
- }
140
- }
141
-
142
- const onFinish = async (values: any) => {
143
- if (guardEvents.onBeforeLogin) {
144
- try {
145
- const canLogin = await guardEvents.onBeforeLogin(
146
- {
147
- type: LoginMethods.Password,
148
- data: {
149
- identity: values.identity,
150
- password: values.password,
151
- captchaCode: values.captchaCode,
152
- },
153
- },
154
- authClient
155
- )
156
-
157
- if (!canLogin) {
158
- setLoading(false)
159
- return
160
- }
161
- } catch (e) {
162
- if (typeof e === 'string') {
163
- message.error(e)
164
- } else {
165
- message.error(e.message)
166
- }
167
- setLoading(false)
168
- return
169
- }
170
- }
171
-
172
- try {
173
- let user: User | undefined
174
- user = await login(values)
175
- user && onSuccess && onSuccess(user)
176
- } catch (error) {
177
- if (error.code === NEED_CAPTCHA && verifyCodeUrl === null) {
178
- setNeedCaptcha(true)
179
- setVerifyCodeUrl(getCaptchaUrl())
180
- }
181
-
182
- onFail && onFail(error)
183
- } finally {
184
- setLoading(false)
185
- }
186
- }
187
-
188
- useImperativeHandle(ref, () => rawForm)
189
-
190
- const formItems = [
191
- {
192
- component: (
193
- <Input
194
- autoComplete="email,username,tel"
195
- size="large"
196
- placeholder={usernamePlaceholder}
197
- prefix={<UserOutlined style={{ color: '#ddd' }} />}
198
- />
199
- ),
200
- name: 'identity',
201
- rules: identityRules,
202
- },
203
- {
204
- component: (
205
- <Input.Password
206
- size="large"
207
- placeholder={t('login.inputLoginPwd')}
208
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
209
- />
210
- ),
211
- name: 'password',
212
- rules: getRequiredRules(t('common.passwordNotNull')),
213
- },
214
- {
215
- component: (
216
- <Input
217
- size="large"
218
- placeholder={t('login.inputCaptchaCode')}
219
- addonAfter={
220
- <img
221
- src={verifyCodeUrl ?? ''}
222
- alt={t('login.captchaCode')}
223
- style={{ height: '2em', cursor: 'pointer' }}
224
- onClick={() => setVerifyCodeUrl(getCaptchaUrl())}
225
- />
226
- }
227
- />
228
- ),
229
- name: 'captchaCode',
230
- rules: getRequiredRules(t('common.captchaCodeNotNull')),
231
- hide: !needCaptcha,
232
- },
233
- ]
234
-
235
- return (
236
- <Form
237
- form={rawForm}
238
- onSubmitCapture={() => setLoading(true)}
239
- onFinishFailed={onFinishFailed}
240
- onFinish={onFinish}
241
- >
242
- {autoRegister && (
243
- <Alert message={t('login.autoRegister')} style={{ marginBottom: 24 }} />
244
- )}
245
- {formItems.map(
246
- (item) =>
247
- !item.hide && (
248
- <Form.Item key={item.name} name={item.name} rules={item.rules}>
249
- {item.component}
250
- </Form.Item>
251
- )
252
- )}
253
-
254
- <LoginFormFooter
255
- needRegister
256
- needRestPwd
257
- loading={loading}
258
- ></LoginFormFooter>
259
- </Form>
260
- )
261
- })