@authing/react-ui-components 3.0.2-beta.1 → 3.0.2-beta.14

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 (263) hide show
  1. package/lib/index.d.ts +555 -46
  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 +30 -10
  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/asset-manifest.json +0 -26
  11. package/build/favicon.ico +0 -0
  12. package/build/index.html +0 -1
  13. package/build/logo192.png +0 -0
  14. package/build/logo512.png +0 -0
  15. package/build/manifest.json +0 -25
  16. package/build/robots.txt +0 -3
  17. package/build/static/css/2.9512539b.chunk.css +0 -3
  18. package/build/static/css/2.9512539b.chunk.css.map +0 -1
  19. package/build/static/css/main.0ff9e24a.chunk.css +0 -2
  20. package/build/static/css/main.0ff9e24a.chunk.css.map +0 -1
  21. package/build/static/js/2.1105ecfb.chunk.js +0 -3
  22. package/build/static/js/2.1105ecfb.chunk.js.LICENSE.txt +0 -102
  23. package/build/static/js/2.1105ecfb.chunk.js.map +0 -1
  24. package/build/static/js/3.fd17f196.chunk.js +0 -2
  25. package/build/static/js/3.fd17f196.chunk.js.map +0 -1
  26. package/build/static/js/main.a47645ff.chunk.js +0 -2
  27. package/build/static/js/main.a47645ff.chunk.js.map +0 -1
  28. package/build/static/js/runtime-main.ef138021.js +0 -2
  29. package/build/static/js/runtime-main.ef138021.js.map +0 -1
  30. package/build/static/media/loading.4a67a5f3.svg +0 -29
  31. package/components/AuthingDropdown/index.tsx +0 -52
  32. package/components/AuthingDropdown/style.less +0 -43
  33. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  34. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  35. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  36. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  37. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  38. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  39. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  40. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  41. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  42. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  43. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  44. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  45. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  46. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  47. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  48. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  49. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  50. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  51. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  52. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  53. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  54. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  55. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  56. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  57. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  58. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  59. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  60. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  61. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  62. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  63. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  64. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  65. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  66. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  67. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  68. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  69. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  70. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  71. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  72. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  73. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  74. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  75. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  76. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  77. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  78. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  79. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  80. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  81. package/components/AuthingGuard/Forms/index.ts +0 -13
  82. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  83. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  84. package/components/AuthingGuard/Header/index.tsx +0 -25
  85. package/components/AuthingGuard/Header/style.less +0 -52
  86. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  87. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  88. package/components/AuthingGuard/IconFont/style.less +0 -6
  89. package/components/AuthingGuard/IconFont/svg.js +0 -2
  90. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  91. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  92. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  93. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  94. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  95. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  96. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  97. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  98. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  99. package/components/AuthingGuard/api/appConfig.ts +0 -146
  100. package/components/AuthingGuard/api/index.ts +0 -3
  101. package/components/AuthingGuard/api/sso.ts +0 -29
  102. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  103. package/components/AuthingGuard/constants.ts +0 -107
  104. package/components/AuthingGuard/hooks/index.tsx +0 -70
  105. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  106. package/components/AuthingGuard/index.tsx +0 -126
  107. package/components/AuthingGuard/style.less +0 -103
  108. package/components/AuthingGuard/types/Forms.ts +0 -94
  109. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  110. package/components/AuthingGuard/types/GuardState.ts +0 -7
  111. package/components/AuthingGuard/types/Locales.ts +0 -12
  112. package/components/AuthingGuard/types/index.ts +0 -4
  113. package/components/AuthingTabs/index.tsx +0 -98
  114. package/components/AuthingTabs/style.less +0 -135
  115. package/components/BindTotp/core/bindSuccess.tsx +0 -73
  116. package/components/BindTotp/core/securityCode.tsx +0 -108
  117. package/components/BindTotp/index.tsx +0 -134
  118. package/components/BindTotp/interface.ts +0 -30
  119. package/components/BindTotp/styles.less +0 -57
  120. package/components/ChangeLanguage/index.tsx +0 -35
  121. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  122. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  123. package/components/ChangePassword/index.tsx +0 -59
  124. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  125. package/components/CompleteInfo/index.tsx +0 -45
  126. package/components/CompleteInfo/interface.ts +0 -40
  127. package/components/CompleteInfo/styles.less +0 -7
  128. package/components/CopyAbleText/index.tsx +0 -54
  129. package/components/CopyAbleText/style.less +0 -13
  130. package/components/DownloadAuthenticator/index.tsx +0 -97
  131. package/components/DownloadAuthenticator/interface.ts +0 -22
  132. package/components/DownloadAuthenticator/styles.less +0 -52
  133. package/components/Error/index.tsx +0 -21
  134. package/components/Error/interface.ts +0 -9
  135. package/components/Error/styles.less +0 -12
  136. package/components/ForgetPassword/core/resetPassword.tsx +0 -162
  137. package/components/ForgetPassword/index.tsx +0 -78
  138. package/components/ForgetPassword/interface.ts +0 -32
  139. package/components/Guard/Guard.tsx +0 -255
  140. package/components/Guard/authClient.ts +0 -46
  141. package/components/Guard/config.ts +0 -19
  142. package/components/Guard/event.ts +0 -52
  143. package/components/Guard/index.tsx +0 -4
  144. package/components/Guard/module.ts +0 -20
  145. package/components/Guard/stateMachine.ts +0 -133
  146. package/components/Guard/styles.less +0 -461
  147. package/components/IconFont/iconfont.js +0 -74
  148. package/components/IconFont/index.tsx +0 -16
  149. package/components/IconFont/style.less +0 -6
  150. package/components/IconFont/svg.js +0 -2
  151. package/components/ImagePro/index.tsx +0 -53
  152. package/components/ImagePro/styles.less +0 -40
  153. package/components/InputNumber/index.tsx +0 -33
  154. package/components/Login/codemap.ts +0 -47
  155. package/components/Login/core/withAD.tsx +0 -9
  156. package/components/Login/core/withAppQrcode.tsx +0 -49
  157. package/components/Login/core/withLDAP.tsx +0 -146
  158. package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
  159. package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -31
  160. package/components/Login/core/withPassword/InputAccount.tsx +0 -64
  161. package/components/Login/core/withPassword/index.tsx +0 -173
  162. package/components/Login/core/withPhonecode.tsx +0 -122
  163. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  164. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  165. package/components/Login/index.tsx +0 -373
  166. package/components/Login/props.ts +0 -74
  167. package/components/Login/socialLogin/index.tsx +0 -407
  168. package/components/Login/socialLogin/style.less +0 -69
  169. package/components/Login/styles.less +0 -53
  170. package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
  171. package/components/MFA/VerifyCodeInput/index.tsx +0 -145
  172. package/components/MFA/VerifyCodeInput/style.less +0 -35
  173. package/components/MFA/codemap.ts +0 -24
  174. package/components/MFA/core/email.tsx +0 -203
  175. package/components/MFA/core/face.tsx +0 -297
  176. package/components/MFA/core/face_deps.tsx +0 -37
  177. package/components/MFA/core/sms.tsx +0 -204
  178. package/components/MFA/core/totp.tsx +0 -122
  179. package/components/MFA/index.tsx +0 -143
  180. package/components/MFA/mfaMethods/index.tsx +0 -88
  181. package/components/MFA/mfaMethods/style.less +0 -39
  182. package/components/MFA/props.ts +0 -51
  183. package/components/MFA/styles.less +0 -100
  184. package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
  185. package/components/NeedHelpView/index.tsx +0 -47
  186. package/components/RecoveryCode/core/useCode.tsx +0 -71
  187. package/components/RecoveryCode/index.tsx +0 -27
  188. package/components/RecoveryCode/interface.ts +0 -31
  189. package/components/RecoveryCode/style.less +0 -13
  190. package/components/Register/codemap.ts +0 -12
  191. package/components/Register/components/Agreements/index.tsx +0 -81
  192. package/components/Register/components/Agreements/style.less +0 -44
  193. package/components/Register/core/WithEmail.tsx +0 -239
  194. package/components/Register/core/WithPhone.tsx +0 -184
  195. package/components/Register/index.tsx +0 -138
  196. package/components/Register/props.ts +0 -50
  197. package/components/SendCode/SendCodeBtn.tsx +0 -96
  198. package/components/SendCode/index.tsx +0 -94
  199. package/components/SendCode/style.less +0 -31
  200. package/components/ShieldSpin/index.tsx +0 -27
  201. package/components/ShieldSpin/loading.svg +0 -29
  202. package/components/SubmitButton/index.tsx +0 -50
  203. package/components/SubmitSuccess/index.tsx +0 -66
  204. package/components/SubmitSuccess/interface.ts +0 -17
  205. package/components/Type/index.ts +0 -52
  206. package/components/ValidatorRules/EmailFormItem.tsx +0 -95
  207. package/components/ValidatorRules/PhoneFormItem.tsx +0 -100
  208. package/components/ValidatorRules/index.ts +0 -14
  209. package/components/VerifyCodeInput/index.tsx +0 -76
  210. package/components/VerifyCodeInput/style.less +0 -24
  211. package/components/_utils/GuardErrorCode.ts +0 -9
  212. package/components/_utils/clipboard.ts +0 -27
  213. package/components/_utils/config.ts +0 -118
  214. package/components/_utils/guradHttp.ts +0 -97
  215. package/components/_utils/hooks/index.ts +0 -64
  216. package/components/_utils/http.ts +0 -85
  217. package/components/_utils/index.ts +0 -322
  218. package/components/_utils/locales/en/common.json +0 -227
  219. package/components/_utils/locales/en/index.ts +0 -6
  220. package/components/_utils/locales/en/login.json +0 -96
  221. package/components/_utils/locales/en/map.json +0 -4
  222. package/components/_utils/locales/en/user.json +0 -82
  223. package/components/_utils/locales/index.ts +0 -45
  224. package/components/_utils/locales/zh/common.json +0 -227
  225. package/components/_utils/locales/zh/index.ts +0 -6
  226. package/components/_utils/locales/zh/login.json +0 -96
  227. package/components/_utils/locales/zh/map.json +0 -4
  228. package/components/_utils/locales/zh/user.json +0 -82
  229. package/components/_utils/popupCenter.ts +0 -48
  230. package/components/assets/images/error.png +0 -0
  231. package/components/context/base.tsx +0 -28
  232. package/components/context/global/context.tsx +0 -39
  233. package/components/context/global/reducer.tsx +0 -56
  234. package/components/context/module/context.tsx +0 -23
  235. package/components/index.ts +0 -12
  236. package/config/antdReplacer.js +0 -51
  237. package/config/env.js +0 -104
  238. package/config/getHttpsConfig.js +0 -66
  239. package/config/jest/cssTransform.js +0 -14
  240. package/config/jest/fileTransform.js +0 -40
  241. package/config/modules.js +0 -134
  242. package/config/paths.js +0 -71
  243. package/config/pnpTs.js +0 -35
  244. package/config/webpack.config.js +0 -835
  245. package/config/webpackDevServer.config.js +0 -130
  246. package/examples.tsx +0 -82
  247. package/index.js +0 -1
  248. package/logo.svg +0 -7
  249. package/public/favicon.ico +0 -0
  250. package/public/index.html +0 -43
  251. package/public/logo192.png +0 -0
  252. package/public/logo512.png +0 -0
  253. package/public/manifest.json +0 -25
  254. package/public/robots.txt +0 -3
  255. package/react-app-env.d.ts +0 -71
  256. package/reportWebVitals.ts +0 -15
  257. package/scripts/build.js +0 -208
  258. package/scripts/lib.js +0 -200
  259. package/scripts/publish.js +0 -57
  260. package/scripts/start.js +0 -162
  261. package/scripts/test.js +0 -49
  262. package/setupTests.ts +0 -5
  263. package/tsconfig.json +0 -30
@@ -1,204 +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 { User } from 'authing-js-sdk'
5
- import React, { useCallback, 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 { ICheckProps, PhoneFormItem } from '../../ValidatorRules'
12
- import { VerifyCodeFormItem } from '../VerifyCodeInput/VerifyCodeFormItem'
13
- import { MFAConfig } from '../props'
14
- import { InputNumber } from '../../InputNumber'
15
- export interface BindMFASmsProps {
16
- mfaToken: string
17
- onBind: (phone: string) => void
18
- config: any
19
- }
20
-
21
- export const BindMFASms: React.FC<BindMFASmsProps> = ({
22
- mfaToken,
23
- onBind,
24
- config,
25
- }) => {
26
- const authClient = useAuthClient()
27
- const submitButtonRef = useRef<any>(null)
28
- const { t } = useTranslation()
29
- const [form] = Form.useForm()
30
-
31
- const ref = useRef<ICheckProps>(null)
32
- const onFinish = async ({ phone }: any) => {
33
- submitButtonRef.current.onSpin(true)
34
- await form.validateFields()
35
- try {
36
- onBind(phone)
37
- } catch (e) {
38
- // do nothing
39
- submitButtonRef.current?.onError()
40
- } finally {
41
- submitButtonRef.current?.onSpin(false)
42
- }
43
- }
44
-
45
- return (
46
- <>
47
- <h3 className="authing-g2-mfa-title">{t('common.bindPhone')}</h3>
48
- <p className="authing-g2-mfa-tips">{t('login.bindPhoneInfo')}</p>
49
- <Form
50
- form={form}
51
- onFinish={onFinish}
52
- onFinishFailed={() => submitButtonRef.current.onError()}
53
- onValuesChange={() => {
54
- ref.current?.check()
55
- }}
56
- >
57
- <PhoneFormItem
58
- className="authing-g2-input-form"
59
- name="phone"
60
- userPoolId={config.__publicConfig__.userPoolId}
61
- form={form}
62
- ref={ref}
63
- checkRepeat={true}
64
- >
65
- <InputNumber
66
- className="authing-g2-input"
67
- autoComplete="tel"
68
- size="large"
69
- placeholder={t('login.inputPhone')}
70
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
71
- />
72
- </PhoneFormItem>
73
- <SubmitButton text={t('common.sure')} ref={submitButtonRef} />
74
- </Form>
75
- </>
76
- )
77
- }
78
-
79
- export interface VerifyMFASmsProps {
80
- mfaToken: string
81
- phone: string
82
- onVerify: (code: number, data: any) => void
83
- sendCodeRef: React.RefObject<HTMLButtonElement>
84
- codeLength: number
85
- }
86
-
87
- export const VerifyMFASms: React.FC<VerifyMFASmsProps> = ({
88
- mfaToken,
89
- phone,
90
- onVerify,
91
- sendCodeRef,
92
- codeLength = 4,
93
- }) => {
94
- const authClient = useAuthClient()
95
- const submitButtonRef = useRef<any>(null)
96
- const { t } = useTranslation()
97
- const [form] = Form.useForm()
98
-
99
- const [sent, setSent] = useState(false)
100
-
101
- const onFinish = async (values: any) => {
102
- submitButtonRef.current.onSpin(true)
103
- const mfaCode = form.getFieldValue('mfaCode')
104
- try {
105
- const user: User = await authClient.mfa.verifyAppSmsMfa({
106
- mfaToken,
107
- phone: phone!,
108
- code: mfaCode.join(''),
109
- })
110
- // TODO
111
- onVerify(200, user)
112
- } catch (e) {
113
- const error = JSON.parse(e.message)
114
- submitButtonRef.current.onError()
115
- onVerify(error.code as number, error)
116
- } finally {
117
- submitButtonRef.current?.onSpin(false)
118
- }
119
- }
120
-
121
- const sendVerifyCode = async () => {
122
- try {
123
- await authClient.sendSmsCode(phone!)
124
- setSent(true)
125
- return true
126
- } catch (e) {
127
- const errorMessage = JSON.parse(e.message)
128
- message.error(errorMessage.message)
129
- return false
130
- }
131
- }
132
-
133
- return (
134
- <>
135
- <h3 className="authing-g2-mfa-title">{t('login.inputPhoneCode')}</h3>
136
- <p className="authing-g2-mfa-tips">
137
- {sent
138
- ? `${t('login.verifyCodeSended')} ${phone}`
139
- : t('login.clickSent')}
140
- </p>
141
- <Form
142
- form={form}
143
- onFinish={onFinish}
144
- onFinishFailed={() => submitButtonRef.current.onError()}
145
- >
146
- <VerifyCodeFormItem
147
- codeLength={codeLength}
148
- ruleKeyword={t('common.captchaCode')}
149
- >
150
- <VerifyCodeInput length={codeLength} />
151
- </VerifyCodeFormItem>
152
-
153
- <SendCodeBtn
154
- btnRef={sendCodeRef}
155
- beforeSend={() => sendVerifyCode()}
156
- type="link"
157
- />
158
-
159
- <SubmitButton
160
- text={t('common.sure')}
161
- ref={submitButtonRef}
162
- className="g2-mfa-submit-button"
163
- />
164
- </Form>
165
- </>
166
- )
167
- }
168
-
169
- export const MFASms: React.FC<{
170
- mfaToken: string
171
- phone?: string
172
- mfaLogin: any
173
- config: MFAConfig
174
- }> = ({ phone: userPhone, mfaToken, mfaLogin, config }) => {
175
- const [phone, setPhone] = useState(userPhone)
176
- const sendCodeRef = useRef<HTMLButtonElement>(null)
177
-
178
- const codeLength = config.__publicConfig__?.verifyCodeLength
179
-
180
- return (
181
- <>
182
- {phone ? (
183
- <VerifyMFASms
184
- mfaToken={mfaToken}
185
- phone={phone}
186
- onVerify={(code, data) => {
187
- mfaLogin(code, data)
188
- }}
189
- codeLength={codeLength ?? 4}
190
- sendCodeRef={sendCodeRef}
191
- />
192
- ) : (
193
- <BindMFASms
194
- config={config}
195
- mfaToken={mfaToken}
196
- onBind={(phone: string) => {
197
- setPhone(phone)
198
- sendCodeRef.current?.click()
199
- }}
200
- />
201
- )}
202
- </>
203
- )
204
- }
@@ -1,122 +0,0 @@
1
- import { Form } from 'antd'
2
- import React, { useRef } from 'react'
3
- import { useTranslation } from 'react-i18next'
4
- import { useAsyncFn } from 'react-use'
5
- import { GuardModuleType } from '../../Guard/module'
6
- import { useGuardHttp } from '../../_utils/guradHttp'
7
- import { GuardMFAInitData, MFAConfig } from '../props'
8
- import { message as Message } from 'antd'
9
- import SubmitButton from '../../SubmitButton'
10
- import { VerifyCodeFormItem } from '../VerifyCodeInput/VerifyCodeFormItem'
11
- import { VerifyCodeInput } from '../VerifyCodeInput'
12
- export interface BindMFATotpProps {
13
- initData: GuardMFAInitData
14
- changeModule: any
15
- }
16
-
17
- export const BindMFATotp: React.FC<BindMFATotpProps> = ({
18
- changeModule,
19
- initData,
20
- }) => {
21
- const { t } = useTranslation()
22
-
23
- const next = () => changeModule(GuardModuleType.BIND_TOTP, initData)
24
- return (
25
- <>
26
- <p className="authing-g2-mfa-title">{t('common.bindTotp')}</p>
27
- <p className="authing-g2-mfa-tips">{t('common.otpText1')}</p>
28
- <SubmitButton
29
- text={t('common.sure')}
30
- onClick={next}
31
- className="g2-mfa-submit-button bind-totp"
32
- />
33
- </>
34
- )
35
- }
36
-
37
- export interface VerifyMFATotpProps {
38
- mfaToken: string
39
- mfaLogin: any
40
- }
41
-
42
- export const VerifyMFATotp: React.FC<VerifyMFATotpProps> = ({
43
- mfaToken,
44
- mfaLogin,
45
- }) => {
46
- const { t } = useTranslation()
47
- const [form] = Form.useForm()
48
-
49
- const submitButtonRef = useRef<any>(null)
50
-
51
- const { post } = useGuardHttp()
52
-
53
- const [, onFinish] = useAsyncFn(async () => {
54
- submitButtonRef.current.onSpin(true)
55
-
56
- const mfaCode = form.getFieldValue('mfaCode')
57
- try {
58
- const { code, data, message } = await post(
59
- '/api/v2/mfa/totp/verify',
60
- {
61
- totp: mfaCode.join(''),
62
- },
63
- {
64
- headers: {
65
- authorization: mfaToken,
66
- },
67
- }
68
- )
69
-
70
- if (code !== 200) {
71
- mfaLogin(200, message)
72
- Message.error(message)
73
- } else {
74
- mfaLogin(200, data)
75
- }
76
- } finally {
77
- submitButtonRef.current.onSpin(false)
78
- }
79
- }, [mfaToken])
80
-
81
- return (
82
- <>
83
- <p className="authing-g2-mfa-title">{t('login.accPwdLoginVerify')}</p>
84
- <p className="authing-g2-mfa-tips">{t('login.inputSixCode')}</p>
85
- <Form
86
- form={form}
87
- onSubmitCapture={() => {}}
88
- onFinish={onFinish}
89
- onFinishFailed={() => submitButtonRef.current.onError()}
90
- >
91
- <VerifyCodeFormItem codeLength={6}>
92
- <VerifyCodeInput length={6} showDivider={true} gutter={'10px'} />
93
- </VerifyCodeFormItem>
94
-
95
- <SubmitButton text={t('common.sure')} ref={submitButtonRef} />
96
- </Form>
97
- </>
98
- )
99
- }
100
-
101
- export interface MFATotpProps {
102
- changeModule: any
103
- config: MFAConfig
104
- initData: GuardMFAInitData
105
- mfaLogin: any
106
- }
107
-
108
- export const MFATotp: React.FC<MFATotpProps> = ({
109
- changeModule,
110
- initData,
111
- mfaLogin,
112
- }) => {
113
- return (
114
- <>
115
- {initData.totpMfaEnabled ? (
116
- <VerifyMFATotp mfaToken={initData.mfaToken} mfaLogin={mfaLogin} />
117
- ) : (
118
- <BindMFATotp initData={initData} changeModule={changeModule} />
119
- )}
120
- </>
121
- )
122
- }
@@ -1,143 +0,0 @@
1
- import React, { useState } from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { GuardModuleType } from '../Guard/module'
4
- import { IconFont } from '../IconFont'
5
- import { MFAEmail } from './core/email'
6
- import { MFASms } from './core/sms'
7
- import { MFAFace } from './core/face'
8
- import { MFATotp } from './core/totp'
9
- import { MFAMethods } from './mfaMethods'
10
- import { GuardMFAViewProps, MFAType } from './props'
11
- import { useAuthClient } from '../Guard/authClient'
12
- import { codeMap } from './codemap'
13
- import './styles.less'
14
- import { message } from 'antd'
15
- const window: Window = require('global/window')
16
-
17
- const ComponentsMapping: Record<MFAType, (props: any) => React.ReactNode> = {
18
- [MFAType.EMAIL]: ({ config, initData, mfaLogin }) => (
19
- <MFAEmail
20
- config={config}
21
- mfaToken={initData.mfaToken}
22
- email={initData.email}
23
- mfaLogin={mfaLogin}
24
- />
25
- ),
26
- [MFAType.SMS]: ({ config, initData, mfaLogin }) => (
27
- <MFASms
28
- config={config}
29
- mfaToken={initData.mfaToken}
30
- phone={initData.phone}
31
- mfaLogin={mfaLogin}
32
- />
33
- ),
34
- [MFAType.TOTP]: ({ initData, config, changeModule, mfaLogin }) => (
35
- <MFATotp
36
- changeModule={changeModule}
37
- config={config}
38
- initData={initData}
39
- mfaLogin={mfaLogin}
40
- />
41
- ),
42
- [MFAType.FACE]: ({ config, initData, mfaLogin, setShowMethods }) => (
43
- <MFAFace
44
- config={config}
45
- initData={initData}
46
- mfaLogin={mfaLogin}
47
- setShowMethods={setShowMethods}
48
- />
49
- ),
50
- }
51
-
52
- export const GuardMFAView: React.FC<GuardMFAViewProps> = ({
53
- initData,
54
- config,
55
- __changeModule,
56
- onLogin,
57
- }) => {
58
- const [currentMethod, setCurrentMethod] = useState(
59
- initData.current ??
60
- initData.applicationMfa?.sort((a, b) => a.sort - b.sort)[0].mfaPolicy
61
- )
62
- const [showMethods, setShowMethods] = useState(true)
63
- const client = useAuthClient()
64
- const { t } = useTranslation()
65
-
66
- const onBack = () => window.history.back()
67
-
68
- const __codePaser = (code: number) => {
69
- const action = codeMap[code]
70
- if (code === 200) {
71
- return (data: any) => {
72
- onLogin?.(data, client) // 登录成功
73
- }
74
- }
75
-
76
- if (!action) {
77
- return () => {
78
- console.error('not catch code', code)
79
- // props.onLoginError?.(data, client) // 未捕获 code
80
- }
81
- }
82
-
83
- // 解析成功
84
- if (action?.action === 'changeModule') {
85
- let m = action.module ? action.module : GuardModuleType.ERROR
86
- return (initData?: any) => __changeModule?.(m, initData)
87
- }
88
- if (action?.action === 'insideFix') {
89
- return () => {}
90
- }
91
-
92
- if (action?.action === 'message') {
93
- return (data: any) => {
94
- message.error(data.message)
95
- }
96
- }
97
-
98
- // 最终结果
99
- return () => {
100
- // props.onLoginError?.(data, client!) // 未捕获 code
101
- console.error('last action at mfaview')
102
- }
103
- }
104
-
105
- const mfaLogin = (code: any, data: any, message?: string) => {
106
- const callback = __codePaser?.(code)
107
-
108
- if (!data) {
109
- data = {}
110
- }
111
- data.__message = message
112
- callback?.(data)
113
- }
114
-
115
- return (
116
- <div className="g2-view-container">
117
- <div className="g2-view-back">
118
- <span onClick={onBack}>
119
- <IconFont type="authing-back" />
120
- <span>{t('common.backLoginPage')}</span>
121
- </span>
122
- </div>
123
- <div className="g2-mfa-content">
124
- {ComponentsMapping[currentMethod]({
125
- config: config,
126
- initData: initData,
127
- changeModule: __changeModule,
128
- mfaLogin: mfaLogin,
129
- setShowMethods: setShowMethods,
130
- })}
131
- </div>
132
- {showMethods && (
133
- <MFAMethods
134
- applicationMfa={initData.applicationMfa}
135
- method={currentMethod}
136
- onChangeMethod={(type) => {
137
- setCurrentMethod(type)
138
- }}
139
- />
140
- )}
141
- </div>
142
- )
143
- }
@@ -1,88 +0,0 @@
1
- import React, { useMemo, useState } from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { Button } from 'antd'
4
- import { IconFont } from '../../IconFont'
5
- import { GuardMFAInitData, MFAType } from '../props'
6
- import { i18n } from '../../_utils/locales'
7
- import './style.less'
8
-
9
- export interface MFAMethodsProps {
10
- applicationMfa: GuardMFAInitData['applicationMfa']
11
- method: MFAType
12
- onChangeMethod: (type: MFAType) => void
13
- }
14
-
15
- const methodTitleMapping: Record<
16
- MFAType,
17
- {
18
- title: () => string
19
- icon: string
20
- }
21
- > = {
22
- [MFAType.EMAIL]: {
23
- title: () => i18n.t('common.EmailVerification'),
24
- icon: 'authing-mail',
25
- },
26
- [MFAType.SMS]: {
27
- title: () => i18n.t('common.SMS'),
28
- icon: 'authing-phone',
29
- },
30
- [MFAType.TOTP]: {
31
- title: () => i18n.t('common.OTPVerification'),
32
- icon: 'authing-totp',
33
- },
34
- [MFAType.FACE]: {
35
- title: () => i18n.t('common.faceVerification'),
36
- icon: 'authing-face',
37
- },
38
- }
39
-
40
- export const MFAMethods: React.FC<MFAMethodsProps> = ({
41
- applicationMfa = [],
42
- method,
43
- onChangeMethod,
44
- }) => {
45
- const [currentMethod, setCurrentMethod] = useState(method)
46
- const { t } = useTranslation()
47
-
48
- const otherMethods = useMemo(
49
- () =>
50
- applicationMfa
51
- .filter((item) => item.mfaPolicy !== currentMethod)
52
- .sort((a, b) => a.sort - b.sort)
53
- .map((item) => (
54
- <Button
55
- className="g2-guard-mfa-methods-btn"
56
- onClick={(e) => {
57
- onChangeMethod(item.mfaPolicy)
58
- setCurrentMethod(item.mfaPolicy)
59
- }}
60
- key={item.mfaPolicy}
61
- >
62
- <IconFont type={methodTitleMapping[item.mfaPolicy].icon} />
63
- {`${methodTitleMapping[item.mfaPolicy].title()}`}
64
- </Button>
65
- )),
66
- [applicationMfa, currentMethod, onChangeMethod]
67
- )
68
-
69
- return (
70
- <>
71
- {otherMethods.length !== 0 && (
72
- <>
73
- <div
74
- style={{
75
- minHeight: 32,
76
- }}
77
- />
78
- <div className="g2-mfa-method">
79
- <div className="g2-mfa-method-title">
80
- {t('login.otherVerifyWay')}
81
- </div>
82
- {otherMethods}
83
- </div>
84
- </>
85
- )}
86
- </>
87
- )
88
- }
@@ -1,39 +0,0 @@
1
- .g2-mfa-method {
2
- padding: 0 38px;
3
- }
4
-
5
- .g2-mfa-method-title {
6
- text-align: center;
7
- font-size: 14px;
8
- color: #c8c9cc;
9
- margin-bottom: 8px;
10
- width: 100%;
11
- }
12
-
13
- .g2-mfa-method-title::before,
14
- .g2-mfa-method-title::after {
15
- content: '——';
16
- color: #eeeeee;
17
- margin: 0 11px;
18
- }
19
-
20
- .g2-guard-mfa-methods-btn {
21
- border: none !important;
22
- background-color: #f5f6f7 !important;
23
- border-radius: 4px !important;
24
- color: #282d3c !important;
25
- font-size: 14px !important;
26
- height: 49px !important;
27
- margin-top: 8px !important;
28
- width: 100%;
29
-
30
- justify-content: center;
31
- align-items: center;
32
-
33
- font-size: 14px;
34
-
35
- .g2-icon {
36
- font-size: 16px;
37
- margin-right: 8px;
38
- }
39
- }
@@ -1,51 +0,0 @@
1
- import { getDefaultG2Config, IG2Config, IG2Events, IG2FCProps } from '../Type'
2
- import { AuthenticationClient, User } from '..'
3
-
4
- export interface MFAConfig extends IG2Config {}
5
-
6
- const defaultConfig: MFAConfig = {
7
- ...getDefaultG2Config(),
8
- }
9
-
10
- export const getDefaultMFAConfig = (): MFAConfig => ({
11
- ...getDefaultG2Config(),
12
- ...defaultConfig,
13
- })
14
-
15
- export interface MFAEvents extends IG2Events {
16
- onLogin?: (user: User, authClient: AuthenticationClient) => void
17
- }
18
-
19
- export enum MFAType {
20
- SMS = 'SMS',
21
- EMAIL = 'EMAIL',
22
- TOTP = 'OTP',
23
- FACE = 'FACE',
24
- }
25
-
26
- export interface GuardMFAInitData {
27
- mfaToken: string
28
- applicationMfa: {
29
- mfaPolicy: MFAType
30
- sort: number
31
- status: 0 | 1
32
- }[]
33
- faceMfaEnabled: boolean
34
- totpMfaEnabled: boolean
35
- email?: string
36
- phone?: string
37
- avatar?: string
38
- nickme?: string
39
- username?: string
40
- current?: MFAType
41
- }
42
-
43
- export interface GuardMFAProps extends IG2FCProps, MFAEvents {
44
- config: Partial<MFAConfig>
45
- initData: GuardMFAInitData
46
- }
47
-
48
- export interface GuardMFAViewProps extends GuardMFAProps {
49
- config: MFAConfig
50
- initData: GuardMFAInitData
51
- }