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

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 (232) hide show
  1. package/lib/index.d.ts +781 -110
  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 +34 -12
  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/favicon.ico +0 -0
  11. package/build/logo192.png +0 -0
  12. package/build/logo512.png +0 -0
  13. package/build/manifest.json +0 -25
  14. package/build/robots.txt +0 -3
  15. package/components/AuthingDropdown/index.tsx +0 -52
  16. package/components/AuthingDropdown/style.less +0 -43
  17. package/components/AuthingGuard/AppMFALayout/index.tsx +0 -74
  18. package/components/AuthingGuard/AppMFALayout/style.less +0 -12
  19. package/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +0 -29
  20. package/components/AuthingGuard/CompleteUserInfoLayout/style.less +0 -8
  21. package/components/AuthingGuard/Forms/ADLoginForm/index.tsx +0 -117
  22. package/components/AuthingGuard/Forms/Agreements/index.tsx +0 -81
  23. package/components/AuthingGuard/Forms/Agreements/style.less +0 -44
  24. package/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +0 -139
  25. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +0 -84
  26. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +0 -116
  27. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +0 -40
  28. package/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  29. package/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +0 -181
  30. package/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  31. package/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +0 -166
  32. package/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  33. package/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +0 -76
  34. package/components/AuthingGuard/Forms/LoginFormFooter/style.less +0 -6
  35. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +0 -86
  36. package/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +0 -53
  37. package/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +0 -65
  38. package/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -20
  39. package/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +0 -105
  40. package/components/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -12
  41. package/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +0 -261
  42. package/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +0 -133
  43. package/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +0 -202
  44. package/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +0 -59
  45. package/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -14
  46. package/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +0 -56
  47. package/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  48. package/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +0 -21
  49. package/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +0 -86
  50. package/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +0 -127
  51. package/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +0 -141
  52. package/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +0 -51
  53. package/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +0 -96
  54. package/components/AuthingGuard/Forms/ResetPwdForm/style.less +0 -3
  55. package/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -88
  56. package/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +0 -50
  57. package/components/AuthingGuard/Forms/SendPhoneCode/style.less +0 -26
  58. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +0 -86
  59. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +0 -113
  60. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +0 -40
  61. package/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -3
  62. package/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +0 -325
  63. package/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -75
  64. package/components/AuthingGuard/Forms/UploadImage/index.tsx +0 -70
  65. package/components/AuthingGuard/Forms/index.ts +0 -13
  66. package/components/AuthingGuard/GuardLayout/index.tsx +0 -474
  67. package/components/AuthingGuard/GuardLayout/style.less +0 -111
  68. package/components/AuthingGuard/Header/index.tsx +0 -25
  69. package/components/AuthingGuard/Header/style.less +0 -52
  70. package/components/AuthingGuard/IconFont/iconfont.js +0 -74
  71. package/components/AuthingGuard/IconFont/index.tsx +0 -19
  72. package/components/AuthingGuard/IconFont/style.less +0 -6
  73. package/components/AuthingGuard/IconFont/svg.js +0 -2
  74. package/components/AuthingGuard/LoginLayout/index.tsx +0 -161
  75. package/components/AuthingGuard/LoginLayout/style.less +0 -0
  76. package/components/AuthingGuard/MfaLayout/Steps.ts +0 -4
  77. package/components/AuthingGuard/MfaLayout/index.tsx +0 -49
  78. package/components/AuthingGuard/MfaLayout/style.less +0 -3
  79. package/components/AuthingGuard/RegisterLayout/index.tsx +0 -89
  80. package/components/AuthingGuard/RegisterLayout/style.less +0 -0
  81. package/components/AuthingGuard/ResetPwdLayout/index.tsx +0 -20
  82. package/components/AuthingGuard/ToggleLang/index.tsx +0 -51
  83. package/components/AuthingGuard/api/appConfig.ts +0 -146
  84. package/components/AuthingGuard/api/index.ts +0 -3
  85. package/components/AuthingGuard/api/sso.ts +0 -29
  86. package/components/AuthingGuard/api/userPoolConfig.ts +0 -111
  87. package/components/AuthingGuard/constants.ts +0 -105
  88. package/components/AuthingGuard/hooks/index.tsx +0 -70
  89. package/components/AuthingGuard/hooks/useScreenSize.tsx +0 -68
  90. package/components/AuthingGuard/index.tsx +0 -126
  91. package/components/AuthingGuard/style.less +0 -103
  92. package/components/AuthingGuard/types/Forms.ts +0 -94
  93. package/components/AuthingGuard/types/GuardConfig.ts +0 -420
  94. package/components/AuthingGuard/types/GuardState.ts +0 -7
  95. package/components/AuthingGuard/types/Locales.ts +0 -12
  96. package/components/AuthingGuard/types/index.ts +0 -4
  97. package/components/AuthingTabs/index.tsx +0 -98
  98. package/components/AuthingTabs/style.less +0 -135
  99. package/components/BindTotp/core/bindSuccess.tsx +0 -61
  100. package/components/BindTotp/core/securityCode.tsx +0 -119
  101. package/components/BindTotp/index.tsx +0 -134
  102. package/components/BindTotp/props.ts +0 -30
  103. package/components/BindTotp/styles.less +0 -56
  104. package/components/ChangeLanguage/index.tsx +0 -35
  105. package/components/ChangePassword/core/firstLoginReset.tsx +0 -104
  106. package/components/ChangePassword/core/rotateReset.tsx +0 -114
  107. package/components/ChangePassword/index.tsx +0 -59
  108. package/components/CompleteInfo/core/completeInfo.tsx +0 -155
  109. package/components/CompleteInfo/index.tsx +0 -45
  110. package/components/CompleteInfo/props.ts +0 -40
  111. package/components/CompleteInfo/styles.less +0 -7
  112. package/components/CompleteUserInfo/index.tsx +0 -49
  113. package/components/CompleteUserInfo/props.ts +0 -25
  114. package/components/ComponentsRender/index.back +0 -64
  115. package/components/CopyAbleText/index.tsx +0 -54
  116. package/components/CopyAbleText/style.less +0 -13
  117. package/components/DownloadAuthenticator/index.tsx +0 -97
  118. package/components/DownloadAuthenticator/props.ts +0 -22
  119. package/components/DownloadAuthenticator/styles.less +0 -52
  120. package/components/ForgetPassword/core/resetPassword.tsx +0 -150
  121. package/components/ForgetPassword/index.tsx +0 -51
  122. package/components/Guard/Guard.tsx +0 -226
  123. package/components/Guard/authClient.ts +0 -55
  124. package/components/Guard/config.ts +0 -19
  125. package/components/Guard/event.ts +0 -18
  126. package/components/Guard/index.tsx +0 -10
  127. package/components/Guard/module.ts +0 -19
  128. package/components/Guard/stateMachine.ts +0 -133
  129. package/components/Guard/styles.less +0 -444
  130. package/components/IconFont/iconfont.js +0 -74
  131. package/components/IconFont/index.tsx +0 -16
  132. package/components/IconFont/style.less +0 -6
  133. package/components/IconFont/svg.js +0 -2
  134. package/components/ImagePro/index.tsx +0 -52
  135. package/components/ImagePro/styles.less +0 -40
  136. package/components/Login/codemap.ts +0 -35
  137. package/components/Login/core/withAD.tsx +0 -9
  138. package/components/Login/core/withAppQrcode.tsx +0 -49
  139. package/components/Login/core/withLDAP.tsx +0 -145
  140. package/components/Login/core/withPassword.tsx +0 -176
  141. package/components/Login/core/withPhonecode.tsx +0 -135
  142. package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
  143. package/components/Login/core/withWechatmpQrcode.tsx +0 -53
  144. package/components/Login/index.tsx +0 -359
  145. package/components/Login/props.ts +0 -90
  146. package/components/Login/socialLogin/index.tsx +0 -413
  147. package/components/Login/socialLogin/style.less +0 -61
  148. package/components/Login/styles.less +0 -53
  149. package/components/MFA/codemap.ts +0 -21
  150. package/components/MFA/core/email.tsx +0 -226
  151. package/components/MFA/core/face.tsx +0 -297
  152. package/components/MFA/core/face_deps.tsx +0 -37
  153. package/components/MFA/core/sms.tsx +0 -222
  154. package/components/MFA/core/totp.tsx +0 -137
  155. package/components/MFA/index.tsx +0 -135
  156. package/components/MFA/mfaMethods/index.tsx +0 -81
  157. package/components/MFA/mfaMethods/style.less +0 -39
  158. package/components/MFA/props.ts +0 -51
  159. package/components/MFA/styles.less +0 -92
  160. package/components/NeedHelpView/core/describeQuestions.tsx +0 -227
  161. package/components/NeedHelpView/index.tsx +0 -99
  162. package/components/RecoveryCode/core/useCode.tsx +0 -71
  163. package/components/RecoveryCode/index.tsx +0 -27
  164. package/components/RecoveryCode/interface.ts +0 -31
  165. package/components/RecoveryCode/style.less +0 -13
  166. package/components/Register/codemap.ts +0 -16
  167. package/components/Register/components/Agreements/index.tsx +0 -81
  168. package/components/Register/components/Agreements/style.less +0 -44
  169. package/components/Register/core/WithEmail.tsx +0 -250
  170. package/components/Register/core/WithPhone.tsx +0 -190
  171. package/components/Register/index.tsx +0 -122
  172. package/components/Register/props.ts +0 -50
  173. package/components/SendCode/SendCodeBtn.tsx +0 -96
  174. package/components/SendCode/index.tsx +0 -98
  175. package/components/SendCode/style.less +0 -31
  176. package/components/ShieldSpin/index.tsx +0 -27
  177. package/components/ShieldSpin/loading.svg +0 -29
  178. package/components/SubmitButton/index.tsx +0 -50
  179. package/components/Type/index.ts +0 -61
  180. package/components/VerifyCodeInput/index.tsx +0 -76
  181. package/components/VerifyCodeInput/style.less +0 -24
  182. package/components/_utils/GuardErrorCode.ts +0 -8
  183. package/components/_utils/clipboard.ts +0 -27
  184. package/components/_utils/config.ts +0 -123
  185. package/components/_utils/guradHttp.ts +0 -93
  186. package/components/_utils/hooks/index.ts +0 -56
  187. package/components/_utils/http.ts +0 -85
  188. package/components/_utils/index.ts +0 -310
  189. package/components/_utils/locales/en/common.json +0 -218
  190. package/components/_utils/locales/en/index.ts +0 -6
  191. package/components/_utils/locales/en/login.json +0 -95
  192. package/components/_utils/locales/en/map.json +0 -4
  193. package/components/_utils/locales/en/user.json +0 -82
  194. package/components/_utils/locales/index.ts +0 -45
  195. package/components/_utils/locales/zh/common.json +0 -218
  196. package/components/_utils/locales/zh/index.ts +0 -6
  197. package/components/_utils/locales/zh/login.json +0 -95
  198. package/components/_utils/locales/zh/map.json +0 -4
  199. package/components/_utils/locales/zh/user.json +0 -82
  200. package/components/_utils/popupCenter.ts +0 -48
  201. package/components/context/base.tsx +0 -28
  202. package/components/context/global/context.tsx +0 -39
  203. package/components/context/global/reducer.tsx +0 -56
  204. package/components/context/module/context.tsx +0 -23
  205. package/components/index.ts +0 -10
  206. package/config/antdReplacer.js +0 -51
  207. package/config/env.js +0 -104
  208. package/config/getHttpsConfig.js +0 -66
  209. package/config/jest/cssTransform.js +0 -14
  210. package/config/jest/fileTransform.js +0 -40
  211. package/config/modules.js +0 -134
  212. package/config/paths.js +0 -71
  213. package/config/pnpTs.js +0 -35
  214. package/config/webpack.config.js +0 -835
  215. package/config/webpackDevServer.config.js +0 -130
  216. package/examples.tsx +0 -100
  217. package/index.js +0 -1
  218. package/logo.svg +0 -7
  219. package/public/favicon.ico +0 -0
  220. package/public/index.html +0 -43
  221. package/public/logo192.png +0 -0
  222. package/public/logo512.png +0 -0
  223. package/public/manifest.json +0 -25
  224. package/public/robots.txt +0 -3
  225. package/react-app-env.d.ts +0 -71
  226. package/reportWebVitals.ts +0 -15
  227. package/scripts/build.js +0 -208
  228. package/scripts/lib.js +0 -200
  229. package/scripts/start.js +0 -162
  230. package/scripts/test.js +0 -49
  231. package/setupTests.ts +0 -5
  232. package/tsconfig.json +0 -30
@@ -1,261 +0,0 @@
1
- import { Input, Form, Alert, message as Message, message } from 'antd'
2
- import { FormInstance, Rule } from 'antd/lib/form'
3
- import { UserOutlined, LockOutlined } from '@ant-design/icons'
4
- import React, {
5
- forwardRef,
6
- useImperativeHandle,
7
- useMemo,
8
- useState,
9
- } from 'react'
10
-
11
- import { getRequiredRules, getUserRegisterParams } from '../../../_utils'
12
- import { useGuardContext } from '../../../context/global/context'
13
- import { NEED_CAPTCHA } from '../../../../components/AuthingGuard/constants'
14
- import {
15
- LoginMethods,
16
- PasswordLoginFormProps,
17
- User,
18
- } from '../../../../components/AuthingGuard/types'
19
- import { LoginFormFooter } from '../../../../components/AuthingGuard/Forms/LoginFormFooter'
20
- import { useTranslation } from 'react-i18next'
21
- import { PasswordLoginMethods } from '../../api'
22
- import { requestClient } from '../../../_utils/http'
23
-
24
- export const PasswordLoginForm = forwardRef<
25
- FormInstance,
26
- PasswordLoginFormProps
27
- >(({ onSuccess, onValidateFail, onFail }, ref) => {
28
- const { state, getValue } = useGuardContext()
29
- const { t } = useTranslation()
30
-
31
- const { config, authClient, realHost, userPoolId, appId, guardEvents } = state
32
- const autoRegister = config.autoRegister
33
-
34
- const captchaUrl = `${realHost}/api/v2/security/captcha`
35
- const getCaptchaUrl = () => `${captchaUrl}?r=${+new Date()}`
36
-
37
- const [rawForm] = Form.useForm()
38
-
39
- const [needCaptcha, setNeedCaptcha] = useState(false)
40
- const [verifyCodeUrl, setVerifyCodeUrl] = useState<string | null>(null)
41
- const [loading, setLoading] = useState(false)
42
-
43
- const onFinishFailed = (errorInfo: any) => {
44
- setLoading(false)
45
- onValidateFail && onValidateFail(errorInfo)
46
- }
47
-
48
- const loginMethodsText = useMemo<
49
- Record<
50
- PasswordLoginMethods,
51
- {
52
- t: string
53
- sort: number
54
- }
55
- >
56
- >(
57
- () => ({
58
- 'email-password': {
59
- t: t('common.email'),
60
- sort: 2,
61
- },
62
- 'phone-password': {
63
- t: t('common.phoneNumber'),
64
- sort: 1,
65
- },
66
- 'username-password': {
67
- t: t('common.username'),
68
- sort: 0,
69
- },
70
- }),
71
- [t]
72
- )
73
-
74
- const usernamePlaceholder = useMemo(
75
- () =>
76
- t('login.inputAccount', {
77
- text: config.passwordLoginMethods
78
- ?.map((item) => loginMethodsText[item])
79
- .sort((a, b) => a.sort - b.sort)
80
- .map((item) => item.t)
81
- .join(' / '),
82
- }),
83
- [config.passwordLoginMethods, loginMethodsText, t]
84
- )
85
-
86
- const identityRules = useMemo(() => {
87
- const rules: Rule[] = getRequiredRules(t('common.accNotNull'))
88
-
89
- const loginMethods = config.passwordLoginMethods
90
-
91
- if (
92
- loginMethods?.includes('email-password') &&
93
- loginMethods?.length === 1
94
- ) {
95
- rules.push({
96
- type: 'email',
97
- message: t('common.emailFormatError'),
98
- })
99
- }
100
-
101
- return rules
102
- }, [config, t])
103
-
104
- const login = async (values: any) => {
105
- const identity = values.identity && values.identity.trim()
106
- const password = values.password && values.password.trim()
107
- const captchaCode = values.captchaCode && values.captchaCode.trim()
108
-
109
- const encrypt = authClient.options.encryptFunction
110
-
111
- const { publicKey, autoRegister } = getValue('config')
112
- const { code, data, message } = await requestClient.post<User>(
113
- '/api/v2/login/account',
114
- {
115
- account: identity,
116
- password: await encrypt!(password, publicKey),
117
- captchaCode,
118
- customData: getUserRegisterParams(),
119
- autoRegister: autoRegister,
120
- },
121
- {
122
- headers: {
123
- 'x-authing-userpool-id': userPoolId,
124
- 'x-authing-app-id': appId,
125
- },
126
- }
127
- )
128
-
129
- if (code === 200) {
130
- return data
131
- } else {
132
- Message.error(message)
133
- // eslint-disable-next-line no-throw-literal
134
- throw {
135
- code,
136
- message,
137
- data,
138
- }
139
- }
140
- }
141
-
142
- const onFinish = async (values: any) => {
143
- if (guardEvents.onBeforeLogin) {
144
- try {
145
- const canLogin = await guardEvents.onBeforeLogin(
146
- {
147
- type: LoginMethods.Password,
148
- data: {
149
- identity: values.identity,
150
- password: values.password,
151
- captchaCode: values.captchaCode,
152
- },
153
- },
154
- authClient
155
- )
156
-
157
- if (!canLogin) {
158
- setLoading(false)
159
- return
160
- }
161
- } catch (e) {
162
- if (typeof e === 'string') {
163
- message.error(e)
164
- } else {
165
- message.error(e.message)
166
- }
167
- setLoading(false)
168
- return
169
- }
170
- }
171
-
172
- try {
173
- let user: User | undefined
174
- user = await login(values)
175
- user && onSuccess && onSuccess(user)
176
- } catch (error) {
177
- if (error.code === NEED_CAPTCHA && verifyCodeUrl === null) {
178
- setNeedCaptcha(true)
179
- setVerifyCodeUrl(getCaptchaUrl())
180
- }
181
-
182
- onFail && onFail(error)
183
- } finally {
184
- setLoading(false)
185
- }
186
- }
187
-
188
- useImperativeHandle(ref, () => rawForm)
189
-
190
- const formItems = [
191
- {
192
- component: (
193
- <Input
194
- autoComplete="email,username,tel"
195
- size="large"
196
- placeholder={usernamePlaceholder}
197
- prefix={<UserOutlined style={{ color: '#ddd' }} />}
198
- />
199
- ),
200
- name: 'identity',
201
- rules: identityRules,
202
- },
203
- {
204
- component: (
205
- <Input.Password
206
- size="large"
207
- placeholder={t('login.inputLoginPwd')}
208
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
209
- />
210
- ),
211
- name: 'password',
212
- rules: getRequiredRules(t('common.passwordNotNull')),
213
- },
214
- {
215
- component: (
216
- <Input
217
- size="large"
218
- placeholder={t('login.inputCaptchaCode')}
219
- addonAfter={
220
- <img
221
- src={verifyCodeUrl ?? ''}
222
- alt={t('login.captchaCode')}
223
- style={{ height: '2em', cursor: 'pointer' }}
224
- onClick={() => setVerifyCodeUrl(getCaptchaUrl())}
225
- />
226
- }
227
- />
228
- ),
229
- name: 'captchaCode',
230
- rules: getRequiredRules(t('common.captchaCodeNotNull')),
231
- hide: !needCaptcha,
232
- },
233
- ]
234
-
235
- return (
236
- <Form
237
- form={rawForm}
238
- onSubmitCapture={() => setLoading(true)}
239
- onFinishFailed={onFinishFailed}
240
- onFinish={onFinish}
241
- >
242
- {autoRegister && (
243
- <Alert message={t('login.autoRegister')} style={{ marginBottom: 24 }} />
244
- )}
245
- {formItems.map(
246
- (item) =>
247
- !item.hide && (
248
- <Form.Item key={item.name} name={item.name} rules={item.rules}>
249
- {item.component}
250
- </Form.Item>
251
- )
252
- )}
253
-
254
- <LoginFormFooter
255
- needRegister
256
- needRestPwd
257
- loading={loading}
258
- ></LoginFormFooter>
259
- </Form>
260
- )
261
- })
@@ -1,133 +0,0 @@
1
- import React, { forwardRef, useImperativeHandle, useState } from 'react'
2
- import { FormInstance, Rule } from 'antd/lib/form'
3
- import { Alert, Form, Input, message } from 'antd'
4
- import { UserOutlined, SafetyOutlined } from '@ant-design/icons'
5
-
6
- import {
7
- getRequiredRules,
8
- getUserRegisterParams,
9
- VALIDATE_PATTERN,
10
- } from '../../../_utils'
11
- import { useGuardContext } from '../../../context/global/context'
12
- import {
13
- LoginMethods,
14
- PhoneCodeLoginFormProps,
15
- } from '../../../../components/AuthingGuard/types'
16
- import { SendPhoneCode } from '../../../../components/AuthingGuard/Forms/SendPhoneCode'
17
- import { LoginFormFooter } from '../../../../components/AuthingGuard/Forms/LoginFormFooter'
18
- import { useTranslation } from 'react-i18next'
19
-
20
- export const PhoneCodeLoginForm = forwardRef<
21
- FormInstance,
22
- PhoneCodeLoginFormProps
23
- >(({ onSuccess, onFail, onValidateFail }, ref) => {
24
- const {
25
- state: { authClient, config, guardEvents },
26
- } = useGuardContext()
27
- const { t } = useTranslation()
28
-
29
- const rulesMap: Record<string, Rule[]> = {
30
- phone: getRequiredRules(t('login.inputPhone')).concat({
31
- pattern: VALIDATE_PATTERN.phone,
32
- message: t('common.phoneFormateError'),
33
- }),
34
- code: getRequiredRules(t('common.inputVerifyCode')),
35
- }
36
-
37
- const [rawForm] = Form.useForm()
38
-
39
- const [phone, setPhone] = useState('')
40
- const [loading, setLoading] = useState(false)
41
-
42
- const onFinishFailed = (errorInfo: any) => {
43
- setLoading(false)
44
- onValidateFail && onValidateFail(errorInfo)
45
- }
46
-
47
- const onFinish = async (values: any) => {
48
- if (guardEvents.onBeforeLogin) {
49
- try {
50
- const canLogin = await guardEvents.onBeforeLogin(
51
- {
52
- type: LoginMethods.PhoneCode,
53
- data: {
54
- phone: values.phone,
55
- code: values.code,
56
- },
57
- },
58
- authClient
59
- )
60
-
61
- if (!canLogin) {
62
- setLoading(false)
63
- return
64
- }
65
- } catch (e) {
66
- if (typeof e === 'string') {
67
- message.error(e)
68
- } else {
69
- message.error(e.message)
70
- }
71
- setLoading(false)
72
- return
73
- }
74
- }
75
-
76
- try {
77
- const { phone, code } = values
78
- const user = await authClient.loginByPhoneCode(phone, code, {
79
- params: getUserRegisterParams(),
80
- })
81
- onSuccess && onSuccess(user)
82
- } catch (error) {
83
- onFail && onFail(error)
84
- } finally {
85
- setLoading(false)
86
- }
87
- }
88
-
89
- useImperativeHandle(ref, () => rawForm)
90
-
91
- return (
92
- <Form
93
- form={rawForm}
94
- onSubmitCapture={() => setLoading(true)}
95
- onFinishFailed={onFinishFailed}
96
- onFinish={onFinish}
97
- >
98
- {config.autoRegister && (
99
- <Alert
100
- message={t('login.phoneAutoRegister')}
101
- style={{ marginBottom: 24 }}
102
- />
103
- )}
104
- <Form.Item name="phone" rules={rulesMap.phone}>
105
- <Input
106
- autoComplete="tel"
107
- onChange={(e) => {
108
- setPhone(e.target.value)
109
- }}
110
- size="large"
111
- placeholder={t('login.inputPhone')}
112
- prefix={<UserOutlined style={{ color: '#ddd' }} />}
113
- />
114
- </Form.Item>
115
- <Form.Item name="code" rules={rulesMap.code}>
116
- <Input
117
- size="large"
118
- placeholder={t('common.inputFourVerifyCode', {
119
- length: 4,
120
- })}
121
- prefix={<SafetyOutlined style={{ color: '#ddd' }} />}
122
- suffix={<SendPhoneCode phone={phone} />}
123
- />
124
- </Form.Item>
125
-
126
- <LoginFormFooter
127
- needRestPwd
128
- needRegister
129
- loading={loading}
130
- ></LoginFormFooter>
131
- </Form>
132
- )
133
- })
@@ -1,202 +0,0 @@
1
- import { Input, Form, message } from 'antd'
2
- import { FormInstance } from 'antd/lib/form'
3
- import React, { forwardRef, useImperativeHandle, useState } from 'react'
4
- import { UserOutlined, LockOutlined, SafetyOutlined } from '@ant-design/icons'
5
-
6
- import { useGuardContext } from '../../../context/global/context'
7
- import {
8
- PhoneRegisterFormProps,
9
- RegisterMethods,
10
- } from '../../../../components/AuthingGuard/types'
11
- import {
12
- getDeviceName,
13
- getRequiredRules,
14
- getUserRegisterParams,
15
- VALIDATE_PATTERN,
16
- } from '../../../_utils'
17
- import { SendPhoneCode } from '../../../../components/AuthingGuard/Forms/SendPhoneCode'
18
- import { RegisterFormFooter } from '../../../../components/AuthingGuard/Forms/RegisterFormFooter'
19
- import { useTranslation } from 'react-i18next'
20
- import { Agreements } from '../Agreements'
21
-
22
- export const PhoneRegisterForm = forwardRef<
23
- FormInstance,
24
- PhoneRegisterFormProps
25
- >(({ onSuccess, onFail, onValidateFail }, ref) => {
26
- const {
27
- state: { authClient, config, guardEvents },
28
- } = useGuardContext()
29
- const { t } = useTranslation()
30
-
31
- const [rawForm] = Form.useForm()
32
-
33
- const { agreements, agreementEnabled } = config
34
-
35
- /** 表单是否被提交校验过 */
36
- const [validated, setValidated] = useState(false)
37
-
38
- const [phone, setPhone] = useState('')
39
- const [loading, setLoading] = useState(false)
40
-
41
- const onFinishFailed = (errorInfo: any) => {
42
- setLoading(false)
43
- onValidateFail && onValidateFail(errorInfo)
44
- }
45
-
46
- const [acceptedAgreements, setAcceptedAgreements] = useState(false)
47
-
48
- const onFinish = async (values: any) => {
49
- if (guardEvents.onBeforeRegister) {
50
- try {
51
- const canRegister = await guardEvents.onBeforeRegister(
52
- {
53
- type: RegisterMethods.Phone,
54
- data: {
55
- phone: values.phone,
56
- password: values.password,
57
- code: values.code,
58
- },
59
- },
60
- authClient
61
- )
62
-
63
- if (!canRegister) {
64
- setLoading(false)
65
- return
66
- }
67
- } catch (e) {
68
- if (typeof e === 'string') {
69
- message.error(e)
70
- } else {
71
- message.error(e.message)
72
- }
73
- setLoading(false)
74
- return
75
- }
76
- }
77
-
78
- try {
79
- await rawForm.validateFields()
80
-
81
- setValidated(true)
82
-
83
- if (agreementEnabled && agreements?.length && !acceptedAgreements) {
84
- return
85
- }
86
-
87
- const { phone, code, password } = values
88
- const user = await authClient.registerByPhoneCode(
89
- phone,
90
- code,
91
- password,
92
- {
93
- browser:
94
- typeof navigator !== 'undefined' ? navigator.userAgent : null,
95
- device: getDeviceName(),
96
- },
97
- {
98
- generateToken: true,
99
- params: getUserRegisterParams(),
100
- }
101
- )
102
- onSuccess && onSuccess(user)
103
- } catch (error) {
104
- onFail && onFail(error)
105
- } finally {
106
- setLoading(false)
107
- }
108
- }
109
-
110
- useImperativeHandle(ref, () => rawForm)
111
-
112
- const formItems = [
113
- {
114
- component: (
115
- <Input
116
- autoComplete="tel"
117
- onChange={(e) => {
118
- setPhone(e.target.value)
119
- }}
120
- size="large"
121
- placeholder={t('login.inputPhone')}
122
- prefix={<UserOutlined style={{ color: '#ddd' }} />}
123
- />
124
- ),
125
- name: 'phone',
126
- rules: getRequiredRules(t('common.phoneNotNull')).concat({
127
- pattern: VALIDATE_PATTERN.phone,
128
- message: t('login.phoneError'),
129
- }),
130
- },
131
- {
132
- component: (
133
- <Input.Password
134
- size="large"
135
- placeholder={t('common.setPassword')}
136
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
137
- />
138
- ),
139
- name: 'password',
140
- rules: getRequiredRules(t('common.passwordNotNull')),
141
- },
142
- {
143
- component: (
144
- <Input.Password
145
- size="large"
146
- placeholder={t('login.inputPwdAgain')}
147
- prefix={<LockOutlined style={{ color: '#ddd' }} />}
148
- />
149
- ),
150
- name: 'new-password',
151
- rules: getRequiredRules(t('common.repeatPassword')).concat({
152
- validator: (rule, value) => {
153
- if (value !== rawForm.getFieldValue('password')) {
154
- return Promise.reject(t('common.repeatPasswordDoc'))
155
- } else {
156
- return Promise.resolve()
157
- }
158
- },
159
- }),
160
- },
161
- {
162
- component: (
163
- <Input
164
- autoComplete="one-time-code"
165
- size="large"
166
- placeholder={t('common.inputFourVerifyCode', {
167
- length: 4,
168
- })}
169
- prefix={<SafetyOutlined style={{ color: '#ddd' }} />}
170
- addonAfter={<SendPhoneCode phone={phone} />}
171
- />
172
- ),
173
- name: 'code',
174
- rules: getRequiredRules(t('common.captchaCodeNotNull')),
175
- },
176
- ]
177
-
178
- return (
179
- <Form
180
- form={rawForm}
181
- onSubmitCapture={() => setLoading(true)}
182
- onFinishFailed={onFinishFailed}
183
- onFinish={onFinish}
184
- >
185
- {formItems.map((item) => (
186
- <Form.Item name={item.name} key={item.name} rules={item.rules}>
187
- {item.component}
188
- </Form.Item>
189
- ))}
190
-
191
- {config.agreementEnabled && Boolean(agreements?.length) && (
192
- <Agreements
193
- onChange={setAcceptedAgreements}
194
- agreements={agreements}
195
- showError={validated}
196
- />
197
- )}
198
-
199
- <RegisterFormFooter loading={loading} />
200
- </Form>
201
- )
202
- })
@@ -1,59 +0,0 @@
1
- import { Spin } from 'antd'
2
- import React, { FC, useEffect, useMemo, useRef } from 'react'
3
-
4
- import { useGuardContext } from '../../../context/global/context'
5
- import {
6
- LoginMethods,
7
- QrLoginFormProps,
8
- } from '../../../../components/AuthingGuard/types'
9
-
10
- import './style.less'
11
- import { User } from 'authing-js-sdk'
12
-
13
- export const QrCodeLoginForm: FC<QrLoginFormProps> = ({
14
- onFail,
15
- onSuccess,
16
- type,
17
- }) => {
18
- const {
19
- state: { authClient, config },
20
- } = useGuardContext()
21
-
22
- const timerRef = useRef<any>()
23
-
24
- const client = useMemo(() => {
25
- return {
26
- [LoginMethods.AppQr]: authClient.qrcode,
27
- [LoginMethods.WxMinQr]: authClient.wxqrcode,
28
- [LoginMethods.WechatMpQrcode]: authClient.wechatmpqrcode,
29
- }[type]
30
- }, [type, authClient])
31
-
32
- useEffect(() => {
33
- client.startScanning('authingGuardQrcode', {
34
- autoExchangeUserInfo: true,
35
- ...config.qrCodeScanOptions,
36
- onStart(timer) {
37
- timerRef.current = timer
38
- },
39
- onSuccess(user) {
40
- onSuccess && onSuccess(user as User)
41
- },
42
- onError: (message) => {
43
- config.qrCodeScanOptions?.onError?.(message)
44
-
45
- onFail && onFail(`${message}`)
46
- },
47
- })
48
- return () => clearInterval(timerRef.current)
49
- }, [client, config.qrCodeScanOptions, onFail, onSuccess])
50
-
51
- return (
52
- <div className="authing-guard-qr-form">
53
- <div className="authing-guard-qr-loading">
54
- <Spin size="large" />
55
- </div>
56
- <div id="authingGuardQrcode"></div>
57
- </div>
58
- )
59
- }
@@ -1,14 +0,0 @@
1
- .authing-guard-qr-form {
2
- position: relative;
3
- min-height: 300px;
4
- }
5
- .authing-guard-qr-loading {
6
- position: absolute;
7
- width: 100%;
8
- height: 100%;
9
- left: 0;
10
- top: 0;
11
- display: flex;
12
- justify-content: center;
13
- align-items: center;
14
- }