@authing/react-ui-components 3.0.2-beta.9 → 3.1.1-rc.6
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.
- package/.eslintignore +6 -0
- package/.eslintrc.js +7 -0
- package/.prettierrc +5 -0
- package/.vscode/settings.json +31 -0
- package/LICENSE +21 -0
- package/config/antdReplacer.js +51 -0
- package/config/env.js +106 -0
- package/config/getHttpsConfig.js +66 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +134 -0
- package/config/paths.js +71 -0
- package/config/pnpTs.js +35 -0
- package/config/webpack.config.js +857 -0
- package/config/webpackDevServer.config.js +130 -0
- package/lib/index.d.ts +211 -1669
- package/lib/index.min.css +1 -2
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.LICENSE.txt +0 -32
- package/package.json +18 -42
- package/public/favicon.ico +0 -0
- package/public/index.html +43 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +25 -0
- package/public/robots.txt +3 -0
- package/scripts/build.js +212 -0
- package/scripts/lib.js +200 -0
- package/scripts/start.js +166 -0
- package/scripts/test.js +53 -0
- package/src/common/AuthingDropdown/index.tsx +52 -0
- package/src/common/AuthingDropdown/style.less +43 -0
- package/src/common/AuthingTabs/index.tsx +98 -0
- package/src/common/AuthingTabs/style.less +135 -0
- package/src/common/CopyAbleText/index.tsx +54 -0
- package/src/common/CopyAbleText/style.less +13 -0
- package/src/common/VerifyCodeInput/index.tsx +76 -0
- package/src/common/VerifyCodeInput/style.less +24 -0
- package/src/components/AuthingGuard/AppMFALayout/index.tsx +74 -0
- package/src/components/AuthingGuard/AppMFALayout/style.less +12 -0
- package/src/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +29 -0
- package/src/components/AuthingGuard/CompleteUserInfoLayout/style.less +8 -0
- package/src/components/AuthingGuard/Forms/ADLoginForm/index.tsx +117 -0
- package/src/components/AuthingGuard/Forms/Agreements/index.tsx +81 -0
- package/src/components/AuthingGuard/Forms/Agreements/style.less +44 -0
- package/src/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +139 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +86 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +116 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +40 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +181 -0
- package/src/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +161 -0
- package/src/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +76 -0
- package/src/components/AuthingGuard/Forms/LoginFormFooter/style.less +6 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +86 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +53 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +65 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +20 -0
- package/src/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +105 -0
- package/src/components/AuthingGuard/Forms/MfaVerifyForm/style.less +12 -0
- package/src/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +261 -0
- package/src/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +133 -0
- package/src/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +202 -0
- package/src/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +61 -0
- package/src/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +14 -0
- package/src/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +56 -0
- package/src/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +21 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +86 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +127 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +141 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +51 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +96 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/style.less +3 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +88 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +50 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/style.less +26 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +86 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +113 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +40 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +3 -0
- package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +325 -0
- package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +75 -0
- package/src/components/AuthingGuard/Forms/UploadImage/index.tsx +70 -0
- package/src/components/AuthingGuard/Forms/index.ts +13 -0
- package/src/components/AuthingGuard/GuardLayout/index.tsx +488 -0
- package/src/components/AuthingGuard/GuardLayout/style.less +111 -0
- package/src/components/AuthingGuard/Header/index.tsx +28 -0
- package/src/components/AuthingGuard/Header/style.less +71 -0
- package/src/components/AuthingGuard/IconFont/iconfont.js +74 -0
- package/src/components/AuthingGuard/IconFont/index.tsx +19 -0
- package/src/components/AuthingGuard/IconFont/style.less +6 -0
- package/src/components/AuthingGuard/IconFont/svg.js +2 -0
- package/src/components/AuthingGuard/LoginLayout/index.tsx +205 -0
- package/src/components/AuthingGuard/LoginLayout/style.less +0 -0
- package/src/components/AuthingGuard/MfaLayout/Steps.ts +4 -0
- package/src/components/AuthingGuard/MfaLayout/index.tsx +49 -0
- package/src/components/AuthingGuard/MfaLayout/style.less +3 -0
- package/src/components/AuthingGuard/RegisterLayout/index.tsx +89 -0
- package/src/components/AuthingGuard/RegisterLayout/style.less +0 -0
- package/src/components/AuthingGuard/ResetPwdLayout/index.tsx +20 -0
- package/src/components/AuthingGuard/ToggleLang/index.tsx +51 -0
- package/src/components/AuthingGuard/api/appConfig.ts +154 -0
- package/src/components/AuthingGuard/api/http.ts +88 -0
- package/src/components/AuthingGuard/api/index.ts +3 -0
- package/src/components/AuthingGuard/api/sso.ts +29 -0
- package/src/components/AuthingGuard/api/userPoolConfig.ts +112 -0
- package/src/components/AuthingGuard/constants.ts +107 -0
- package/src/components/AuthingGuard/hooks/index.tsx +70 -0
- package/src/components/AuthingGuard/hooks/useScreenSize.tsx +68 -0
- package/src/components/AuthingGuard/index.tsx +134 -0
- package/src/components/AuthingGuard/locales/en/common.json +185 -0
- package/src/components/AuthingGuard/locales/en/index.ts +6 -0
- package/src/components/AuthingGuard/locales/en/login.json +94 -0
- package/src/components/AuthingGuard/locales/en/map.json +4 -0
- package/src/components/AuthingGuard/locales/en/user.json +81 -0
- package/src/components/AuthingGuard/locales/index.ts +45 -0
- package/src/components/AuthingGuard/locales/zh/common.json +185 -0
- package/src/components/AuthingGuard/locales/zh/index.ts +6 -0
- package/src/components/AuthingGuard/locales/zh/login.json +94 -0
- package/src/components/AuthingGuard/locales/zh/map.json +4 -0
- package/src/components/AuthingGuard/locales/zh/user.json +81 -0
- package/src/components/AuthingGuard/style.less +108 -0
- package/src/components/AuthingGuard/types/Forms.ts +95 -0
- package/src/components/AuthingGuard/types/GuardConfig.ts +424 -0
- package/src/components/AuthingGuard/types/GuardState.ts +7 -0
- package/src/components/AuthingGuard/types/Locales.ts +12 -0
- package/src/components/AuthingGuard/types/index.ts +4 -0
- package/src/components/index.ts +7 -0
- package/src/context/base.tsx +28 -0
- package/src/context/global/context.tsx +39 -0
- package/src/context/global/reducer.tsx +56 -0
- package/src/index.tsx +142 -0
- package/src/logo.svg +7 -0
- package/src/react-app-env.d.ts +71 -0
- package/src/reportWebVitals.ts +15 -0
- package/src/setupTests.ts +5 -0
- package/src/utils/clipboard.ts +27 -0
- package/src/utils/index.ts +180 -0
- package/src/utils/popupCenter.ts +48 -0
- package/tsconfig.json +24 -0
- package/lib/static/media/loading.4a67a5f3.svg +0 -29
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
idpId,
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
state: { authClient, config },
|
|
21
|
+
} = useGuardContext()
|
|
22
|
+
|
|
23
|
+
const timerRef = useRef<any>()
|
|
24
|
+
|
|
25
|
+
const client = useMemo(() => {
|
|
26
|
+
return {
|
|
27
|
+
[LoginMethods.AppQr]: authClient.qrcode,
|
|
28
|
+
[LoginMethods.WxMinQr]: authClient.wxqrcode,
|
|
29
|
+
[LoginMethods.WechatMpQrcode]: authClient.wechatmpqrcode,
|
|
30
|
+
}[type]
|
|
31
|
+
}, [type, authClient])
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
client.startScanning('authingGuardQrcode', {
|
|
35
|
+
extIdpConnId: idpId,
|
|
36
|
+
autoExchangeUserInfo: true,
|
|
37
|
+
...config.qrCodeScanOptions,
|
|
38
|
+
onStart(timer) {
|
|
39
|
+
timerRef.current = timer
|
|
40
|
+
},
|
|
41
|
+
onSuccess(user) {
|
|
42
|
+
onSuccess && onSuccess(user as User)
|
|
43
|
+
},
|
|
44
|
+
onError: (message) => {
|
|
45
|
+
config.qrCodeScanOptions?.onError?.(message)
|
|
46
|
+
|
|
47
|
+
onFail && onFail(`${message}`)
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
return () => clearInterval(timerRef.current)
|
|
51
|
+
}, [client, config.qrCodeScanOptions, idpId, onFail, onSuccess])
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="authing-guard-qr-form">
|
|
55
|
+
<div className="authing-guard-qr-loading">
|
|
56
|
+
<Spin size="large" />
|
|
57
|
+
</div>
|
|
58
|
+
<div id="authingGuardQrcode"></div>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Button } from 'antd'
|
|
2
|
+
import React, { FC } from 'react'
|
|
3
|
+
import { useGuardContext } from '../../../../context/global/context'
|
|
4
|
+
import { GuardScenes } from '../../../../components/AuthingGuard/types'
|
|
5
|
+
|
|
6
|
+
import './style.less'
|
|
7
|
+
import { useTranslation } from 'react-i18next'
|
|
8
|
+
|
|
9
|
+
export interface RegisterFormFooterProps {
|
|
10
|
+
loading: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const RegisterFormFooter: FC<RegisterFormFooterProps> = ({
|
|
14
|
+
loading,
|
|
15
|
+
}) => {
|
|
16
|
+
const {
|
|
17
|
+
setValue,
|
|
18
|
+
state: { config },
|
|
19
|
+
} = useGuardContext()
|
|
20
|
+
const { t } = useTranslation()
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<Button
|
|
25
|
+
htmlType="submit"
|
|
26
|
+
size="large"
|
|
27
|
+
type="primary"
|
|
28
|
+
loading={loading}
|
|
29
|
+
block
|
|
30
|
+
>
|
|
31
|
+
{loading
|
|
32
|
+
? t(
|
|
33
|
+
`map.${config.text?.registerBtn?.loading}`,
|
|
34
|
+
config.text?.registerBtn?.loading
|
|
35
|
+
)
|
|
36
|
+
: t(
|
|
37
|
+
`map.${config.text?.registerBtn?.normal}`,
|
|
38
|
+
config.text?.registerBtn?.normal
|
|
39
|
+
)}
|
|
40
|
+
</Button>
|
|
41
|
+
|
|
42
|
+
<div className="authing-guard-form-actions">
|
|
43
|
+
<div className="authing-guard-tip-btn-comb">
|
|
44
|
+
<span className="authing-guard-tip">{t('common.alreadyHasAcc')}</span>
|
|
45
|
+
<Button
|
|
46
|
+
onClick={() => setValue('guardScenes', GuardScenes.Login)}
|
|
47
|
+
className="authing-guard-text-btn authing-guard-to-login-btn"
|
|
48
|
+
type="text"
|
|
49
|
+
>
|
|
50
|
+
{t('common.loginImmediate')}
|
|
51
|
+
</Button>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Button } from 'antd'
|
|
3
|
+
|
|
4
|
+
import { useGuardContext } from '../../../../context/global/context'
|
|
5
|
+
import { GuardScenes } from '../../../../components/AuthingGuard/types'
|
|
6
|
+
import { useTranslation } from 'react-i18next'
|
|
7
|
+
|
|
8
|
+
export const ResetPwdFormFooter = () => {
|
|
9
|
+
const { setValue } = useGuardContext()
|
|
10
|
+
const { t } = useTranslation()
|
|
11
|
+
return (
|
|
12
|
+
<Button
|
|
13
|
+
onClick={() => setValue('guardScenes', GuardScenes.Login)}
|
|
14
|
+
className="authing-guard-text-btn authing-guard-form-actions"
|
|
15
|
+
type="text"
|
|
16
|
+
htmlType="button"
|
|
17
|
+
>
|
|
18
|
+
{t('login.otherAccLogin')}
|
|
19
|
+
</Button>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, { FC, useState } from 'react'
|
|
2
|
+
import { Form, Input, Button, message } from 'antd'
|
|
3
|
+
|
|
4
|
+
import { validate } from '../../../../utils'
|
|
5
|
+
import {
|
|
6
|
+
ResetPasswordStep1Props,
|
|
7
|
+
ResetPwdMethods,
|
|
8
|
+
} from '../../../../components/AuthingGuard/types'
|
|
9
|
+
import { useGuardContext } from '../../../../context/global/context'
|
|
10
|
+
import { EmailScene } from 'authing-js-sdk'
|
|
11
|
+
import { useTranslation } from 'react-i18next'
|
|
12
|
+
|
|
13
|
+
export const ResetPasswordStep1: FC<ResetPasswordStep1Props> = ({
|
|
14
|
+
onSuccess,
|
|
15
|
+
}) => {
|
|
16
|
+
const {
|
|
17
|
+
state: { authClient, guardEvents },
|
|
18
|
+
} = useGuardContext()
|
|
19
|
+
const { t } = useTranslation()
|
|
20
|
+
|
|
21
|
+
const [loading, setLoading] = useState(false)
|
|
22
|
+
|
|
23
|
+
const onFinish = async (values: any) => {
|
|
24
|
+
const value = values.phoneOrEmail
|
|
25
|
+
|
|
26
|
+
if (validate('email', value)) {
|
|
27
|
+
try {
|
|
28
|
+
setLoading(true)
|
|
29
|
+
await authClient.sendEmail(value, EmailScene.ResetPassword)
|
|
30
|
+
|
|
31
|
+
guardEvents.onPwdEmailSend?.(authClient)
|
|
32
|
+
message.success(t('login.emailSent'))
|
|
33
|
+
onSuccess(ResetPwdMethods.Email, value)
|
|
34
|
+
} catch (e) {
|
|
35
|
+
guardEvents.onPwdEmailSendError?.(e, authClient)
|
|
36
|
+
} finally {
|
|
37
|
+
setLoading(false)
|
|
38
|
+
}
|
|
39
|
+
} else if (validate('phone', value)) {
|
|
40
|
+
onSuccess(ResetPwdMethods.Phone, value)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Form
|
|
46
|
+
onSubmitCapture={() => setLoading(true)}
|
|
47
|
+
onFinishFailed={() => setLoading(false)}
|
|
48
|
+
onFinish={onFinish}
|
|
49
|
+
>
|
|
50
|
+
<Form.Item
|
|
51
|
+
name="phoneOrEmail"
|
|
52
|
+
validateTrigger="onBlur"
|
|
53
|
+
rules={[
|
|
54
|
+
{
|
|
55
|
+
validator: (rule, value) => {
|
|
56
|
+
if (!value) {
|
|
57
|
+
return Promise.reject(t('login.inputPhoneOrEmail'))
|
|
58
|
+
}
|
|
59
|
+
if (validate('email', value) || validate('phone', value)) {
|
|
60
|
+
return Promise.resolve()
|
|
61
|
+
} else {
|
|
62
|
+
return Promise.reject(t('login.inputCorrectPhone'))
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
]}
|
|
67
|
+
>
|
|
68
|
+
<Input
|
|
69
|
+
size="large"
|
|
70
|
+
autoComplete="tel,email"
|
|
71
|
+
placeholder={t('login.inputPhoneOrEmail')}
|
|
72
|
+
/>
|
|
73
|
+
</Form.Item>
|
|
74
|
+
<Button
|
|
75
|
+
className="authing-reset-pwd-btn"
|
|
76
|
+
block
|
|
77
|
+
type="primary"
|
|
78
|
+
size="large"
|
|
79
|
+
htmlType="submit"
|
|
80
|
+
loading={loading}
|
|
81
|
+
>
|
|
82
|
+
{t('login.resetPwd')}
|
|
83
|
+
</Button>
|
|
84
|
+
</Form>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React, { FC, useState } from 'react'
|
|
2
|
+
import { Form, Input, Button } from 'antd'
|
|
3
|
+
import { SafetyOutlined, LockOutlined, UserOutlined } from '@ant-design/icons'
|
|
4
|
+
|
|
5
|
+
import { getRequiredRules } from '../../../../utils'
|
|
6
|
+
import { useGuardContext } from '../../../../context/global/context'
|
|
7
|
+
import { ResetPasswordStep2Props } from '../../../../components/AuthingGuard/types'
|
|
8
|
+
import { SendPhoneCode } from '../../../../components/AuthingGuard/Forms/SendPhoneCode'
|
|
9
|
+
import { useTranslation } from 'react-i18next'
|
|
10
|
+
|
|
11
|
+
export const ResetPasswordStep2: FC<ResetPasswordStep2Props> = ({
|
|
12
|
+
phone,
|
|
13
|
+
onSuccess,
|
|
14
|
+
onFail,
|
|
15
|
+
}) => {
|
|
16
|
+
const [rawForm] = Form.useForm()
|
|
17
|
+
const { t } = useTranslation()
|
|
18
|
+
|
|
19
|
+
const [loading, setLoading] = useState(false)
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
state: { authClient, guardEvents },
|
|
23
|
+
} = useGuardContext()
|
|
24
|
+
|
|
25
|
+
const onStep2Finish = async (values: any) => {
|
|
26
|
+
const code = values.code
|
|
27
|
+
const password = values.password
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await authClient.resetPasswordByPhoneCode(phone, code, password)
|
|
31
|
+
onSuccess()
|
|
32
|
+
} catch (e) {
|
|
33
|
+
onFail?.(e)
|
|
34
|
+
} finally {
|
|
35
|
+
setLoading(false)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Form
|
|
41
|
+
form={rawForm}
|
|
42
|
+
onFinishFailed={() => setLoading(false)}
|
|
43
|
+
onSubmitCapture={() => setLoading(true)}
|
|
44
|
+
onFinish={onStep2Finish}
|
|
45
|
+
>
|
|
46
|
+
<Form.Item
|
|
47
|
+
name="phone"
|
|
48
|
+
initialValue={phone}
|
|
49
|
+
rules={getRequiredRules(t('common.phoneNotNull'))}
|
|
50
|
+
>
|
|
51
|
+
<Input
|
|
52
|
+
autoComplete="tel"
|
|
53
|
+
name="phone"
|
|
54
|
+
readOnly
|
|
55
|
+
size="large"
|
|
56
|
+
placeholder={t('login.inputPhone')}
|
|
57
|
+
prefix={<UserOutlined style={{ color: '#ddd' }} />}
|
|
58
|
+
/>
|
|
59
|
+
</Form.Item>
|
|
60
|
+
<Form.Item
|
|
61
|
+
name="code"
|
|
62
|
+
rules={getRequiredRules(t('common.inputVerifyCode')).concat({
|
|
63
|
+
len: 4,
|
|
64
|
+
message: t('common.inputFourVerifyCode', {
|
|
65
|
+
length: 4,
|
|
66
|
+
}),
|
|
67
|
+
})}
|
|
68
|
+
>
|
|
69
|
+
<Input
|
|
70
|
+
name="code"
|
|
71
|
+
size="large"
|
|
72
|
+
placeholder={t('common.inputFourVerifyCode', {
|
|
73
|
+
length: 4,
|
|
74
|
+
})}
|
|
75
|
+
prefix={<SafetyOutlined style={{ color: '#ddd' }} />}
|
|
76
|
+
suffix={
|
|
77
|
+
<SendPhoneCode
|
|
78
|
+
onError={(error) =>
|
|
79
|
+
guardEvents.onPwdPhoneSendError?.(error, authClient)
|
|
80
|
+
}
|
|
81
|
+
onSend={() => guardEvents.onPwdPhoneSend?.(authClient)}
|
|
82
|
+
phone={phone}
|
|
83
|
+
/>
|
|
84
|
+
}
|
|
85
|
+
/>
|
|
86
|
+
</Form.Item>
|
|
87
|
+
<Form.Item
|
|
88
|
+
name="password"
|
|
89
|
+
rules={getRequiredRules(t('common.passwordNotNull'))}
|
|
90
|
+
>
|
|
91
|
+
<Input.Password
|
|
92
|
+
name="password"
|
|
93
|
+
size="large"
|
|
94
|
+
placeholder={t('user.newPwd')}
|
|
95
|
+
prefix={<LockOutlined style={{ color: '#ddd' }} />}
|
|
96
|
+
/>
|
|
97
|
+
</Form.Item>
|
|
98
|
+
<Form.Item
|
|
99
|
+
name="repeat-password"
|
|
100
|
+
rules={getRequiredRules(t('common.repeatPassword')).concat({
|
|
101
|
+
validator: async (rule, value) => {
|
|
102
|
+
if (rawForm.getFieldValue('password') !== value) {
|
|
103
|
+
throw new Error(t('login.twoPwdNeedSame'))
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
})}
|
|
107
|
+
>
|
|
108
|
+
<Input.Password
|
|
109
|
+
name="repeat-password"
|
|
110
|
+
size="large"
|
|
111
|
+
placeholder={t('login.inputPwdAgain')}
|
|
112
|
+
prefix={<LockOutlined style={{ color: '#ddd' }} />}
|
|
113
|
+
/>
|
|
114
|
+
</Form.Item>
|
|
115
|
+
<Button
|
|
116
|
+
className="authing-reset-pwd-btn"
|
|
117
|
+
block
|
|
118
|
+
loading={loading}
|
|
119
|
+
type="primary"
|
|
120
|
+
size="large"
|
|
121
|
+
htmlType="submit"
|
|
122
|
+
>
|
|
123
|
+
{t('login.resetPwd')}
|
|
124
|
+
</Button>
|
|
125
|
+
</Form>
|
|
126
|
+
)
|
|
127
|
+
}
|