@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,236 +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 {
11
- getDeviceName,
12
- getPasswordValidate,
13
- getUserRegisterParams,
14
- } from '../../_utils'
15
- import { Agreements } from '../components/Agreements'
16
- import SubmitButton from '../../SubmitButton'
17
- import {
18
- EmailFormItem,
19
- ICheckProps,
20
- ValidatorFormItemProps,
21
- } from '../../ValidatorRules'
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 [form] = Form.useForm()
41
-
42
- const [acceptedAgreements, setAcceptedAgreements] = useState(false)
43
- const [validated, setValidated] = useState(false)
44
- const ref = useRef<ICheckProps>(null)
45
-
46
- const [, onFinish] = useAsyncFn(
47
- async (values: any) => {
48
- submitButtonRef.current.onSpin(true)
49
- if (onBeforeRegister) {
50
- try {
51
- const canRegister = await 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
- if (!canRegister) {
63
- submitButtonRef.current.onSpin(false)
64
- return
65
- }
66
- } catch (e: any) {
67
- if (typeof e === 'string') {
68
- message.error(e)
69
- } else {
70
- message.error(e?.message)
71
- }
72
- submitButtonRef.current.onSpin(false)
73
- return
74
- }
75
- }
76
-
77
- try {
78
- await form.validateFields()
79
- setValidated(true)
80
- if (agreements?.length && !acceptedAgreements) {
81
- submitButtonRef.current.onSpin(false)
82
- return
83
- }
84
- const { email, password } = values
85
-
86
- // 注册
87
- const user = await authClient.registerByEmail(
88
- email,
89
- password,
90
- {
91
- browser:
92
- typeof navigator !== 'undefined' ? navigator.userAgent : null,
93
- device: getDeviceName(),
94
- },
95
- {
96
- generateToken: true,
97
- params: getUserRegisterParams(),
98
- }
99
- )
100
- submitButtonRef.current.onSpin(false)
101
- onRegister(200, user)
102
- } catch ({ code, data, message }) {
103
- submitButtonRef.current.onSpin(false)
104
- onRegister(code, data, message)
105
- }
106
- },
107
- [form, acceptedAgreements],
108
- { loading: false }
109
- )
110
-
111
- const formItems: {
112
- component: React.ReactNode
113
- name: string
114
- rules?: Rule[]
115
- FormItemFC?: React.ForwardRefExoticComponent<
116
- ValidatorFormItemProps & React.RefAttributes<ICheckProps>
117
- >
118
- }[] = [
119
- {
120
- component: (
121
- <Input
122
- className="authing-g2-input"
123
- autoComplete="email"
124
- size="large"
125
- placeholder={t('login.inputEmail')}
126
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
127
- />
128
- ),
129
- name: 'email',
130
- FormItemFC: EmailFormItem,
131
- },
132
- {
133
- component: (
134
- <Input.Password
135
- className="authing-g2-input"
136
- size="large"
137
- placeholder={t('login.inputPwd')}
138
- prefix={<LockOutlined style={{ color: '#878A95' }} />}
139
- />
140
- ),
141
- name: 'password',
142
- rules: [
143
- {
144
- validator(_, value) {
145
- if ((value ?? '').indexOf(' ') !== -1) {
146
- return Promise.reject(t('common.checkPasswordHasSpace'))
147
- }
148
- return Promise.resolve()
149
- },
150
- },
151
- ...getPasswordValidate(
152
- publicConfig?.passwordStrength,
153
- publicConfig?.customPasswordStrength
154
- ),
155
- ],
156
- },
157
- {
158
- component: (
159
- <Input.Password
160
- className="authing-g2-input"
161
- size="large"
162
- placeholder={t('common.passwordAgain')}
163
- prefix={<LockOutlined style={{ color: '#878A95' }} />}
164
- />
165
- ),
166
- name: 'new-password',
167
- rules: [
168
- ...getPasswordValidate(
169
- publicConfig?.passwordStrength,
170
- publicConfig?.customPasswordStrength
171
- ),
172
- {
173
- validator: (_, value) => {
174
- if (value !== form.getFieldValue('password')) {
175
- return Promise.reject(t('common.repeatPasswordDoc'))
176
- } else {
177
- return Promise.resolve()
178
- }
179
- },
180
- },
181
- ],
182
- },
183
- ]
184
-
185
- return (
186
- <div className="authing-g2-register-email">
187
- <Form
188
- form={form}
189
- name="emailRegister"
190
- autoComplete="off"
191
- onFinish={onFinish}
192
- onFinishFailed={() => submitButtonRef.current.onError()}
193
- onValuesChange={() => {
194
- ref.current?.check()
195
- }}
196
- >
197
- {formItems.map((item) =>
198
- item.FormItemFC ? (
199
- <item.FormItemFC
200
- ref={ref}
201
- key={item.name}
202
- name={item.name}
203
- className="authing-g2-input-form"
204
- validateFirst={true}
205
- userPoolId={publicConfig?.userPoolId!}
206
- form={form}
207
- checkRepeat={true}
208
- >
209
- {item.component}
210
- </item.FormItemFC>
211
- ) : (
212
- <Form.Item
213
- key={item.name}
214
- name={item.name}
215
- rules={item.rules}
216
- className="authing-g2-input-form"
217
- validateFirst={true}
218
- >
219
- {item.component}
220
- </Form.Item>
221
- )
222
- )}
223
- {Boolean(agreements?.length) && (
224
- <Agreements
225
- onChange={setAcceptedAgreements}
226
- agreements={agreements}
227
- showError={validated}
228
- />
229
- )}
230
- <Form.Item>
231
- <SubmitButton text={t('common.register')} ref={submitButtonRef} />
232
- </Form.Item>
233
- </Form>
234
- </div>
235
- )
236
- }
@@ -1,184 +0,0 @@
1
- import { SafetyOutlined, UserOutlined } from '@ant-design/icons'
2
- import { Form } 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 {
10
- fieldRequiredRule,
11
- getDeviceName,
12
- getUserRegisterParams,
13
- } from '../../_utils'
14
- import { Agreements } from '../components/Agreements'
15
- import SubmitButton from '../../SubmitButton'
16
- import { InputNumber } from '../../InputNumber'
17
- import {
18
- ICheckProps,
19
- PhoneFormItem,
20
- ValidatorFormItemProps,
21
- } from '../../ValidatorRules'
22
- import { Rule } from 'antd/lib/form'
23
-
24
- export interface RegisterWithPhoneProps {
25
- onRegister: Function
26
- agreements: Agreement[]
27
- publicConfig?: ApplicationConfig
28
- }
29
-
30
- export const RegisterWithPhone: React.FC<RegisterWithPhoneProps> = ({
31
- onRegister,
32
- agreements,
33
- publicConfig,
34
- }) => {
35
- const { t } = useTranslation()
36
- const submitButtonRef = useRef<any>(null)
37
- const authClient = useAuthClient()
38
- const [form] = Form.useForm()
39
- const [phone, setPhone] = useState<string>('')
40
- const [acceptedAgreements, setAcceptedAgreements] = useState(false)
41
- const [validated, setValidated] = useState(false)
42
-
43
- const ref = useRef<ICheckProps>(null)
44
-
45
- const verifyCodeLength = publicConfig?.verifyCodeLength ?? 4
46
-
47
- const [, onFinish] = useAsyncFn(
48
- async (values: any) => {
49
- try {
50
- submitButtonRef.current.onSpin(true)
51
- await form.validateFields()
52
-
53
- setValidated(true)
54
-
55
- if (agreements?.length && !acceptedAgreements) {
56
- return
57
- }
58
-
59
- const { phone, password = '', code } = values
60
-
61
- // 注册
62
- const user = await authClient.registerByPhoneCode(
63
- phone,
64
- code,
65
- password,
66
- {
67
- browser:
68
- typeof navigator !== 'undefined' ? navigator.userAgent : null,
69
- device: getDeviceName(),
70
- },
71
- {
72
- generateToken: true,
73
- params: getUserRegisterParams(),
74
- }
75
- )
76
-
77
- submitButtonRef.current.onSpin(false)
78
- onRegister(200, user)
79
- } catch ({ code, data, message }) {
80
- submitButtonRef.current.onSpin(false)
81
- onRegister(code, data, message)
82
- }
83
- },
84
- [form],
85
- { loading: false }
86
- )
87
-
88
- const formItems: {
89
- component: React.ReactNode
90
- name: string
91
- rules?: Rule[]
92
- FormItemFC?: React.ForwardRefExoticComponent<
93
- ValidatorFormItemProps & React.RefAttributes<ICheckProps>
94
- >
95
- }[] = [
96
- {
97
- component: (
98
- <InputNumber
99
- className="authing-g2-input"
100
- onChange={(e) => {
101
- setPhone(e.target.value)
102
- }}
103
- size="large"
104
- placeholder={t('login.inputPhone')}
105
- prefix={<UserOutlined style={{ color: '#878A95' }} />}
106
- maxLength={11}
107
- />
108
- ),
109
- name: 'phone',
110
- FormItemFC: PhoneFormItem,
111
- },
112
- {
113
- component: (
114
- <SendCode
115
- className="authing-g2-input"
116
- autoComplete="one-time-code"
117
- size="large"
118
- placeholder={t('common.inputFourVerifyCode', {
119
- length: verifyCodeLength,
120
- })}
121
- maxLength={verifyCodeLength}
122
- prefix={<SafetyOutlined style={{ color: '#878A95' }} />}
123
- method="phone"
124
- onSendCodeBefore={() => form.validateFields(['phone'])}
125
- data={phone}
126
- />
127
- ),
128
- name: 'code',
129
- rules: fieldRequiredRule(t('common.captchaCode')),
130
- },
131
- ]
132
-
133
- return (
134
- <div className="authing-g2-register-email">
135
- <Form
136
- form={form}
137
- name="emailRegister"
138
- autoComplete="off"
139
- onFinish={onFinish}
140
- onFinishFailed={() => submitButtonRef.current.onError()}
141
- onValuesChange={() => {
142
- ref.current?.check()
143
- }}
144
- >
145
- {formItems.map((item) =>
146
- item.FormItemFC ? (
147
- <item.FormItemFC
148
- ref={ref}
149
- key={item.name}
150
- name={item.name}
151
- className="authing-g2-input-form"
152
- validateFirst={true}
153
- userPoolId={publicConfig?.userPoolId!}
154
- form={form}
155
- checkRepeat={true}
156
- >
157
- {item.component}
158
- </item.FormItemFC>
159
- ) : (
160
- <Form.Item
161
- key={item.name}
162
- name={item.name}
163
- rules={item.rules}
164
- className="authing-g2-input-form"
165
- validateFirst={true}
166
- >
167
- {item.component}
168
- </Form.Item>
169
- )
170
- )}
171
- {Boolean(agreements?.length) && (
172
- <Agreements
173
- onChange={setAcceptedAgreements}
174
- agreements={agreements}
175
- showError={validated}
176
- />
177
- )}
178
- <Form.Item>
179
- <SubmitButton text={t('common.register')} ref={submitButtonRef} />
180
- </Form.Item>
181
- </Form>
182
- </div>
183
- )
184
- }
@@ -1,123 +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
-
12
- export const GuardRegisterView: React.FC<GuardRegisterViewProps> = ({
13
- config,
14
- onLangChange,
15
- __changeModule,
16
- ...registerEvents
17
- }) => {
18
- const { t } = useTranslation()
19
- const agreementEnabled = config?.agreementEnabled
20
- const { langRange } = config
21
- const authClient = useAuthClient()
22
-
23
- const __codePaser = (code: number) => {
24
- if (code === 200) {
25
- return (user: User) => {
26
- // TODO 用户信息补全 等待后端接口修改
27
- if (config.__publicConfig__!.extendsFieldsEnabled) {
28
- __changeModule?.(GuardModuleType.COMPLETE_INFO, {})
29
- } else {
30
- registerEvents.onRegister?.(user, authClient)
31
- __changeModule?.(GuardModuleType.LOGIN, {})
32
- }
33
- }
34
- }
35
- }
36
-
37
- const registerContextProps = useMemo(
38
- () => ({
39
- onRegister: (code: number, data: any = {}, message?: string) => {
40
- const callback = __codePaser(code)
41
-
42
- if (code !== 200) {
43
- registerEvents.onRegisterError?.({
44
- code,
45
- data,
46
- message,
47
- })
48
- }
49
-
50
- callback?.({
51
- ...data,
52
- _message: message,
53
- })
54
- },
55
- onBeforeRegister: registerEvents.onBeforeRegister,
56
- agreements: agreementEnabled ? config?.agreements ?? [] : [],
57
- publicConfig: config.__publicConfig__,
58
- }),
59
- // eslint-disable-next-line react-hooks/exhaustive-deps
60
- [agreementEnabled, config?.agreements, registerEvents.onBeforeRegister]
61
- )
62
-
63
- const tabMapping: Record<
64
- RegisterMethods,
65
- { component: React.ReactNode; name: string }
66
- > = useMemo(
67
- () => ({
68
- [RegisterMethods.Email]: {
69
- component: <RegisterWithEmail {...registerContextProps} />,
70
- name: t('common.emailLabel'),
71
- },
72
- [RegisterMethods.Phone]: {
73
- component: <RegisterWithPhone {...registerContextProps} />,
74
- name: t('common.phoneLabel'),
75
- },
76
- }),
77
- [registerContextProps, t]
78
- )
79
-
80
- const renderTab = useMemo(
81
- () =>
82
- config?.registerMethods?.map((method) => (
83
- <Tabs.TabPane tab={tabMapping[method].name} key={method}>
84
- {tabMapping[method].component}
85
- </Tabs.TabPane>
86
- )),
87
- [config?.registerMethods, tabMapping]
88
- )
89
-
90
- return (
91
- <div className="g2-view-container">
92
- <div className="g2-view-header">
93
- <img src={config?.logo} alt="" className="icon" />
94
-
95
- <div className="title">
96
- {t('common.welcomeJoin', { name: config?.title })}
97
- </div>
98
- </div>
99
- <div className="g2-view-tabs">
100
- <Tabs
101
- defaultActiveKey={config?.defaultRegisterMethod}
102
- onChange={(activeKey) => {
103
- registerEvents.onRegisterTabChange?.(activeKey as RegisterMethods)
104
- }}
105
- >
106
- {renderTab}
107
- </Tabs>
108
- </div>
109
- <div className="g2-tips-line">
110
- <span className="back-to-login">
111
- <span className="gray">{t('common.alreadyHasAcc')}</span>
112
- <span
113
- className="link-like"
114
- onClick={() => __changeModule?.(GuardModuleType.LOGIN, {})}
115
- >
116
- {t('common.backLoginPage')}
117
- </span>
118
- </span>
119
- </div>
120
- <ChangeLanguage langRange={langRange} onLangChange={onLangChange} />
121
- </div>
122
- )
123
- }
@@ -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
- }