@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,250 +0,0 @@
1
- import { LockOutlined, UserOutlined } from '@ant-design/icons'
2
- import { Form, Input, message } from 'antd'
3
- import { Rule } from 'antd/lib/form'
4
- import { RegisterMethods } from 'authing-js-sdk'
5
- import React, { useRef, useState } from 'react'
6
- import { useTranslation } from 'react-i18next'
7
- import { useAsyncFn } from 'react-use'
8
- import { Agreement, ApplicationConfig } from '../../AuthingGuard/api'
9
- import { useAuthClient } from '../../Guard/authClient'
10
- import { useDebounce } from '../../_utils/hooks'
11
- import {
12
- getDeviceName,
13
- getPasswordValidate,
14
- getRequiredRules,
15
- getUserRegisterParams,
16
- PASSWORD_STRENGTH_TEXT_MAP,
17
- VALIDATE_PATTERN,
18
- } from '../../_utils'
19
- import { useGuardHttp } from '../../_utils/guradHttp'
20
- import { Agreements } from '../components/Agreements'
21
- import SubmitButton from '../../SubmitButton'
22
-
23
- export interface RegisterWithEmailProps {
24
- onRegister: Function
25
- onBeforeRegister?: Function
26
- publicConfig?: ApplicationConfig
27
- agreements: Agreement[]
28
- }
29
-
30
- export const RegisterWithEmail: React.FC<RegisterWithEmailProps> = ({
31
- onRegister,
32
- onBeforeRegister,
33
- agreements,
34
- publicConfig,
35
- }) => {
36
- const { t } = useTranslation()
37
- const submitButtonRef = useRef<any>(null)
38
-
39
- const authClient = useAuthClient()
40
- const { get } = useGuardHttp()
41
- const [form] = Form.useForm()
42
-
43
- const [acceptedAgreements, setAcceptedAgreements] = useState(false)
44
- const [validated, setValidated] = useState(false)
45
- const [isFind, setIsFind] = useState<boolean>(false)
46
-
47
- // 检查手机号是否已经被注册过了 by my son donglyc
48
- const handleCheckEmail = useDebounce(async (value: any) => {
49
- if (value.email) {
50
- let { data } = await get<boolean>(`/api/v2/users/find`, {
51
- userPoolId: publicConfig?.userPoolId,
52
- key: form.getFieldValue('email'),
53
- type: 'email',
54
- })
55
- setIsFind(Boolean(data))
56
- form.validateFields(['email'])
57
- }
58
- }, 1000)
59
-
60
- const [, onFinish] = useAsyncFn(
61
- async (values: any) => {
62
- submitButtonRef.current.onSpin(true)
63
- if (onBeforeRegister) {
64
- try {
65
- const canRegister = await onBeforeRegister(
66
- {
67
- type: RegisterMethods.Phone,
68
- data: {
69
- phone: values.phone,
70
- password: values.password,
71
- code: values.code,
72
- },
73
- },
74
- authClient
75
- )
76
- if (!canRegister) {
77
- submitButtonRef.current.onSpin(false)
78
- return
79
- }
80
- } catch (e) {
81
- if (typeof e === 'string') {
82
- message.error(e)
83
- } else {
84
- message.error(e.message)
85
- }
86
- submitButtonRef.current.onSpin(false)
87
- return
88
- }
89
- }
90
-
91
- try {
92
- await form.validateFields()
93
- setValidated(true)
94
- if (agreements?.length && !acceptedAgreements) {
95
- submitButtonRef.current.onSpin(false)
96
- return
97
- }
98
- const { email, password } = values
99
-
100
- // 注册
101
- const user = await authClient.registerByEmail(
102
- email,
103
- password,
104
- {
105
- browser:
106
- typeof navigator !== 'undefined' ? navigator.userAgent : null,
107
- device: getDeviceName(),
108
- },
109
- {
110
- generateToken: true,
111
- params: getUserRegisterParams(),
112
- }
113
- )
114
- submitButtonRef.current.onSpin(false)
115
- onRegister(200, user)
116
- } catch ({ code, data, message }) {
117
- submitButtonRef.current.onSpin(false)
118
- onRegister(code, data, message)
119
- }
120
- },
121
- [form],
122
- { loading: false }
123
- )
124
-
125
- const formItems: {
126
- component: React.ReactNode
127
- name: string
128
- rules: Rule[]
129
- }[] = [
130
- {
131
- component: (
132
- <Input
133
- className="authing-g2-input"
134
- autoComplete="email"
135
- size="large"
136
- placeholder={t('login.inputEmail')}
137
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
138
- />
139
- ),
140
- name: 'email',
141
- rules: [
142
- ...getRequiredRules(t('common.emailNotNull')),
143
- {
144
- validator: (rule, value) => {
145
- if (value) {
146
- if (VALIDATE_PATTERN.email.test(value)) {
147
- if (isFind) {
148
- return Promise.reject(t('common.checkEmail'))
149
- } else {
150
- return Promise.resolve()
151
- }
152
- } else {
153
- return Promise.reject(new Error(t('common.emailFormatError')))
154
- }
155
- } else {
156
- return Promise.resolve()
157
- }
158
- },
159
- },
160
- ],
161
- },
162
- {
163
- component: (
164
- <Input.Password
165
- className="authing-g2-input"
166
- size="large"
167
- placeholder={PASSWORD_STRENGTH_TEXT_MAP[
168
- publicConfig?.passwordStrength!
169
- ].placeholder()}
170
- prefix={<LockOutlined style={{ color: '#878A95' }} />}
171
- />
172
- ),
173
- name: 'password',
174
- rules: [
175
- {
176
- validator(_, value) {
177
- if ((value ?? '').indexOf(' ') !== -1) {
178
- return Promise.reject(t('common.checkPasswordHasSpace'))
179
- }
180
- return Promise.resolve()
181
- },
182
- },
183
- ...getPasswordValidate(
184
- publicConfig?.passwordStrength,
185
- publicConfig?.customPasswordStrength
186
- ),
187
- ],
188
- },
189
- {
190
- component: (
191
- <Input.Password
192
- className="authing-g2-input"
193
- size="large"
194
- placeholder={t('common.passwordAgain')}
195
- prefix={<LockOutlined style={{ color: '#878A95' }} />}
196
- />
197
- ),
198
- name: 'new-password',
199
- rules: [
200
- {
201
- validator: (_, value) => {
202
- if (value !== form.getFieldValue('password')) {
203
- return Promise.reject(t('common.repeatPasswordDoc'))
204
- } else {
205
- return Promise.resolve()
206
- }
207
- },
208
- },
209
- ...getPasswordValidate(
210
- publicConfig?.passwordStrength,
211
- publicConfig?.customPasswordStrength
212
- ),
213
- ],
214
- },
215
- ]
216
-
217
- return (
218
- <div className="authing-g2-register-email">
219
- <Form
220
- form={form}
221
- name="emailRegister"
222
- autoComplete="off"
223
- onFinish={onFinish}
224
- onFinishFailed={() => submitButtonRef.current.onError()}
225
- onValuesChange={handleCheckEmail}
226
- >
227
- {formItems.map((item) => (
228
- <Form.Item
229
- key={item.name}
230
- name={item.name}
231
- rules={item.rules}
232
- className="authing-g2-input-form"
233
- >
234
- {item.component}
235
- </Form.Item>
236
- ))}
237
- {Boolean(agreements?.length) && (
238
- <Agreements
239
- onChange={setAcceptedAgreements}
240
- agreements={agreements}
241
- showError={validated}
242
- />
243
- )}
244
- <Form.Item>
245
- <SubmitButton text={t('common.register')} ref={submitButtonRef} />
246
- </Form.Item>
247
- </Form>
248
- </div>
249
- )
250
- }
@@ -1,190 +0,0 @@
1
- import { SafetyOutlined, UserOutlined } from '@ant-design/icons'
2
- import { Form, Input } from 'antd'
3
- import React, { useRef, useState } from 'react'
4
- import { useTranslation } from 'react-i18next'
5
- import { useAsyncFn } from 'react-use'
6
- import { Agreement, ApplicationConfig } from '../../AuthingGuard/api'
7
- import { useAuthClient } from '../../Guard/authClient'
8
- import { SendCode } from '../../SendCode'
9
- import { useDebounce } from '../../_utils/hooks'
10
- import {
11
- getDeviceName,
12
- getRequiredRules,
13
- getUserRegisterParams,
14
- VALIDATE_PATTERN,
15
- } from '../../_utils'
16
- import { useGuardHttp } from '../../_utils/guradHttp'
17
- import { Agreements } from '../components/Agreements'
18
- import SubmitButton from '../../SubmitButton'
19
-
20
- export interface RegisterWithPhoneProps {
21
- onRegister: Function
22
- agreements: Agreement[]
23
- publicConfig?: ApplicationConfig
24
- }
25
-
26
- export const RegisterWithPhone: React.FC<RegisterWithPhoneProps> = ({
27
- onRegister,
28
- agreements,
29
- publicConfig,
30
- }) => {
31
- const { t } = useTranslation()
32
- const submitButtonRef = useRef<any>(null)
33
- const authClient = useAuthClient()
34
- const [form] = Form.useForm()
35
- const { get } = useGuardHttp()
36
- const [phone, setPhone] = useState<string>('')
37
- const [acceptedAgreements, setAcceptedAgreements] = useState(false)
38
- const [validated, setValidated] = useState(false)
39
- const [isFind, setIsFind] = useState<boolean>(false)
40
-
41
- const verifyCodeLength = publicConfig?.verifyCodeLength ?? 4
42
-
43
- // 检查手机号是否已经被注册过了 by my son donglyc
44
- const handleCheckPhone = useDebounce(async (value: any) => {
45
- if (value.phone) {
46
- let { data } = await get(`/api/v2/users/find`, {
47
- userPoolId: publicConfig?.userPoolId,
48
- key: form.getFieldValue('phone'),
49
- type: 'phone',
50
- })
51
- setIsFind(Boolean(data))
52
- form.validateFields(['phone'])
53
- }
54
- }, 1000)
55
-
56
- const [, onFinish] = useAsyncFn(
57
- async (values: any) => {
58
- try {
59
- submitButtonRef.current.onSpin(true)
60
- await form.validateFields()
61
-
62
- setValidated(true)
63
-
64
- if (agreements?.length && !acceptedAgreements) {
65
- return
66
- }
67
-
68
- const { phone, password = '', code } = values
69
-
70
- // 注册
71
- const user = await authClient.registerByPhoneCode(
72
- phone,
73
- code,
74
- password,
75
- {
76
- browser:
77
- typeof navigator !== 'undefined' ? navigator.userAgent : null,
78
- device: getDeviceName(),
79
- },
80
- {
81
- generateToken: true,
82
- params: getUserRegisterParams(),
83
- }
84
- )
85
-
86
- submitButtonRef.current.onSpin(false)
87
- onRegister(200, user)
88
- } catch ({ code, data, message }) {
89
- submitButtonRef.current.onSpin(false)
90
- onRegister(code, data, message)
91
- }
92
- },
93
- [form],
94
- { loading: false }
95
- )
96
-
97
- const formItems = [
98
- {
99
- component: (
100
- <Input
101
- className="authing-g2-input"
102
- autoComplete="tel"
103
- onChange={(e) => {
104
- setPhone(e.target.value)
105
- }}
106
- size="large"
107
- placeholder={t('login.inputPhone')}
108
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
109
- />
110
- ),
111
- name: 'phone',
112
- rules: [
113
- ...getRequiredRules(t('common.phoneNotNull')).concat({
114
- pattern: VALIDATE_PATTERN.phone,
115
- message: t('login.phoneError'),
116
- }),
117
- {
118
- validator: (_: any, value: string) => {
119
- if (value) {
120
- if (VALIDATE_PATTERN.phone.test(value)) {
121
- if (isFind) {
122
- return Promise.reject(t('common.checkPhone'))
123
- } else {
124
- return Promise.resolve()
125
- }
126
- } else {
127
- return Promise.reject(new Error(t('common.phoneFormateError')))
128
- }
129
- } else {
130
- return Promise.resolve()
131
- }
132
- },
133
- },
134
- ],
135
- },
136
- {
137
- component: (
138
- <SendCode
139
- className="authing-g2-input"
140
- autoComplete="one-time-code"
141
- size="large"
142
- placeholder={t('common.inputFourVerifyCode', {
143
- length: verifyCodeLength,
144
- })}
145
- maxLength={verifyCodeLength}
146
- prefix={<SafetyOutlined style={{ color: '#878A95' }} />}
147
- method="phone"
148
- onSendCodeBefore={() => form.validateFields(['phone'])}
149
- data={phone}
150
- />
151
- ),
152
- name: 'code',
153
- rules: getRequiredRules(t('common.captchaCodeNotNull')),
154
- },
155
- ]
156
-
157
- return (
158
- <div className="authing-g2-register-email">
159
- <Form
160
- form={form}
161
- name="emailRegister"
162
- autoComplete="off"
163
- onFinish={onFinish}
164
- onFinishFailed={() => submitButtonRef.current.onError()}
165
- onValuesChange={handleCheckPhone}
166
- >
167
- {formItems.map((item) => (
168
- <Form.Item
169
- key={item.name}
170
- name={item.name}
171
- rules={item.rules}
172
- className="authing-g2-input-form"
173
- >
174
- {item.component}
175
- </Form.Item>
176
- ))}
177
- {Boolean(agreements?.length) && (
178
- <Agreements
179
- onChange={setAcceptedAgreements}
180
- agreements={agreements}
181
- showError={validated}
182
- />
183
- )}
184
- <Form.Item>
185
- <SubmitButton text={t('common.register')} ref={submitButtonRef} />
186
- </Form.Item>
187
- </Form>
188
- </div>
189
- )
190
- }
@@ -1,122 +0,0 @@
1
- import React, { useMemo } from 'react'
2
- import { useTranslation } from 'react-i18next'
3
- import { Tabs } from 'antd'
4
- import { RegisterMethods, User } from 'authing-js-sdk'
5
- import { ChangeLanguage } from '../ChangeLanguage'
6
- import { useAuthClient } from '../Guard/authClient'
7
- import { GuardModuleType } from '../Guard/module'
8
- import { RegisterWithEmail } from './core/WithEmail'
9
- import { RegisterWithPhone } from './core/WithPhone'
10
- import { GuardRegisterViewProps } from './props'
11
- import { i18n } from '../_utils/locales'
12
-
13
- export const GuardRegisterView: React.FC<GuardRegisterViewProps> = ({
14
- config,
15
- onLangChange,
16
- __changeModule,
17
- ...registerEvents
18
- }) => {
19
- const { t } = useTranslation()
20
- const agreementEnabled = config?.agreementEnabled
21
- const { langRange } = config
22
- const authClient = useAuthClient()
23
-
24
- const __codePaser = (code: number) => {
25
- if (code === 200) {
26
- return (user: User) => {
27
- // TODO 用户信息补全 等待后端接口修改
28
- if (config.__publicConfig__!.extendsFieldsEnabled) {
29
- __changeModule?.(GuardModuleType.COMPLETE_INFO, {})
30
- } else {
31
- registerEvents.onRegister?.(user, authClient)
32
- __changeModule?.(GuardModuleType.LOGIN, {})
33
- }
34
- }
35
- }
36
- }
37
-
38
- const registerContextProps = useMemo(
39
- () => ({
40
- onRegister: (code: number, data: any = {}, message?: string) => {
41
- const callback = __codePaser(code)
42
-
43
- callback?.({
44
- ...data,
45
- _message: message,
46
- })
47
- },
48
- onBeforeRegister: registerEvents.onBeforeRegister,
49
- agreements: agreementEnabled ? config?.agreements ?? [] : [],
50
- publicConfig: config.__publicConfig__,
51
- }),
52
- // eslint-disable-next-line react-hooks/exhaustive-deps
53
- [agreementEnabled, config?.agreements, registerEvents.onBeforeRegister]
54
- )
55
-
56
- const tabMapping: Record<
57
- RegisterMethods,
58
- { component: React.ReactNode; name: string }
59
- > = useMemo(
60
- () => ({
61
- [RegisterMethods.Email]: {
62
- component: <RegisterWithEmail {...registerContextProps} />,
63
- name: i18n.t('common.email'),
64
- },
65
- [RegisterMethods.Phone]: {
66
- component: <RegisterWithPhone {...registerContextProps} />,
67
- name: i18n.t('common.phoneNumber'),
68
- },
69
- }),
70
- [registerContextProps]
71
- )
72
-
73
- const renderTab = useMemo(
74
- () =>
75
- config?.registerMethods?.map((method) => (
76
- <Tabs.TabPane tab={tabMapping[method].name} key={method}>
77
- {tabMapping[method].component}
78
- </Tabs.TabPane>
79
- )),
80
- [config?.registerMethods, tabMapping]
81
- )
82
-
83
- return (
84
- <div className="g2-view-container">
85
- <div className="g2-view-header">
86
- <img src={config?.logo} alt="" className="icon" />
87
-
88
- <div className="title">
89
- {t('common.welcomeJoin', { name: config?.title })}
90
- </div>
91
- </div>
92
- <div className="g2-view-tabs">
93
- <Tabs
94
- defaultActiveKey={config?.defaultRegisterMethod}
95
- onChange={(activeKey) => {
96
- registerEvents.onRegisterTabChange?.(activeKey as RegisterMethods)
97
- }}
98
- >
99
- {renderTab}
100
- </Tabs>
101
- </div>
102
- <div className="g2-tips-line">
103
- <div
104
- className="link-like"
105
- onClick={() => __changeModule?.(GuardModuleType.FORGET_PWD, {})}
106
- >
107
- {t('login.forgetPwd')}
108
- </div>
109
- <span className="back-to-login">
110
- <span className="gray">{t('common.alreadyHasAcc')}</span>
111
- <span
112
- className="link-like"
113
- onClick={() => __changeModule?.(GuardModuleType.LOGIN, {})}
114
- >
115
- {t('common.backLoginPage')}
116
- </span>
117
- </span>
118
- </div>
119
- <ChangeLanguage langRange={langRange} onLangChange={onLangChange} />
120
- </div>
121
- )
122
- }
@@ -1,50 +0,0 @@
1
- import { RegisterMethods } from 'authing-js-sdk'
2
- import { IG2FCProps, IG2Config, getDefaultG2Config, IG2Events } from '../Type'
3
- import {
4
- AuthenticationClient,
5
- User,
6
- EmailRegisterParams,
7
- PhoneRegisterParams,
8
- } from '..'
9
- import { Agreement } from '../AuthingGuard/api'
10
-
11
- export interface RegisterConfig extends IG2Config {
12
- disableRegister: boolean
13
- registerMethods: RegisterMethods[]
14
- defaultRegisterMethod: RegisterMethods
15
- publicKey?: string
16
- agreementEnabled?: boolean
17
- agreements?: Agreement[]
18
- }
19
-
20
- const defaultConfig: RegisterConfig = {
21
- ...getDefaultG2Config(),
22
- disableRegister: false,
23
- defaultRegisterMethod: RegisterMethods.Email,
24
- registerMethods: [RegisterMethods.Email, RegisterMethods.Phone],
25
- }
26
-
27
- export interface RegisterEvents extends IG2Events {
28
- onBeforeRegister?: (
29
- registerInfo: EmailRegisterParams | PhoneRegisterParams,
30
- authClient: AuthenticationClient
31
- ) => boolean | Promise<boolean>
32
- onRegister?: (user: User, authClient: AuthenticationClient) => void
33
- onRegisterError?: (error: any) => void
34
- onRegisterTabChange?: (activeTab: RegisterMethods) => void
35
- }
36
-
37
- export interface GuardRegisterProps extends IG2FCProps, RegisterEvents {
38
- config?: Partial<RegisterConfig>
39
- }
40
-
41
- export interface GuardRegisterViewProps extends GuardRegisterProps {
42
- config: RegisterConfig
43
- }
44
-
45
- const getDefaultConfig = (): RegisterConfig => ({
46
- ...getDefaultG2Config(),
47
- ...defaultConfig,
48
- })
49
-
50
- export const getDefaultRegisterConfig = getDefaultConfig
@@ -1,96 +0,0 @@
1
- import { Button } from 'antd'
2
- import React, { FC, useState, useRef, useEffect, useMemo } from 'react'
3
- import { useTranslation } from 'react-i18next'
4
- import './style.less'
5
- import { ButtonProps } from 'antd/lib/button'
6
-
7
- const TIME = 60
8
- export interface SendCodeProps extends ButtonProps {
9
- beforeSend: () => Promise<boolean>
10
- btnRef?: React.RefObject<HTMLButtonElement>
11
- }
12
-
13
- const useSentCounter = () => {
14
- const [countDown, setCountDown] = useState(0)
15
- const timerRef = useRef<any>(0)
16
-
17
- useEffect(() => {
18
- return () => clearInterval(timerRef.current)
19
- }, [])
20
-
21
- useEffect(() => {
22
- if (countDown <= 0) {
23
- clearInterval(timerRef.current)
24
- }
25
- }, [countDown])
26
-
27
- const enabled = useMemo(() => countDown <= 0, [countDown])
28
-
29
- const send = () => {
30
- setCountDown(TIME)
31
-
32
- timerRef.current = setInterval(() => {
33
- setCountDown((prev) => {
34
- return prev - 1
35
- })
36
- }, 1000)
37
- }
38
-
39
- return {
40
- enabled,
41
- send,
42
- countDown,
43
- }
44
- }
45
-
46
- export const SendCodeBtn: FC<SendCodeProps> = ({
47
- beforeSend,
48
- btnRef,
49
- ...buttonProps
50
- }) => {
51
- const { enabled, send, countDown } = useSentCounter()
52
- const [loading, setLoading] = useState(false)
53
- const { t } = useTranslation()
54
- const disabled = useMemo(() => {
55
- return !enabled || loading
56
- }, [enabled, loading])
57
-
58
- const onClick = async (e: React.MouseEvent<HTMLButtonElement>) => {
59
- setLoading(true)
60
- if (disabled) {
61
- return
62
- }
63
-
64
- let beforeStop = !(await beforeSend())
65
- if (beforeStop) {
66
- setLoading(false)
67
- return
68
- }
69
- setLoading(false)
70
- send()
71
- }
72
-
73
- return (
74
- <Button
75
- {...buttonProps}
76
- className={
77
- buttonProps.type ?? 'authing-g2-send-code-btn g2-loading-btn-center'
78
- }
79
- disabled={disabled}
80
- loading={loading}
81
- onClick={onClick}
82
- ref={btnRef}
83
- >
84
- {loading === true && <span></span>}
85
- {loading === false && (
86
- <span>
87
- {enabled
88
- ? t('common.sendVerifyCode')
89
- : t('common.retryAfterTime', {
90
- time: countDown,
91
- })}
92
- </span>
93
- )}
94
- </Button>
95
- )
96
- }