@authing/react-ui-components 3.0.0-alpha → 3.0.0-rc.11

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 (235) hide show
  1. package/dist/index.min.css +2 -0
  2. package/dist/index.min.js +2 -0
  3. package/dist/index.min.js.LICENSE.txt +71 -0
  4. package/{components/ShieldSpin/loading.svg → dist/static/media/loading.4a67a5f3.svg} +0 -0
  5. package/lib/index.d.ts +2108 -118
  6. package/lib/index.min.css +2 -2
  7. package/lib/index.min.js +1 -1
  8. package/lib/index.min.js.LICENSE.txt +2 -0
  9. package/package.json +32 -10
  10. package/.eslintignore +0 -6
  11. package/.eslintrc.js +0 -7
  12. package/.prettierrc +0 -5
  13. package/.vscode/settings.json +0 -31
  14. package/build/favicon.ico +0 -0
  15. package/build/logo192.png +0 -0
  16. package/build/logo512.png +0 -0
  17. package/build/manifest.json +0 -25
  18. package/build/robots.txt +0 -3
  19. package/components/AuthingDropdown/index.tsx +0 -52
  20. package/components/AuthingDropdown/style.less +0 -43
  21. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  22. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  23. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  24. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  25. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  26. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  27. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  28. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  29. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  30. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  31. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  32. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  33. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  34. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  35. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  36. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  37. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  38. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  39. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  40. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  41. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  42. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  43. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  44. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  45. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  46. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  47. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  48. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  49. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  50. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  51. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  52. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  53. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  54. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  55. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  56. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  57. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  58. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  59. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  60. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  61. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  62. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  63. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  64. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  65. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  66. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  67. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  68. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  69. package/components/AuthingGuard/Forms/index.ts +0 -13
  70. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  71. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  72. package/components/AuthingGuard/Header/index.tsx +0 -25
  73. package/components/AuthingGuard/Header/style.less +0 -52
  74. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  75. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  76. package/components/AuthingGuard/IconFont/style.less +0 -6
  77. package/components/AuthingGuard/IconFont/svg.js +0 -2
  78. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  79. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  80. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  81. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  82. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  83. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  84. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  85. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  86. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  87. package/components/AuthingGuard/api/appConfig.ts +0 -146
  88. package/components/AuthingGuard/api/index.ts +0 -3
  89. package/components/AuthingGuard/api/sso.ts +0 -29
  90. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  91. package/components/AuthingGuard/constants.ts +0 -105
  92. package/components/AuthingGuard/hooks/index.tsx +0 -70
  93. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  94. package/components/AuthingGuard/index.tsx +0 -126
  95. package/components/AuthingGuard/style.less +0 -103
  96. package/components/AuthingGuard/types/Forms.ts +0 -94
  97. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  98. package/components/AuthingGuard/types/GuardState.ts +0 -7
  99. package/components/AuthingGuard/types/Locales.ts +0 -12
  100. package/components/AuthingGuard/types/index.ts +0 -4
  101. package/components/AuthingTabs/index.tsx +0 -98
  102. package/components/AuthingTabs/style.less +0 -135
  103. package/components/BindTotp/core/bindSuccess.tsx +0 -61
  104. package/components/BindTotp/core/securityCode.tsx +0 -119
  105. package/components/BindTotp/index.tsx +0 -134
  106. package/components/BindTotp/props.ts +0 -30
  107. package/components/BindTotp/styles.less +0 -56
  108. package/components/ChangeLanguage/index.tsx +0 -35
  109. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  110. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  111. package/components/ChangePassword/index.tsx +0 -59
  112. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  113. package/components/CompleteInfo/index.tsx +0 -45
  114. package/components/CompleteInfo/props.ts +0 -40
  115. package/components/CompleteInfo/styles.less +0 -7
  116. package/components/CompleteUserInfo/index.tsx +0 -49
  117. package/components/CompleteUserInfo/props.ts +0 -25
  118. package/components/ComponentsRender/index.back +0 -64
  119. package/components/CopyAbleText/index.tsx +0 -54
  120. package/components/CopyAbleText/style.less +0 -13
  121. package/components/DownloadAuthenticator/index.tsx +0 -97
  122. package/components/DownloadAuthenticator/props.ts +0 -22
  123. package/components/DownloadAuthenticator/styles.less +0 -52
  124. package/components/ForgetPassword/core/resetPassword.tsx +0 -150
  125. package/components/ForgetPassword/index.tsx +0 -51
  126. package/components/Guard/Guard.tsx +0 -226
  127. package/components/Guard/authClient.ts +0 -55
  128. package/components/Guard/config.ts +0 -19
  129. package/components/Guard/event.ts +0 -18
  130. package/components/Guard/index.tsx +0 -10
  131. package/components/Guard/module.ts +0 -19
  132. package/components/Guard/stateMachine.ts +0 -133
  133. package/components/Guard/styles.less +0 -444
  134. package/components/IconFont/iconfont.js +0 -74
  135. package/components/IconFont/index.tsx +0 -16
  136. package/components/IconFont/style.less +0 -6
  137. package/components/IconFont/svg.js +0 -2
  138. package/components/ImagePro/index.tsx +0 -52
  139. package/components/ImagePro/styles.less +0 -40
  140. package/components/Login/codemap.ts +0 -35
  141. package/components/Login/core/withAD.tsx +0 -9
  142. package/components/Login/core/withAppQrcode.tsx +0 -49
  143. package/components/Login/core/withLDAP.tsx +0 -145
  144. package/components/Login/core/withPassword.tsx +0 -176
  145. package/components/Login/core/withPhonecode.tsx +0 -135
  146. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  147. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  148. package/components/Login/index.tsx +0 -359
  149. package/components/Login/props.ts +0 -90
  150. package/components/Login/socialLogin/index.tsx +0 -413
  151. package/components/Login/socialLogin/style.less +0 -61
  152. package/components/Login/styles.less +0 -53
  153. package/components/MFA/codemap.ts +0 -21
  154. package/components/MFA/core/email.tsx +0 -226
  155. package/components/MFA/core/face.tsx +0 -297
  156. package/components/MFA/core/face_deps.tsx +0 -37
  157. package/components/MFA/core/sms.tsx +0 -222
  158. package/components/MFA/core/totp.tsx +0 -137
  159. package/components/MFA/index.tsx +0 -135
  160. package/components/MFA/mfaMethods/index.tsx +0 -81
  161. package/components/MFA/mfaMethods/style.less +0 -39
  162. package/components/MFA/props.ts +0 -51
  163. package/components/MFA/styles.less +0 -92
  164. package/components/NeedHelpView/core/describeQuestions.tsx +0 -227
  165. package/components/NeedHelpView/index.tsx +0 -99
  166. package/components/RecoveryCode/core/useCode.tsx +0 -71
  167. package/components/RecoveryCode/index.tsx +0 -27
  168. package/components/RecoveryCode/interface.ts +0 -31
  169. package/components/RecoveryCode/style.less +0 -13
  170. package/components/Register/codemap.ts +0 -16
  171. package/components/Register/components/Agreements/index.tsx +0 -81
  172. package/components/Register/components/Agreements/style.less +0 -44
  173. package/components/Register/core/WithEmail.tsx +0 -250
  174. package/components/Register/core/WithPhone.tsx +0 -190
  175. package/components/Register/index.tsx +0 -122
  176. package/components/Register/props.ts +0 -50
  177. package/components/SendCode/SendCodeBtn.tsx +0 -96
  178. package/components/SendCode/index.tsx +0 -98
  179. package/components/SendCode/style.less +0 -31
  180. package/components/ShieldSpin/index.tsx +0 -27
  181. package/components/SubmitButton/index.tsx +0 -50
  182. package/components/Type/index.ts +0 -61
  183. package/components/VerifyCodeInput/index.tsx +0 -76
  184. package/components/VerifyCodeInput/style.less +0 -24
  185. package/components/_utils/GuardErrorCode.ts +0 -8
  186. package/components/_utils/clipboard.ts +0 -27
  187. package/components/_utils/config.ts +0 -123
  188. package/components/_utils/guradHttp.ts +0 -93
  189. package/components/_utils/hooks/index.ts +0 -56
  190. package/components/_utils/http.ts +0 -85
  191. package/components/_utils/index.ts +0 -310
  192. package/components/_utils/locales/en/common.json +0 -218
  193. package/components/_utils/locales/en/index.ts +0 -6
  194. package/components/_utils/locales/en/login.json +0 -95
  195. package/components/_utils/locales/en/map.json +0 -4
  196. package/components/_utils/locales/en/user.json +0 -82
  197. package/components/_utils/locales/index.ts +0 -45
  198. package/components/_utils/locales/zh/common.json +0 -218
  199. package/components/_utils/locales/zh/index.ts +0 -6
  200. package/components/_utils/locales/zh/login.json +0 -95
  201. package/components/_utils/locales/zh/map.json +0 -4
  202. package/components/_utils/locales/zh/user.json +0 -82
  203. package/components/_utils/popupCenter.ts +0 -48
  204. package/components/context/base.tsx +0 -28
  205. package/components/context/global/context.tsx +0 -39
  206. package/components/context/global/reducer.tsx +0 -56
  207. package/components/context/module/context.tsx +0 -23
  208. package/components/index.ts +0 -10
  209. package/config/antdReplacer.js +0 -51
  210. package/config/env.js +0 -104
  211. package/config/getHttpsConfig.js +0 -66
  212. package/config/jest/cssTransform.js +0 -14
  213. package/config/jest/fileTransform.js +0 -40
  214. package/config/modules.js +0 -134
  215. package/config/paths.js +0 -71
  216. package/config/pnpTs.js +0 -35
  217. package/config/webpack.config.js +0 -835
  218. package/config/webpackDevServer.config.js +0 -130
  219. package/examples.tsx +0 -100
  220. package/index.js +0 -1
  221. package/logo.svg +0 -7
  222. package/public/favicon.ico +0 -0
  223. package/public/index.html +0 -43
  224. package/public/logo192.png +0 -0
  225. package/public/logo512.png +0 -0
  226. package/public/manifest.json +0 -25
  227. package/public/robots.txt +0 -3
  228. package/react-app-env.d.ts +0 -71
  229. package/reportWebVitals.ts +0 -15
  230. package/scripts/build.js +0 -208
  231. package/scripts/lib.js +0 -200
  232. package/scripts/start.js +0 -162
  233. package/scripts/test.js +0 -49
  234. package/setupTests.ts +0 -5
  235. package/tsconfig.json +0 -30
@@ -1,222 +0,0 @@
1
- import { UserOutlined } from '@ant-design/icons'
2
- import { Input, message as Message } from 'antd'
3
- import { Form } from 'antd'
4
- import { 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 { VALIDATE_PATTERN } from '../../_utils'
11
- import SubmitButton from '../../SubmitButton'
12
-
13
- const CODE_LEN = 4
14
-
15
- export interface BindMFASmsProps {
16
- mfaToken: string
17
- onBind: (phone: string) => void
18
- }
19
-
20
- export const BindMFASms: React.FC<BindMFASmsProps> = ({ mfaToken, onBind }) => {
21
- const authClient = useAuthClient()
22
- const submitButtonRef = useRef<any>(null)
23
- const { t } = useTranslation()
24
- const [form] = Form.useForm()
25
- const onFinish = async ({ phone }: any) => {
26
- submitButtonRef.current.onSpin(true)
27
- try {
28
- const bindable = await authClient.mfa.phoneOrEmailBindable({
29
- mfaToken,
30
- phone,
31
- })
32
- if (!bindable) {
33
- Message.error(
34
- t('common.unBindEmaileDoc', {
35
- email: phone,
36
- })
37
- )
38
- return
39
- }
40
-
41
- onBind(phone)
42
- } catch (e) {
43
- // do nothing
44
- } finally {
45
- submitButtonRef.current?.onSpin(false)
46
- }
47
- }
48
-
49
- return (
50
- <>
51
- <h3 className="authing-g2-mfa-title">{t('common.bindPhone')}</h3>
52
- <p className="authing-g2-mfa-tips">{t('login.bindPhoneInfo')}</p>
53
- <Form
54
- form={form}
55
- onFinish={onFinish}
56
- onFinishFailed={() => submitButtonRef.current.onError()}
57
- >
58
- <Form.Item
59
- className="authing-g2-input-form"
60
- name="phone"
61
- rules={[
62
- {
63
- required: true,
64
- message: t('login.inputPhone'),
65
- },
66
- {
67
- pattern: VALIDATE_PATTERN.phone,
68
- message: t('login.phoneError'),
69
- },
70
- ]}
71
- >
72
- <Input
73
- className="authing-g2-input"
74
- autoComplete="tel"
75
- size="large"
76
- placeholder={t('login.inputPhone')}
77
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
78
- />
79
- </Form.Item>
80
- <SubmitButton text={t('common.sure')} ref={submitButtonRef} />
81
- </Form>
82
- </>
83
- )
84
- }
85
-
86
- export interface VerifyMFASmsProps {
87
- mfaToken: string
88
- phone: string
89
- onVerify: (code: number, data: any) => void
90
- sendCodeRef: React.RefObject<HTMLButtonElement>
91
- }
92
-
93
- export const VerifyMFASms: React.FC<VerifyMFASmsProps> = ({
94
- mfaToken,
95
- phone,
96
- onVerify,
97
- sendCodeRef,
98
- }) => {
99
- const authClient = useAuthClient()
100
- const submitButtonRef = useRef<any>(null)
101
- const { t } = useTranslation()
102
- const [form] = Form.useForm()
103
-
104
- const [MfaCode, setMFACode] = useState(new Array(CODE_LEN).fill(''))
105
- const [sending, setSending] = useState(false)
106
- const [sent, setSent] = useState(false)
107
-
108
- const onFinish = async (values: any) => {
109
- submitButtonRef.current.onSpin(true)
110
- try {
111
- const user: User = await authClient.mfa.verifyAppSmsMfa({
112
- mfaToken,
113
- phone: phone!,
114
- code: MfaCode.join(''),
115
- })
116
- // TODO
117
- onVerify(200, user)
118
- } catch (e) {
119
- const error = JSON.parse(e.message)
120
- submitButtonRef.current.onError()
121
- onVerify(error.code as number, error)
122
- } finally {
123
- submitButtonRef.current?.onSpin(false)
124
- }
125
- }
126
-
127
- const sendVerifyCode = async () => {
128
- setSending(true)
129
- try {
130
- await authClient.sendSmsCode(phone!)
131
- setSent(true)
132
- return true
133
- } catch (e) {
134
- return false
135
- } finally {
136
- setSending(false)
137
- }
138
- }
139
-
140
- return (
141
- <>
142
- <h3 className="authing-g2-mfa-title">{t('login.inputPhoneCode')}</h3>
143
- <p className="authing-g2-mfa-tips">
144
- {sending
145
- ? t('login.sendingVerifyCode')
146
- : sent
147
- ? `${t('login.verifyCodeSended')} ${phone}`
148
- : t('login.clickSent')}
149
- </p>
150
- <Form
151
- form={form}
152
- onFinish={onFinish}
153
- onFinishFailed={() => submitButtonRef.current.onError()}
154
- >
155
- <Form.Item
156
- name="mfaCode"
157
- rules={[
158
- {
159
- validateTrigger: [],
160
- validator() {
161
- if (MfaCode.some((item) => !item)) {
162
- return Promise.reject(t('login.inputFullMfaCode'))
163
- }
164
- return Promise.resolve()
165
- },
166
- },
167
- ]}
168
- >
169
- <VerifyCodeInput
170
- length={CODE_LEN}
171
- verifyCode={MfaCode}
172
- setVerifyCode={setMFACode}
173
- />
174
- </Form.Item>
175
-
176
- <SendCodeBtn
177
- btnRef={sendCodeRef}
178
- beforeSend={() => sendVerifyCode()}
179
- type="link"
180
- />
181
-
182
- <SubmitButton
183
- text={t('common.sure')}
184
- ref={submitButtonRef}
185
- className="g2-mfa-submit-button"
186
- />
187
- </Form>
188
- </>
189
- )
190
- }
191
-
192
- export const MFASms: React.FC<{
193
- mfaToken: string
194
- phone?: string
195
- mfaLogin: any
196
- }> = ({ phone: userPhone, mfaToken, mfaLogin }) => {
197
- const [phone, setPhone] = useState(userPhone)
198
- const sendCodeRef = useRef<HTMLButtonElement>(null)
199
-
200
- return (
201
- <>
202
- {phone ? (
203
- <VerifyMFASms
204
- mfaToken={mfaToken}
205
- phone={phone}
206
- onVerify={(code, data) => {
207
- mfaLogin(code, data)
208
- }}
209
- sendCodeRef={sendCodeRef}
210
- />
211
- ) : (
212
- <BindMFASms
213
- mfaToken={mfaToken}
214
- onBind={(phone: string) => {
215
- setPhone(phone)
216
- sendCodeRef.current?.click()
217
- }}
218
- />
219
- )}
220
- </>
221
- )
222
- }
@@ -1,137 +0,0 @@
1
- import { Form } from 'antd'
2
- import React, { useRef, useState } from 'react'
3
- import { useTranslation } from 'react-i18next'
4
- import { useAsyncFn } from 'react-use'
5
- import { VerifyCodeInput } from '../../VerifyCodeInput'
6
- import { GuardModuleType } from '../../Guard/module'
7
- import { useGuardHttp } from '../../_utils/guradHttp'
8
- import { GuardMFAInitData, MFAConfig } from '../props'
9
- import { message as Message } from 'antd'
10
- import SubmitButton from '../../SubmitButton'
11
-
12
- const CODE_LEN = 6
13
-
14
- export interface BindMFATotpProps {
15
- initData: GuardMFAInitData
16
- changeModule: any
17
- }
18
-
19
- export const BindMFATotp: React.FC<BindMFATotpProps> = ({
20
- changeModule,
21
- initData,
22
- }) => {
23
- const { t } = useTranslation()
24
-
25
- const next = () => changeModule(GuardModuleType.BIND_TOTP, initData)
26
- return (
27
- <>
28
- <p className="authing-g2-mfa-title">{t('common.bindTotp')}</p>
29
- <p className="authing-g2-mfa-tips">{t('common.otpText1')}</p>
30
- <SubmitButton
31
- text={t('common.sure')}
32
- onClick={next}
33
- className="g2-mfa-submit-button bind-totp"
34
- />
35
- </>
36
- )
37
- }
38
-
39
- export interface VerifyMFATotpProps {
40
- mfaToken: string
41
- mfaLogin: any
42
- }
43
-
44
- export const VerifyMFATotp: React.FC<VerifyMFATotpProps> = ({
45
- mfaToken,
46
- mfaLogin,
47
- }) => {
48
- const { t } = useTranslation()
49
- const [form] = Form.useForm()
50
-
51
- const submitButtonRef = useRef<any>(null)
52
-
53
- const { post } = useGuardHttp()
54
-
55
- const [MFACode, setMFACode] = useState(new Array(6).fill(''))
56
-
57
- const [, onFinish] = useAsyncFn(async () => {
58
- submitButtonRef.current.onSpin(true)
59
- try {
60
- const { code, data, message } = await post(
61
- '/api/v2/mfa/totp/verify',
62
- {
63
- totp: MFACode.join(''),
64
- },
65
- {
66
- headers: {
67
- authorization: mfaToken,
68
- },
69
- }
70
- )
71
-
72
- if (code !== 200) {
73
- mfaLogin(200, message)
74
- Message.error(message)
75
- } else {
76
- mfaLogin(200, data)
77
- }
78
- } finally {
79
- submitButtonRef.current.onSpin(false)
80
- }
81
- }, [mfaToken, MFACode])
82
-
83
- return (
84
- <>
85
- <p className="authing-g2-mfa-title">{t('login.accPwdLoginVerify')}</p>
86
- <p className="authing-g2-mfa-tips">{t('login.inputSixCode')}</p>
87
- <Form form={form} onSubmitCapture={() => {}} onFinish={onFinish}>
88
- <Form.Item
89
- name="mfaCode"
90
- className="g2-mfa-totp-verify-input"
91
- rules={[
92
- {
93
- validateTrigger: [],
94
- validator(r, v, cb) {
95
- if (MFACode.some((item) => !item)) {
96
- cb(t('login.inputFullMfaCode'))
97
- return
98
- }
99
- cb()
100
- },
101
- },
102
- ]}
103
- >
104
- <VerifyCodeInput
105
- length={CODE_LEN}
106
- verifyCode={MFACode}
107
- setVerifyCode={setMFACode}
108
- />
109
- </Form.Item>
110
- <SubmitButton text={t('common.sure')} ref={submitButtonRef} />
111
- </Form>
112
- </>
113
- )
114
- }
115
-
116
- export interface MFATotpProps {
117
- changeModule: any
118
- config: MFAConfig
119
- initData: GuardMFAInitData
120
- mfaLogin: any
121
- }
122
-
123
- export const MFATotp: React.FC<MFATotpProps> = ({
124
- changeModule,
125
- initData,
126
- mfaLogin,
127
- }) => {
128
- return (
129
- <>
130
- {initData.totpMfaEnabled ? (
131
- <VerifyMFATotp mfaToken={initData.mfaToken} mfaLogin={mfaLogin} />
132
- ) : (
133
- <BindMFATotp initData={initData} changeModule={changeModule} />
134
- )}
135
- </>
136
- )
137
- }
@@ -1,135 +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
- const window: Window = require('global/window')
15
-
16
- const ComponentsMapping: Record<MFAType, (props: any) => React.ReactNode> = {
17
- [MFAType.EMAIL]: ({ initData, mfaLogin }) => (
18
- <MFAEmail
19
- mfaToken={initData.mfaToken}
20
- email={initData.email}
21
- mfaLogin={mfaLogin}
22
- />
23
- ),
24
- [MFAType.SMS]: ({ initData, mfaLogin }) => (
25
- <MFASms
26
- mfaToken={initData.mfaToken}
27
- phone={initData.phone}
28
- mfaLogin={mfaLogin}
29
- />
30
- ),
31
- [MFAType.TOTP]: ({ initData, config, changeModule, mfaLogin }) => (
32
- <MFATotp
33
- changeModule={changeModule}
34
- config={config}
35
- initData={initData}
36
- mfaLogin={mfaLogin}
37
- />
38
- ),
39
- [MFAType.FACE]: ({ config, initData, mfaLogin, setShowMethods }) => (
40
- <MFAFace
41
- config={config}
42
- initData={initData}
43
- mfaLogin={mfaLogin}
44
- setShowMethods={setShowMethods}
45
- />
46
- ),
47
- }
48
-
49
- export const GuardMFAView: React.FC<GuardMFAViewProps> = ({
50
- initData,
51
- config,
52
- __changeModule,
53
- onLogin,
54
- }) => {
55
- const [currentMethod, setCurrentMethod] = useState(
56
- initData.current ??
57
- initData.applicationMfa?.sort((a, b) => a.sort - b.sort)[0].mfaPolicy
58
- )
59
- const [showMethods, setShowMethods] = useState(true)
60
- const client = useAuthClient()
61
- const { t } = useTranslation()
62
-
63
- const onBack = () => window.history.back()
64
-
65
- const __codePaser = (code: number) => {
66
- const action = codeMap[code]
67
- if (code === 200) {
68
- return (data: any) => {
69
- onLogin?.(data, client) // 登录成功
70
- }
71
- }
72
-
73
- if (!action) {
74
- return () => {
75
- console.error('not catch code', code)
76
- // props.onLoginError?.(data, client) // 未捕获 code
77
- }
78
- }
79
-
80
- // 解析成功
81
- if (action?.action === 'changeModule') {
82
- let m = action.module ? action.module : GuardModuleType.ERROR
83
- return (initData?: any) => __changeModule?.(m, initData)
84
- }
85
- if (action?.action === 'insideFix') {
86
- return () => {}
87
- }
88
-
89
- // 最终结果
90
- return () => {
91
- // props.onLoginError?.(data, client!) // 未捕获 code
92
- console.error('last action at mfaview')
93
- }
94
- }
95
-
96
- const mfaLogin = (code: any, data: any, message?: string) => {
97
- const callback = __codePaser?.(code)
98
-
99
- console.log('data', data)
100
- if (!data) {
101
- data = {}
102
- }
103
- data.__message = message
104
- callback?.(data)
105
- }
106
-
107
- return (
108
- <div className="g2-view-container">
109
- <div className="g2-view-back">
110
- <span onClick={onBack}>
111
- <IconFont type="authing-back" />
112
- <span>{t('common.backLoginPage')}</span>
113
- </span>
114
- </div>
115
- <div className="g2-mfa-content">
116
- {ComponentsMapping[currentMethod]({
117
- config: config,
118
- initData: initData,
119
- changeModule: __changeModule,
120
- mfaLogin: mfaLogin,
121
- setShowMethods: setShowMethods,
122
- })}
123
- </div>
124
- {showMethods && (
125
- <MFAMethods
126
- applicationMfa={initData.applicationMfa}
127
- method={currentMethod}
128
- onChangeMethod={(type) => {
129
- setCurrentMethod(type)
130
- }}
131
- />
132
- )}
133
- </div>
134
- )
135
- }
@@ -1,81 +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
- return (
69
- <>
70
- <div
71
- style={{
72
- minHeight: 32,
73
- }}
74
- />
75
- <div className="g2-mfa-method">
76
- <div className="g2-mfa-method-title">{t('login.otherVerifyWay')}</div>
77
- {otherMethods}
78
- </div>
79
- </>
80
- )
81
- }
@@ -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
- }