7
7
StyledRouteLinkLogin ,
8
8
TermsAndPrivacyInfo ,
9
9
} from "pages/userAuth/authComponents" ;
10
- import { FormInput , messageInstance , PasswordInput } from "lowcoder-design" ;
10
+ import { CustomModal , FormInput , messageInstance , PasswordInput } from "lowcoder-design" ;
11
11
import { AUTH_LOGIN_URL , ORG_AUTH_LOGIN_URL } from "constants/routesURL" ;
12
12
import UserApi from "api/userApi" ;
13
13
import { useRedirectUrl } from "util/hooks" ;
@@ -31,6 +31,8 @@ import { getServerSettings } from "@lowcoder-ee/redux/selectors/applicationSelec
31
31
import { useEnterpriseContext } from "@lowcoder-ee/util/context/EnterpriseContext" ;
32
32
import { fetchConfigAction } from "@lowcoder-ee/redux/reduxActions/configActions" ;
33
33
import { fetchOrgPaginationByEmail } from "@lowcoder-ee/util/pagination/axios" ;
34
+ import { EmailVerifyApi } from "@lowcoder-ee/api/emailVerifyApi" ;
35
+ import Typography from "antd/es/typography" ;
34
36
35
37
const StyledFormInput = styled ( FormInput ) `
36
38
margin-bottom: 16px;
@@ -57,6 +59,7 @@ function UserRegister() {
57
59
const [ password , setPassword ] = useState ( "" ) ;
58
60
const [ orgLoading , setOrgLoading ] = useState ( false ) ;
59
61
const [ lastEmailChecked , setLastEmailChecked ] = useState ( "" ) ;
62
+ const [ emailVerified , setEmailVerified ] = useState ( true ) ;
60
63
const [ signupEnabled , setSignupEnabled ] = useState < boolean > ( true ) ;
61
64
const [ signinEnabled , setSigninEnabled ] = useState < boolean > ( true ) ;
62
65
const [ defaultOrgId , setDefaultOrgId ] = useState < string | undefined > ( ) ;
@@ -159,27 +162,62 @@ function UserRegister() {
159
162
afterLoginSuccess ,
160
163
) ;
161
164
162
- const checkEmailExist = ( ) => {
165
+ const checkEmailExist = async ( ) => {
163
166
if ( ! Boolean ( account . length ) || lastEmailChecked === account || isEnterpriseMode ) return ;
164
-
165
167
setOrgLoading ( true ) ;
166
- OrgApi . fetchOrgsByEmail ( account )
167
- . then ( ( resp ) => {
168
- if ( validateResponse ( resp ) ) {
169
- const orgList = resp . data . data ;
170
- if ( orgList . length ) {
171
- messageInstance . error ( 'Email is already registered' ) ;
172
- history . push (
173
- AUTH_LOGIN_URL ,
174
- { ...location . state || { } , email : account } ,
175
- )
176
- }
168
+ try {
169
+ const resp = await OrgApi . fetchOrgsByEmail ( account ) ;
170
+ if ( validateResponse ( resp ) ) {
171
+ const orgList = resp . data . data ;
172
+ if ( orgList . length ) {
173
+ messageInstance . error ( trans ( 'userAuth.emailAlreadyExist' ) ) ;
174
+ history . push (
175
+ AUTH_LOGIN_URL ,
176
+ { ...location . state || { } , email : account } ,
177
+ )
178
+ throw new Error ( trans ( 'userAuth.emailAlreadyExist' ) ) ;
177
179
}
178
- } )
179
- . finally ( ( ) => {
180
- setLastEmailChecked ( account )
181
- setOrgLoading ( false ) ;
180
+ }
181
+ } finally {
182
+ setLastEmailChecked ( account )
183
+ setOrgLoading ( false ) ;
184
+ }
185
+ }
186
+
187
+ const verifyEmail = async ( ) => {
188
+ if ( ! Boolean ( account . length ) || lastEmailChecked === account ) return ;
189
+ try {
190
+ const resp = await EmailVerifyApi . quickVerification ( account ) ;
191
+ if ( resp ?. data ?. status === "valid" ) return ;
192
+
193
+ setEmailVerified ( false ) ;
194
+ CustomModal . confirm ( {
195
+ title : trans ( "userAuth.emailVerificationFailed" ) ,
196
+ content : trans ( "userAuth.emailVerificationFailedText" ) ,
197
+ confirmBtnType : "normal" ,
198
+ okText : trans ( "componentDoc.close" ) ,
199
+ showCancelButton : false ,
182
200
} ) ;
201
+ throw new Error ( trans ( "userAuth.emailVerificationFailed" ) ) ;
202
+ } catch ( error ) {
203
+ throw error ;
204
+ }
205
+ }
206
+
207
+ const handleEmailBlur = async ( ) => {
208
+ try {
209
+ await checkEmailExist ( ) ;
210
+ } catch ( error ) {
211
+ console . error ( error ) ;
212
+ return ;
213
+ }
214
+
215
+ try {
216
+ await verifyEmail ( ) ;
217
+ } catch ( error ) {
218
+ console . error ( error ) ;
219
+ return ;
220
+ }
183
221
}
184
222
185
223
const registerHeading = trans ( "userAuth.register" )
@@ -201,7 +239,7 @@ function UserRegister() {
201
239
label = { trans ( "userAuth.email" ) }
202
240
defaultValue = { account }
203
241
onChange = { ( value , valid ) => setAccount ( valid ? value : "" ) }
204
- onBlur = { checkEmailExist }
242
+ onBlur = { handleEmailBlur }
205
243
placeholder = { trans ( "userAuth.inputEmail" ) }
206
244
checkRule = { {
207
245
check : checkEmailValid ,
@@ -217,7 +255,7 @@ function UserRegister() {
217
255
doubleCheck
218
256
/>
219
257
< ConfirmButton
220
- disabled = { ! account || ! password || submitBtnDisable }
258
+ disabled = { ! account || ! password || submitBtnDisable || ! emailVerified }
221
259
onClick = { onSubmit }
222
260
loading = { loading }
223
261
>
0 commit comments