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