@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,35 +0,0 @@
1
- .authing-g2-code-input-item {
2
- text-align: center;
3
- width: 40px;
4
- min-width: 40px;
5
- min-height: 40px;
6
- height: 40px;
7
- line-height: 40px;
8
- background-color: #f5f6f7;
9
- border: unset;
10
- border-radius: 4px;
11
-
12
- &:not(:first-child) {
13
- margin-left: 18px;
14
- }
15
- input {
16
- text-align: center;
17
- }
18
- }
19
- .authing-g2-code-input-divider {
20
- width: 14px;
21
- min-width: 14px;
22
- max-width: 14px;
23
- margin-left: 18px;
24
- }
25
- .authing-g2-code-input {
26
- display: flex;
27
- align-items: center;
28
- }
29
-
30
- .authing-ant-form-item-has-error {
31
- .authing-g2-code-input-item {
32
- background-color: #f5f6f7;
33
- border: 1px solid #ff4d4f;
34
- }
35
- }
@@ -1,24 +0,0 @@
1
- import { GuardModuleAction, GuardModuleType } from '../Guard/module'
2
-
3
- export const codeMap: Record<number, GuardModuleAction> = {
4
- // 待添加
5
- 2021: {
6
- action: 'changeModule',
7
- module: GuardModuleType.LOGIN,
8
- },
9
- 1700: {
10
- action: 'insideFix',
11
- message: 'verification failed, let components inside fix is fine.',
12
- },
13
- 1701: {
14
- action: 'insideFix',
15
- message: 'verification failed, let components inside fix is fine.',
16
- },
17
- 1702: {
18
- action: 'insideFix',
19
- message: 'verification failed, let components inside fix is fine.',
20
- },
21
- 500: {
22
- action: 'message',
23
- },
24
- }
@@ -1,203 +0,0 @@
1
- import { UserOutlined } from '@ant-design/icons'
2
- import { Input, message, message as Message } from 'antd'
3
- import { Form } from 'antd'
4
- import { EmailScene, User } from 'authing-js-sdk'
5
- import React, { useRef, useState } from 'react'
6
- import { useTranslation } from 'react-i18next'
7
- import { VerifyCodeInput } from '../VerifyCodeInput'
8
- import { useAuthClient } from '../../Guard/authClient'
9
- import { SendCodeBtn } from '../../SendCode/SendCodeBtn'
10
- import SubmitButton from '../../SubmitButton'
11
- import { EmailFormItem, ICheckProps } from '../../ValidatorRules'
12
- import { MFAConfig } from '../props'
13
- import { VerifyCodeFormItem } from '../VerifyCodeInput/VerifyCodeFormItem'
14
-
15
- interface BindMFAEmailProps {
16
- mfaToken: string
17
- onBind: (email: string) => void
18
- config: any
19
- }
20
- export const BindMFAEmail: React.FC<BindMFAEmailProps> = ({
21
- mfaToken,
22
- onBind,
23
- config,
24
- }) => {
25
- const submitButtonRef = useRef<any>(null)
26
- const { t } = useTranslation()
27
- const [form] = Form.useForm()
28
- const ref = useRef<ICheckProps>(null)
29
-
30
- const onFinish = async ({ email }: any) => {
31
- submitButtonRef.current?.onSpin(true)
32
- await form.validateFields()
33
- try {
34
- onBind(email)
35
- } catch (e: any) {
36
- const error = JSON.parse(e?.message)
37
- submitButtonRef.current.onError()
38
- Message.error(error.message)
39
- } finally {
40
- submitButtonRef.current?.onSpin(false)
41
- }
42
- }
43
- return (
44
- <>
45
- <p className="authing-g2-mfa-title">{t('common.bindEmail')}</p>
46
- <p className="authing-g2-mfa-tips">{t('common.bindEmailDoc')}</p>
47
- <Form
48
- form={form}
49
- onFinish={onFinish}
50
- onFinishFailed={() => submitButtonRef.current.onError()}
51
- onValuesChange={(value) => {
52
- ref.current?.check(value)
53
- }}
54
- >
55
- <EmailFormItem
56
- className="authing-g2-input-form"
57
- name="email"
58
- userPoolId={config.__publicConfig__.userPoolId}
59
- form={form}
60
- ref={ref}
61
- checkRepeat={true}
62
- >
63
- <Input
64
- className="authing-g2-input"
65
- autoComplete="email"
66
- size="large"
67
- placeholder={t('login.inputEmail')}
68
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
69
- />
70
- </EmailFormItem>
71
-
72
- <SubmitButton text={t('common.sure')} ref={submitButtonRef} />
73
- </Form>
74
- </>
75
- )
76
- }
77
-
78
- interface VerifyMFAEmailProps {
79
- email: string
80
- mfaToken: string
81
- onVerify: (code: number, data: any) => void
82
- sendCodeRef: React.RefObject<HTMLButtonElement>
83
- codeLength: number
84
- }
85
-
86
- export const VerifyMFAEmail: React.FC<VerifyMFAEmailProps> = ({
87
- email,
88
- mfaToken,
89
- onVerify,
90
- sendCodeRef,
91
- codeLength,
92
- }) => {
93
- const authClient = useAuthClient()
94
- const submitButtonRef = useRef<any>(null)
95
- const { t } = useTranslation()
96
- const [form] = Form.useForm()
97
- const [sent, setSent] = useState(false)
98
-
99
- const sendVerifyCode = async () => {
100
- try {
101
- await authClient.sendEmail(email!, EmailScene.MfaVerify)
102
- setSent(true)
103
- return true
104
- } catch (e) {
105
- const errorMessage = JSON.parse(e.message)
106
- message.error(errorMessage.message)
107
- return false
108
- }
109
- }
110
-
111
- const onFinish = async (values: any) => {
112
- submitButtonRef.current?.onSpin(true)
113
- const mfaCode = form.getFieldValue('mfaCode')
114
-
115
- try {
116
- const user: User = await authClient.mfa.verifyAppEmailMfa({
117
- mfaToken,
118
- email: email!,
119
- code: mfaCode.join(''),
120
- })
121
-
122
- onVerify(200, user)
123
- } catch (e: any) {
124
- const error = JSON.parse(e?.message)
125
- onVerify(error.code as number, error)
126
- } finally {
127
- submitButtonRef.current?.onSpin(false)
128
- }
129
- }
130
-
131
- return (
132
- <>
133
- <p className="authing-g2-mfa-title">{t('login.inputEmailCode')}</p>
134
- <p className="authing-g2-mfa-tips">
135
- {sent
136
- ? `${t('login.verifyCodeSended')} ${email}`
137
- : t('login.clickSent')}
138
- </p>
139
- <Form
140
- form={form}
141
- onFinish={onFinish}
142
- onFinishFailed={() => submitButtonRef.current?.onError()}
143
- >
144
- <VerifyCodeFormItem
145
- codeLength={codeLength}
146
- ruleKeyword={t('common.captchaCode')}
147
- >
148
- <VerifyCodeInput length={codeLength} />
149
- </VerifyCodeFormItem>
150
-
151
- <SendCodeBtn
152
- btnRef={sendCodeRef}
153
- beforeSend={() => sendVerifyCode()}
154
- type="link"
155
- />
156
-
157
- <SubmitButton
158
- text={t('common.sure')}
159
- ref={submitButtonRef}
160
- className="g2-mfa-submit-button"
161
- />
162
- </Form>
163
- </>
164
- )
165
- }
166
-
167
- export const MFAEmail: React.FC<{
168
- mfaToken: string
169
- email?: string
170
- mfaLogin: any
171
- config: MFAConfig
172
- }> = ({ email: userEmail, mfaToken, mfaLogin, config }) => {
173
- const [email, setEmail] = useState(userEmail)
174
- const sendCodeRef = useRef<HTMLButtonElement>(null)
175
-
176
- const codeLength = config.__publicConfig__?.verifyCodeLength
177
-
178
- return (
179
- <>
180
- {email ? (
181
- <VerifyMFAEmail
182
- mfaToken={mfaToken}
183
- email={email}
184
- onVerify={(code, data) => {
185
- mfaLogin(code, data)
186
- }}
187
- sendCodeRef={sendCodeRef}
188
- codeLength={codeLength ?? 4}
189
- />
190
- ) : (
191
- <BindMFAEmail
192
- config={config}
193
- mfaToken={mfaToken}
194
- onBind={(email: string) => {
195
- console.log('email', email)
196
- setEmail(email)
197
- sendCodeRef.current?.click()
198
- }}
199
- />
200
- )}
201
- </>
202
- )
203
- }
@@ -1,297 +0,0 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { detectSingleFace } from 'face-api.js'
4
- import { useGuardHttp } from '../../_utils/guradHttp'
5
- import {
6
- FACE_SCORE,
7
- devicesConstraints,
8
- dataURItoBlob,
9
- getCurrentFaceDetectionNet,
10
- getFaceDetectorOptions,
11
- isFaceDetectionModelLoaded,
12
- } from './face_deps'
13
- import { ImagePro } from '../../ImagePro'
14
- import SubmitButton from '../../SubmitButton'
15
-
16
- const useDashoffset = (percent: number) => {
17
- // 接受 0 - 1,返回 0-700 之间的偏移量
18
- let offset = percent * 7
19
-
20
- // 在识别成功的时候,返回绿色
21
- let dashStyle = {}
22
- return { offset, dashStyle }
23
- }
24
-
25
- export const MFAFace = (props: any) => {
26
- let { postForm, post } = useGuardHttp()
27
- let { t } = useTranslation()
28
- const [faceState, setFaceState] = useState('ready') // ready, identifying, retry
29
- const [percent, setPercent] = useState(0) // 识别进度(相似性)
30
-
31
- const videoRef = useRef<HTMLVideoElement>(null)
32
- const canvasRef = useRef<HTMLCanvasElement>(null)
33
- const interval = useRef<NodeJS.Timeout | undefined>()
34
- const p1 = useRef<string>() // p1 key
35
- const p2 = useRef<string>() // p2 key
36
- const cooldown = useRef<number>(6) // p2 cooldown, * 500ms
37
- const cdnBase = props.config.__publicConfig__.cdnBase
38
-
39
- let { offset, dashStyle } = useDashoffset(percent)
40
-
41
- // 预加载数据
42
- useEffect(() => {
43
- // 载入 cdn
44
- let cdnContext = getCurrentFaceDetectionNet().loadFromUri(
45
- `${cdnBase}/face-api/v1/tiny_face_detector_model-weights_manifest.json`
46
- )
47
- cdnContext.then((result) => {
48
- // setLoading(false)
49
- })
50
-
51
- if (faceState !== 'identifying') {
52
- return // 不存在 video dom,不要去尝试了
53
- }
54
- let devicesContext = navigator.mediaDevices.getUserMedia(devicesConstraints)
55
- devicesContext
56
- .then((stream) => {
57
- videoRef.current!.srcObject = stream
58
- })
59
- .catch((e) => {
60
- // 没有设备,或没有授权
61
- console.error(e)
62
- // setVideoType(VideoAction.ERROR)
63
- // setProgressStatus('exception')
64
- // setPercent(100)
65
- // setVideoError(e.message)
66
- })
67
-
68
- return () => {
69
- interval.current && clearInterval(interval.current)
70
- }
71
- }, [faceState, interval, props.config, cdnBase])
72
-
73
- // 监听 faceState
74
- useEffect(() => {
75
- if (faceState === 'identifying' || faceState === 'retry') {
76
- props.setShowMethods(false)
77
- } else {
78
- props.setShowMethods(true)
79
- }
80
- // eslint-disable-next-line react-hooks/exhaustive-deps
81
- }, [faceState])
82
-
83
- // 上传文件
84
- const uploadImage = async (blob: Blob) => {
85
- const formData = new FormData()
86
- formData.append('folder', 'photos')
87
- formData.append('file', blob, 'personal.jpeg')
88
-
89
- let url = '/api/v2/upload?folder=photos&private=true'
90
- let result = await postForm<any>(url, formData)
91
- let key = result.data?.key
92
- return key
93
- }
94
-
95
- // get base 64
96
- const getBase64 = (videoDom: any) => {
97
- const canvas = canvasRef.current!
98
- const ctx = canvas!.getContext('2d')!
99
- ctx.clearRect(0, 0, canvas.width, canvas.height)
100
- ctx.drawImage(videoDom, 0, 0, canvas.width, canvas.height)
101
- const base64Data = canvas.toDataURL('image/jpeg', 1.0)
102
- return base64Data
103
- }
104
-
105
- const faceLogin = (result: any) => {
106
- let { code, data, message } = result
107
-
108
- if (code === 1700 || code === 1701 || code === 1702) {
109
- p1.current = undefined
110
- p2.current = undefined
111
- interval.current = undefined
112
- cooldown.current = 6
113
- setFaceState('retry')
114
- }
115
- props.mfaLogin(code, data, message)
116
- }
117
-
118
- const faceBind = () => {
119
- let url = '/api/v2/mfa/face/associate'
120
- let data = {
121
- photoA: p1.current,
122
- photoB: p2.current,
123
- }
124
- let mfaToken = props.initData.mfaToken
125
- let config = {
126
- headers: {
127
- authorization: mfaToken,
128
- },
129
- }
130
- post(url, data, config).then((result) => {
131
- faceLogin(result)
132
- })
133
- }
134
-
135
- const faceCheck = () => {
136
- let url = '/api/v2/mfa/face/verify'
137
- let data = {
138
- photo: p1.current,
139
- }
140
- let mfaToken = props.initData.mfaToken
141
- let config = {
142
- headers: {
143
- authorization: mfaToken,
144
- },
145
- }
146
- post(url, data, config).then((result) => {
147
- // 如果是 1702,那么久绑定一个
148
- faceLogin(result)
149
- })
150
- }
151
-
152
- // bind 的情况
153
- const goToBindScene = (key: string) => {
154
- if (!p1.current) {
155
- p1.current = key
156
- } else {
157
- if (cooldown.current > 0) {
158
- cooldown.current -= 1
159
- }
160
- if (cooldown.current <= 0) {
161
- p2.current = key
162
- // 彻底上传完了,应该走验证了
163
- interval.current && clearInterval(interval.current)
164
- faceBind()
165
- }
166
- }
167
- }
168
-
169
- // goToCheck 的情况
170
- const goToCheckScene = (key: string) => {
171
- p1.current = key
172
- interval.current && clearInterval(interval.current)
173
- faceCheck()
174
- }
175
-
176
- // 识别成功,自动前进到下一个步骤
177
- const quitIdentifying = (blob: Blob) => {
178
- setPercent(100)
179
- uploadImage(blob).then((key) => {
180
- if (props.initData?.faceMfaEnabled === true) {
181
- goToCheckScene(key)
182
- } else {
183
- goToBindScene(key)
184
- }
185
- })
186
- }
187
-
188
- const autoShoot = useCallback(async () => {
189
- if (!interval.current) {
190
- interval.current = setInterval(() => autoShoot(), 500)
191
- }
192
- const videoDom = videoRef.current!
193
- if (videoDom.paused || videoDom.ended || !isFaceDetectionModelLoaded()) {
194
- return
195
- }
196
- const options = getFaceDetectorOptions()
197
- const result = await detectSingleFace(videoDom, options)
198
-
199
- if (result) {
200
- if (result.score > FACE_SCORE) {
201
- const base64Data = getBase64(videoDom)
202
- const blob = dataURItoBlob(base64Data)
203
- quitIdentifying(blob) // 识别成功,退出识别
204
- } else {
205
- // 识别失败,但是有结果,设置相似性
206
- setPercent(() => {
207
- return (result.score / FACE_SCORE) * 100
208
- })
209
- // console.log('识别失败,但是有结果,设置相似性', percent)
210
- }
211
- } else {
212
- setPercent(10)
213
- }
214
- // eslint-disable-next-line react-hooks/exhaustive-deps
215
- }, [])
216
-
217
- return (
218
- <div>
219
- <h3 className="authing-g2-mfa-title">{t('common.faceText1')}</h3>
220
- <p className="authing-g2-mfa-tips">{t('common.faceText2')}</p>
221
- {faceState === 'ready' && (
222
- <>
223
- <ImagePro
224
- className="g2-mfa-face-image"
225
- width={247}
226
- height={131}
227
- src={`${cdnBase}/face.png`}
228
- alt=""
229
- />
230
-
231
- <SubmitButton
232
- onClick={() => {
233
- setFaceState('identifying')
234
- autoShoot()
235
- }}
236
- text={t('common.faceText3')}
237
- className="mfa-face"
238
- />
239
- </>
240
- )}
241
- <div
242
- className="g2-mfa-face-identifying"
243
- style={{
244
- display: faceState !== 'ready' ? 'flex' : 'none',
245
- }}
246
- >
247
- <video
248
- className="video-round"
249
- ref={videoRef}
250
- // onLoadedMetadata={() => onIdentify()}
251
- id="inputVideo"
252
- autoPlay
253
- muted
254
- playsInline
255
- />
256
- <div
257
- className="video-round mesh"
258
- style={{
259
- display: faceState === 'retry' ? 'flex' : 'none',
260
- }}
261
- onClick={() => {
262
- setFaceState('identifying')
263
- setPercent(0)
264
- autoShoot()
265
- }}
266
- >
267
- {t('common.faceText4')}
268
- </div>
269
-
270
- <div className="video-round ring">
271
- <svg width={240} height={240} fill="none">
272
- <circle
273
- className="svg-circle-running"
274
- style={dashStyle}
275
- strokeDasharray={700} // 根据周长做 0-700 之间的数值表示准确率
276
- strokeDashoffset={700 - offset} // 处理这个 offset, 0-700之间的数
277
- cx={120}
278
- cy={120}
279
- r={110}
280
- />
281
- </svg>
282
- </div>
283
- </div>
284
-
285
- <canvas
286
- style={{
287
- width: 210,
288
- height: 210,
289
- opacity: 0,
290
- position: 'absolute',
291
- display: 'none',
292
- }}
293
- ref={canvasRef}
294
- />
295
- </div>
296
- )
297
- }
@@ -1,37 +0,0 @@
1
- import { nets, TinyFaceDetectorOptions } from 'face-api.js'
2
-
3
- let inputSize = 512
4
- let scoreThreshold = 0.5
5
-
6
- export const devicesConstraints = {
7
- video: {
8
- width: 210,
9
- height: 210,
10
- },
11
- }
12
- export const FACE_SCORE = 0.65
13
-
14
- export function getFaceDetectorOptions() {
15
- return new TinyFaceDetectorOptions({ inputSize, scoreThreshold })
16
- }
17
-
18
- export function getCurrentFaceDetectionNet() {
19
- return nets.tinyFaceDetector
20
- }
21
-
22
- export function isFaceDetectionModelLoaded() {
23
- return !!getCurrentFaceDetectionNet().params
24
- }
25
-
26
- export function dataURItoBlob(base64Data: any) {
27
- var byteString
28
- if (base64Data.split(',')[0].indexOf('base64') >= 0)
29
- byteString = atob(base64Data.split(',')[1])
30
- else byteString = unescape(base64Data.split(',')[1])
31
- var mimeString = base64Data.split(',')[0].split(':')[1].split(';')[0]
32
- var ia = new Uint8Array(byteString.length)
33
- for (var i = 0; i < byteString.length; i++) {
34
- ia[i] = byteString.charCodeAt(i)
35
- }
36
- return new Blob([ia], { type: mimeString })
37
- }