Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
7fed4d69
authored
Sep 05, 2024
by
Archer
Committed by
GitHub
Sep 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: captcha code (#2620)
* perf: captcha code * perf: dockerfile
parent
5ed89130
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
140 additions
and
187 deletions
+140
-187
packages/web/i18n/en/common.json
+5
-2
packages/web/i18n/zh/common.json
+6
-3
projects/app/Dockerfile
+2
-2
projects/app/src/components/support/user/safe/SendCodeAuthModal.tsx
+35
-21
projects/app/src/pages/account/components/Info/UpdateNotificationModal.tsx
+5
-39
projects/app/src/pages/login/components/ForgetPasswordForm.tsx
+12
-52
projects/app/src/pages/login/components/RegisterForm.tsx
+15
-55
projects/app/src/web/support/user/api.ts
+1
-1
projects/app/src/web/support/user/hooks/useSendCode.tsx
+59
-12
No files found.
packages/web/i18n/en/common.json
View file @
7fed4d69
...
@@ -647,7 +647,8 @@
...
@@ -647,7 +647,8 @@
"success"
:
"Start syncing"
"success"
:
"Start syncing"
}
}
},
},
"training"
:
{}
"training"
:
{
}
},
},
"data"
:
{
"data"
:
{
"Auxiliary Data"
:
"Auxiliary data"
,
"Auxiliary Data"
:
"Auxiliary data"
,
...
@@ -1084,13 +1085,15 @@
...
@@ -1084,13 +1085,15 @@
"default_reply"
:
"Default reply"
,
"default_reply"
:
"Default reply"
,
"error"
:
{
"error"
:
{
"Create failed"
:
"Create failed"
,
"Create failed"
:
"Create failed"
,
"code_error"
:
"Code error"
,
"fileNotFound"
:
"File not found~"
,
"fileNotFound"
:
"File not found~"
,
"inheritPermissionError"
:
"Inherit permission Error"
,
"inheritPermissionError"
:
"Inherit permission Error"
,
"missingParams"
:
"Insufficient parameters"
,
"missingParams"
:
"Insufficient parameters"
,
"team"
:
{
"team"
:
{
"overSize"
:
"Team members exceed the limit"
"overSize"
:
"Team members exceed the limit"
},
},
"upload_file_error_filename"
:
"{{name}} upload failed"
"upload_file_error_filename"
:
"{{name}} upload failed"
,
"username_empty"
:
"Account cannot be empty"
},
},
"extraction_results"
:
"Extract results"
,
"extraction_results"
:
"Extract results"
,
"field_name"
:
"Name"
,
"field_name"
:
"Name"
,
...
...
packages/web/i18n/zh/common.json
View file @
7fed4d69
...
@@ -647,7 +647,8 @@
...
@@ -647,7 +647,8 @@
"success"
:
"开始同步"
"success"
:
"开始同步"
}
}
},
},
"training"
:
{}
"training"
:
{
}
},
},
"data"
:
{
"data"
:
{
"Auxiliary Data"
:
"辅助数据"
,
"Auxiliary Data"
:
"辅助数据"
,
...
@@ -1084,13 +1085,15 @@
...
@@ -1084,13 +1085,15 @@
"default_reply"
:
"默认回复"
,
"default_reply"
:
"默认回复"
,
"error"
:
{
"error"
:
{
"Create failed"
:
"创建失败"
,
"Create failed"
:
"创建失败"
,
"code_error"
:
"验证码错误"
,
"fileNotFound"
:
"文件找不到了~"
,
"fileNotFound"
:
"文件找不到了~"
,
"inheritPermissionError"
:
"权限继承错误"
,
"inheritPermissionError"
:
"权限继承错误"
,
"missingParams"
:
"参数缺失"
,
"missingParams"
:
"参数缺失"
,
"team"
:
{
"team"
:
{
"overSize"
:
"团队成员超出上限"
"overSize"
:
"团队成员超出上限"
},
},
"upload_file_error_filename"
:
"{{name}} 上传失败"
"upload_file_error_filename"
:
"{{name}} 上传失败"
,
"username_empty"
:
"账号不能为空"
},
},
"extraction_results"
:
"提取结果"
,
"extraction_results"
:
"提取结果"
,
"field_name"
:
"字段名"
,
"field_name"
:
"字段名"
,
...
@@ -1247,7 +1250,6 @@
...
@@ -1247,7 +1250,6 @@
},
},
"user"
:
{
"user"
:
{
"Avatar"
:
"头像"
,
"Avatar"
:
"头像"
,
"captcha_placeholder"
:
"请输入验证码"
,
"Go laf env"
:
"点击前往 {{env}} 获取 PAT 凭证。"
,
"Go laf env"
:
"点击前往 {{env}} 获取 PAT 凭证。"
,
"Laf account course"
:
"查看绑定 laf 账号教程。"
,
"Laf account course"
:
"查看绑定 laf 账号教程。"
,
"Laf account intro"
:
"绑定你的 laf 账号后,你将可以在工作流中使用 laf 模块,实现在线编写代码。"
,
"Laf account intro"
:
"绑定你的 laf 账号后,你将可以在工作流中使用 laf 模块,实现在线编写代码。"
,
...
@@ -1257,6 +1259,7 @@
...
@@ -1257,6 +1259,7 @@
"auth"
:
{
"auth"
:
{
"Sending Code"
:
"正在发送"
"Sending Code"
:
"正在发送"
},
},
"captcha_placeholder"
:
"请输入验证码"
,
"inform"
:
{
"inform"
:
{
"System message"
:
"系统消息"
"System message"
:
"系统消息"
},
},
...
...
projects/app/Dockerfile
View file @
7fed4d69
...
@@ -75,8 +75,8 @@ COPY ./projects/app/data /app/data
...
@@ -75,8 +75,8 @@ COPY ./projects/app/data /app/data
RUN
chown
-R
nextjs:nodejs /app/data
RUN
chown
-R
nextjs:nodejs /app/data
ENV
NODE_ENV
production
ENV
NODE_ENV
=
production
ENV
NEXT_TELEMETRY_DISABLED
1
ENV
NEXT_TELEMETRY_DISABLED
=
1
ENV
PORT=3000
ENV
PORT=3000
EXPOSE
3000
EXPOSE
3000
...
...
projects/app/src/components/support/user/safe/SendCodeAuthModal.tsx
View file @
7fed4d69
import
{
getCaptchaPic
}
from
'@/web/support/user/api'
;
import
{
getCaptchaPic
}
from
'@/web/support/user/api'
;
import
{
useSendCode
}
from
'@/web/support/user/hooks/useSendCode'
;
import
{
Button
,
Input
,
Image
,
ModalBody
,
ModalFooter
,
Skeleton
}
from
'@chakra-ui/react'
;
import
{
Box
,
Button
,
Input
,
Image
,
ModalBody
,
ModalFooter
}
from
'@chakra-ui/react'
;
import
{
UserAuthTypeEnum
}
from
'@fastgpt/global/support/user/auth/constants'
;
import
MyModal
from
'@fastgpt/web/components/common/MyModal'
;
import
MyModal
from
'@fastgpt/web/components/common/MyModal'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
use
State
}
from
'react
'
;
import
{
use
Form
}
from
'react-hook-form
'
;
const
SendCodeAuthModal
=
({
const
SendCodeAuthModal
=
({
username
,
username
,
type
,
onClose
,
onClose
onSending
,
onSendCode
}:
{
}:
{
username
:
string
;
username
:
string
;
type
:
UserAuthTypeEnum
;
onClose
:
()
=>
void
;
onClose
:
()
=>
void
;
onSending
:
boolean
;
onSendCode
:
(
params_0
:
{
username
:
string
;
captcha
:
string
})
=>
Promise
<
void
>
;
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
[
captchaInput
,
setCaptchaInput
]
=
useState
(
''
);
const
{
codeSending
,
sendCode
}
=
useSendCode
();
const
{
register
,
handleSubmit
}
=
useForm
({
defaultValues
:
{
code
:
''
}
});
const
{
const
{
data
,
data
,
loading
,
loading
,
runAsync
:
getCaptcha
runAsync
:
getCaptcha
}
=
useRequest2
(()
=>
getCaptchaPic
(
username
),
{
manual
:
false
});
}
=
useRequest2
(()
=>
getCaptchaPic
(
username
),
{
manual
:
false
});
return
(
return
(
<
MyModal
isOpen=
{
true
}
isLoading=
{
loading
}
>
<
MyModal
isOpen=
{
true
}
>
<
ModalBody
pt=
{
8
}
>
<
ModalBody
pt=
{
8
}
>
<
Skeleton
minH=
"200px"
isLoaded=
{
!
loading
}
fadeDuration=
{
2
}
display=
{
'flex'
}
justifyContent=
{
'center'
}
my=
{
1
}
>
<
Image
<
Image
borderRadius=
{
'md'
}
borderRadius=
{
'md'
}
w=
{
'100%'
}
w=
{
'100%'
}
...
@@ -35,24 +50,23 @@ const SendCodeAuthModal = ({
...
@@ -35,24 +50,23 @@ const SendCodeAuthModal = ({
mb=
{
8
}
mb=
{
8
}
onClick=
{
getCaptcha
}
onClick=
{
getCaptcha
}
src=
{
data
?.
captchaImage
}
src=
{
data
?.
captchaImage
}
alt=
"captcha"
alt=
""
/>
<
Input
placeholder=
{
t
(
'common:support.user.captcha_placeholder'
)
}
value=
{
captchaInput
}
onChange=
{
(
e
)
=>
setCaptchaInput
(
e
.
target
.
value
)
}
/>
/>
</
Skeleton
>
<
Input
placeholder=
{
t
(
'common:support.user.captcha_placeholder'
)
}
{
...
register
('
code
')}
/>
</
ModalBody
>
</
ModalBody
>
<
ModalFooter
gap=
{
2
}
>
<
ModalFooter
gap=
{
2
}
>
<
Button
isLoading=
{
code
Sending
}
variant=
{
'whiteBase'
}
onClick=
{
onClose
}
>
<
Button
isLoading=
{
on
Sending
}
variant=
{
'whiteBase'
}
onClick=
{
onClose
}
>
{
t
(
'common:common.Cancel'
)
}
{
t
(
'common:common.Cancel'
)
}
</
Button
>
</
Button
>
<
Button
<
Button
isLoading=
{
code
Sending
}
isLoading=
{
on
Sending
}
onClick=
{
async
(
)
=>
{
onClick=
{
handleSubmit
(({
code
}
)
=>
{
await
sendCode
({
username
,
type
,
captcha
:
captchaInput
});
return
onSendCode
({
username
,
captcha
:
code
}).
then
(()
=>
{
onClose
();
onClose
();
}
}
});
})
}
>
>
{
t
(
'common:common.Confirm'
)
}
{
t
(
'common:common.Confirm'
)
}
</
Button
>
</
Button
>
...
...
projects/app/src/pages/account/components/Info/UpdateNotificationModal.tsx
View file @
7fed4d69
...
@@ -18,8 +18,6 @@ import Icon from '@fastgpt/web/components/common/Icon';
...
@@ -18,8 +18,6 @@ import Icon from '@fastgpt/web/components/common/Icon';
import
{
useSendCode
}
from
'@/web/support/user/hooks/useSendCode'
;
import
{
useSendCode
}
from
'@/web/support/user/hooks/useSendCode'
;
import
{
useUserStore
}
from
'@/web/support/user/useUserStore'
;
import
{
useUserStore
}
from
'@/web/support/user/useUserStore'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
SendCodeAuthModal
from
'@/components/support/user/safe/SendCodeAuthModal'
;
import
{
UserAuthTypeEnum
}
from
'@fastgpt/global/support/user/auth/constants'
;
type
FormType
=
{
type
FormType
=
{
account
:
string
;
account
:
string
;
...
@@ -30,7 +28,8 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -30,7 +28,8 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
{
initUserInfo
}
=
useUserStore
();
const
{
initUserInfo
}
=
useUserStore
();
const
{
feConfigs
}
=
useSystemStore
();
const
{
feConfigs
}
=
useSystemStore
();
const
{
register
,
handleSubmit
,
trigger
,
getValues
,
watch
}
=
useForm
<
FormType
>
({
const
{
register
,
handleSubmit
,
watch
}
=
useForm
<
FormType
>
({
defaultValues
:
{
defaultValues
:
{
account
:
''
,
account
:
''
,
verifyCode
:
''
verifyCode
:
''
...
@@ -38,11 +37,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -38,11 +37,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
});
});
const
account
=
watch
(
'account'
);
const
account
=
watch
(
'account'
);
const
verifyCode
=
watch
(
'verifyCode'
);
const
verifyCode
=
watch
(
'verifyCode'
);
const
{
isOpen
:
openCodeAuthModal
,
onOpen
:
onOpenCodeAuthModal
,
onClose
:
onCloseCodeAuthModal
}
=
useDisclosure
();
const
{
runAsync
:
onSubmit
,
loading
:
isLoading
}
=
useRequest2
(
const
{
runAsync
:
onSubmit
,
loading
:
isLoading
}
=
useRequest2
(
(
data
:
FormType
)
=>
{
(
data
:
FormType
)
=>
{
return
updateNotificationAccount
(
data
);
return
updateNotificationAccount
(
data
);
...
@@ -57,13 +52,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -57,13 +52,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
}
}
);
);
const
{
sendCodeText
,
codeCountDown
}
=
useSendCode
();
const
{
SendCodeBox
}
=
useSendCode
({
type
:
'bindNotification'
});
const
onclickSendCode
=
useCallback
(
async
()
=>
{
const
check
=
await
trigger
(
'account'
);
if
(
!
check
)
return
;
onOpenCodeAuthModal
();
},
[
onOpenCodeAuthModal
,
trigger
]);
const
placeholder
=
feConfigs
?.
bind_notification_method
const
placeholder
=
feConfigs
?.
bind_notification_method
?.
map
((
item
)
=>
{
?.
map
((
item
)
=>
{
...
@@ -107,23 +96,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -107,23 +96,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
{
...
register
('
verifyCode
',
{
required
:
true
})}
{
...
register
('
verifyCode
',
{
required
:
true
})}
placeholder=
{
t
(
'user:password.code_required'
)
}
placeholder=
{
t
(
'user:password.code_required'
)
}
></
Input
>
></
Input
>
<
Box
<
SendCodeBox
username=
{
account
}
/>
position=
{
'absolute'
}
right=
{
2
}
zIndex=
{
1
}
fontSize=
{
'sm'
}
{
...
(
codeCountDown
>
0
?
{
color
:
'myGray.500'
}
:
{
color
:
'primary.700'
,
cursor
:
'pointer'
,
onClick
:
onclickSendCode
}
)}
>
{
sendCodeText
}
</
Box
>
</
Flex
>
</
Flex
>
</
Flex
>
</
Flex
>
</
ModalBody
>
</
ModalBody
>
...
@@ -140,13 +113,6 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -140,13 +113,6 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
</
Button
>
</
Button
>
</
ModalFooter
>
</
ModalFooter
>
</
MyModal
>
</
MyModal
>
{
openCodeAuthModal
&&
(
<
SendCodeAuthModal
onClose=
{
onCloseCodeAuthModal
}
username=
{
getValues
(
'account'
)
}
type=
{
UserAuthTypeEnum
.
bindNotification
}
/>
)
}
</>
</>
);
);
};
};
...
...
projects/app/src/pages/login/components/ForgetPasswordForm.tsx
View file @
7fed4d69
...
@@ -8,8 +8,8 @@ import type { ResLogin } from '@/global/support/api/userRes.d';
...
@@ -8,8 +8,8 @@ import type { ResLogin } from '@/global/support/api/userRes.d';
import
{
useToast
}
from
'@fastgpt/web/hooks/useToast'
;
import
{
useToast
}
from
'@fastgpt/web/hooks/useToast'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
UserAuthTypeEnum
}
from
'@fastgpt/global/support/user/auth/constants
'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest
'
;
import
SendCodeAuthModal
from
'@/components/support/user/safe/SendCodeAuthModal'
;
interface
Props
{
interface
Props
{
setPageType
:
Dispatch
<
`
${
LoginPageTypeEnum
}
`
>
;
setPageType
:
Dispatch
<
`
${
LoginPageTypeEnum
}
`
>
;
loginSuccess
:
(
e
:
ResLogin
)
=>
void
;
loginSuccess
:
(
e
:
ResLogin
)
=>
void
;
...
@@ -30,25 +30,15 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -30,25 +30,15 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
register
,
register
,
handleSubmit
,
handleSubmit
,
getValues
,
getValues
,
trigger
,
watch
,
formState
:
{
errors
}
formState
:
{
errors
}
}
=
useForm
<
RegisterType
>
({
}
=
useForm
<
RegisterType
>
({
mode
:
'onBlur'
mode
:
'onBlur'
});
});
const
username
=
watch
(
'username'
);
const
{
sendCodeText
,
codeCountDown
}
=
useSendCode
();
const
{
SendCodeBox
}
=
useSendCode
({
type
:
'findPassword'
});
const
{
isOpen
:
openCodeAuthModal
,
onOpen
:
onOpenCodeAuthModal
,
onClose
:
onCloseCodeAuthModal
}
=
useDisclosure
();
const
onclickSendCode
=
useCallback
(
async
()
=>
{
const
check
=
await
trigger
(
'username'
);
if
(
!
check
)
return
;
onOpenCodeAuthModal
();
},
[
onOpenCodeAuthModal
,
trigger
]);
const
[
requesting
,
setRequesting
]
=
useState
(
false
);
const
placeholder
=
feConfigs
?.
find_password_method
const
placeholder
=
feConfigs
?.
find_password_method
?.
map
((
item
)
=>
{
?.
map
((
item
)
=>
{
switch
(
item
)
{
switch
(
item
)
{
...
@@ -62,10 +52,8 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -62,10 +52,8 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
})
})
.
join
(
'/'
);
.
join
(
'/'
);
const
onclickFindPassword
=
useCallback
(
const
{
runAsync
:
onclickFindPassword
,
loading
:
requesting
}
=
useRequest2
(
async
({
username
,
code
,
password
}:
RegisterType
)
=>
{
async
({
username
,
code
,
password
}:
RegisterType
)
=>
{
setRequesting
(
true
);
try
{
loginSuccess
(
loginSuccess
(
await
postFindPassword
({
await
postFindPassword
({
username
,
username
,
...
@@ -74,18 +62,13 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -74,18 +62,13 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
})
})
);
);
toast
({
toast
({
title
:
t
(
'user:password.retrieved'
),
status
:
'success'
,
status
:
'success'
title
:
t
(
'user:password.retrieved'
)
});
}
catch
(
error
:
any
)
{
toast
({
title
:
error
.
message
||
t
(
'user:password.change_error'
),
status
:
'error'
});
});
}
setRequesting
(
false
);
},
},
[
loginSuccess
,
toast
]
{
refreshDeps
:
[
loginSuccess
,
t
,
toast
]
}
);
);
return
(
return
(
...
@@ -131,23 +114,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -131,23 +114,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
required
:
t
('
user
:
password
.
code_required
')
required
:
t
('
user
:
password
.
code_required
')
})}
})}
></
Input
>
></
Input
>
<
Box
<
SendCodeBox
username=
{
username
}
/>
position=
{
'absolute'
}
right=
{
3
}
zIndex=
{
1
}
fontSize=
{
'sm'
}
{
...
(
codeCountDown
>
0
?
{
color
:
'myGray.500'
}
:
{
color
:
'primary.700'
,
cursor
:
'pointer'
,
onClick
:
onclickSendCode
}
)}
>
{
sendCodeText
}
</
Box
>
</
FormControl
>
</
FormControl
>
<
FormControl
mt=
{
6
}
isInvalid=
{
!!
errors
.
password
}
>
<
FormControl
mt=
{
6
}
isInvalid=
{
!!
errors
.
password
}
>
<
Input
<
Input
...
@@ -203,13 +170,6 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -203,13 +170,6 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
{
t
(
'user:password.to_login'
)
}
{
t
(
'user:password.to_login'
)
}
</
Box
>
</
Box
>
</
Box
>
</
Box
>
{
openCodeAuthModal
&&
(
<
SendCodeAuthModal
onClose=
{
onCloseCodeAuthModal
}
username=
{
getValues
(
'username'
)
}
type=
{
UserAuthTypeEnum
.
findPassword
}
/>
)
}
</>
</>
);
);
};
};
...
...
projects/app/src/pages/login/components/RegisterForm.tsx
View file @
7fed4d69
import
React
,
{
useState
,
Dispatch
,
useCallback
}
from
'react'
;
import
React
,
{
Dispatch
}
from
'react'
;
import
{
FormControl
,
Box
,
Input
,
Button
,
useDisclosure
}
from
'@chakra-ui/react'
;
import
{
FormControl
,
Box
,
Input
,
Button
}
from
'@chakra-ui/react'
;
import
{
useForm
}
from
'react-hook-form'
;
import
{
useForm
}
from
'react-hook-form'
;
import
{
LoginPageTypeEnum
}
from
'@/web/support/user/login/constants'
;
import
{
LoginPageTypeEnum
}
from
'@/web/support/user/login/constants'
;
import
{
postRegister
}
from
'@/web/support/user/api'
;
import
{
postRegister
}
from
'@/web/support/user/api'
;
...
@@ -12,8 +12,7 @@ import { useSystemStore } from '@/web/common/system/useSystemStore';
...
@@ -12,8 +12,7 @@ import { useSystemStore } from '@/web/common/system/useSystemStore';
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
AppTypeEnum
}
from
'@fastgpt/global/core/app/constants'
;
import
{
AppTypeEnum
}
from
'@fastgpt/global/core/app/constants'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
SendCodeAuthModal
from
'@/components/support/user/safe/SendCodeAuthModal'
;
import
{
UserAuthTypeEnum
}
from
'@fastgpt/global/support/user/auth/constants'
;
interface
Props
{
interface
Props
{
loginSuccess
:
(
e
:
ResLogin
)
=>
void
;
loginSuccess
:
(
e
:
ResLogin
)
=>
void
;
setPageType
:
Dispatch
<
`
${
LoginPageTypeEnum
}
`
>
;
setPageType
:
Dispatch
<
`
${
LoginPageTypeEnum
}
`
>
;
...
@@ -35,30 +34,17 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -35,30 +34,17 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
register
,
register
,
handleSubmit
,
handleSubmit
,
getValues
,
getValues
,
trigger
,
watch
,
formState
:
{
errors
}
formState
:
{
errors
}
}
=
useForm
<
RegisterType
>
({
}
=
useForm
<
RegisterType
>
({
mode
:
'onBlur'
mode
:
'onBlur'
});
});
const
{
const
username
=
watch
(
'username'
);
isOpen
:
openCodeAuthModal
,
onOpen
:
onOpenCodeAuthModal
,
onClose
:
onCloseCodeAuthModal
}
=
useDisclosure
();
const
{
sendCodeText
,
codeCountDown
}
=
useSendCode
();
const
onclickSendCode
=
useCallback
(
async
()
=>
{
const
{
SendCodeBox
}
=
useSendCode
({
type
:
'register'
});
const
check
=
await
trigger
(
'username'
);
if
(
!
check
)
return
;
onOpenCodeAuthModal
();
},
[
onOpenCodeAuthModal
,
trigger
]);
const
[
requesting
,
setRequesting
]
=
useState
(
false
);
const
{
runAsync
:
onclickRegister
,
loading
:
requesting
}
=
useRequest2
(
const
onclickRegister
=
useCallback
(
async
({
username
,
password
,
code
}:
RegisterType
)
=>
{
async
({
username
,
password
,
code
}:
RegisterType
)
=>
{
setRequesting
(
true
);
try
{
loginSuccess
(
loginSuccess
(
await
postRegister
({
await
postRegister
({
username
,
username
,
...
@@ -67,10 +53,12 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -67,10 +53,12 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
inviterId
:
localStorage
.
getItem
(
'inviterId'
)
||
undefined
inviterId
:
localStorage
.
getItem
(
'inviterId'
)
||
undefined
})
})
);
);
toast
({
toast
({
title
:
t
(
'user:register.success'
)
,
status
:
'success'
,
status
:
'success'
title
:
t
(
'user:register.success'
)
});
});
// auto register template app
// auto register template app
setTimeout
(()
=>
{
setTimeout
(()
=>
{
Object
.
entries
(
emptyTemplates
).
map
(([
type
,
emptyTemplate
])
=>
{
Object
.
entries
(
emptyTemplates
).
map
(([
type
,
emptyTemplate
])
=>
{
...
@@ -83,15 +71,10 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -83,15 +71,10 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
});
});
});
});
},
100
);
},
100
);
}
catch
(
error
:
any
)
{
toast
({
title
:
error
.
message
||
t
(
'user:register.error'
),
status
:
'error'
});
}
setRequesting
(
false
);
},
},
[
loginSuccess
,
t
,
toast
]
{
refreshDeps
:
[
loginSuccess
,
t
,
toast
]
}
);
);
const
placeholder
=
feConfigs
?.
register_method
const
placeholder
=
feConfigs
?.
register_method
...
@@ -148,23 +131,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -148,23 +131,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
required
:
t
('
user
:
password
.
code_required
')
required
:
t
('
user
:
password
.
code_required
')
})}
})}
></
Input
>
></
Input
>
<
Box
<
SendCodeBox
username=
{
username
}
/>
position=
{
'absolute'
}
right=
{
3
}
zIndex=
{
1
}
fontSize=
{
'sm'
}
{
...
(
codeCountDown
>
0
?
{
color
:
'myGray.500'
}
:
{
color
:
'primary.700'
,
cursor
:
'pointer'
,
onClick
:
onclickSendCode
}
)}
>
{
sendCodeText
}
</
Box
>
</
FormControl
>
</
FormControl
>
<
FormControl
mt=
{
6
}
isInvalid=
{
!!
errors
.
password
}
>
<
FormControl
mt=
{
6
}
isInvalid=
{
!!
errors
.
password
}
>
<
Input
<
Input
...
@@ -219,13 +186,6 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -219,13 +186,6 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
{
t
(
'user:register.to_login'
)
}
{
t
(
'user:register.to_login'
)
}
</
Box
>
</
Box
>
</
Box
>
</
Box
>
{
openCodeAuthModal
&&
(
<
SendCodeAuthModal
onClose=
{
onCloseCodeAuthModal
}
username=
{
getValues
(
'username'
)
}
type=
{
UserAuthTypeEnum
.
register
}
/>
)
}
</>
</>
);
);
};
};
...
...
projects/app/src/web/support/user/api.ts
View file @
7fed4d69
...
@@ -87,4 +87,4 @@ export const getWXLoginResult = (code: string) =>
...
@@ -87,4 +87,4 @@ export const getWXLoginResult = (code: string) =>
export
const
getCaptchaPic
=
(
username
:
string
)
=>
export
const
getCaptchaPic
=
(
username
:
string
)
=>
GET
<
{
GET
<
{
captchaImage
:
string
;
captchaImage
:
string
;
}
>
(
'/proApi/support/user/account/captcha'
,
{
username
});
}
>
(
'/proApi/support/user/account/captcha
/getImgCaptcha
'
,
{
username
});
projects/app/src/web/support/user/hooks/useSendCode.ts
→
projects/app/src/web/support/user/hooks/useSendCode.ts
x
View file @
7fed4d69
...
@@ -4,26 +4,24 @@ import { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants';
...
@@ -4,26 +4,24 @@ import { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants';
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
{
Box
,
BoxProps
,
useDisclosure
}
from
'@chakra-ui/react'
;
import
SendCodeAuthModal
from
'@/components/support/user/safe/SendCodeAuthModal'
;
import
{
useMemoizedFn
}
from
'ahooks'
;
import
{
useToast
}
from
'@fastgpt/web/hooks/useToast'
;
let
timer
:
NodeJS
.
Timeout
;
let
timer
:
NodeJS
.
Timeout
;
export
const
useSendCode
=
()
=>
{
export
const
useSendCode
=
(
{
type
}:
{
type
:
`
${
UserAuthTypeEnum
}
`
}
)
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
{
feConfigs
}
=
useSystemStore
();
const
{
feConfigs
}
=
useSystemStore
();
const
{
toast
}
=
useToast
();
const
[
codeCountDown
,
setCodeCountDown
]
=
useState
(
0
);
const
[
codeCountDown
,
setCodeCountDown
]
=
useState
(
0
);
const
{
runAsync
:
sendCode
,
loading
:
codeSending
}
=
useRequest2
(
const
{
runAsync
:
sendCode
,
loading
:
codeSending
}
=
useRequest2
(
async
({
async
({
username
,
captcha
}:
{
username
:
string
;
captcha
:
string
})
=>
{
username
,
type
,
captcha
}:
{
username
:
string
;
type
:
`
${
UserAuthTypeEnum
}
`
;
captcha
:
string
;
})
=>
{
if
(
codeCountDown
>
0
)
return
;
if
(
codeCountDown
>
0
)
return
;
const
googleToken
=
await
getClientToken
(
feConfigs
.
googleClientVerKey
);
const
googleToken
=
await
getClientToken
(
feConfigs
.
googleClientVerKey
);
await
sendAuthCode
({
username
,
type
,
googleToken
,
captcha
});
await
sendAuthCode
({
username
,
type
,
googleToken
,
captcha
});
setCodeCountDown
(
60
);
setCodeCountDown
(
60
);
timer
=
setInterval
(()
=>
{
timer
=
setInterval
(()
=>
{
...
@@ -38,7 +36,7 @@ export const useSendCode = () => {
...
@@ -38,7 +36,7 @@ export const useSendCode = () => {
{
{
successToast
:
t
(
'user:password.code_sended'
),
successToast
:
t
(
'user:password.code_sended'
),
errorToast
:
t
(
'user:password.code_send_error'
),
errorToast
:
t
(
'user:password.code_send_error'
),
refreshDeps
:
[
codeCountDown
,
feConfigs
?.
googleClientVerKey
]
refreshDeps
:
[
codeCountDown
,
type
,
feConfigs
?.
googleClientVerKey
]
}
}
);
);
...
@@ -53,11 +51,60 @@ export const useSendCode = () => {
...
@@ -53,11 +51,60 @@ export const useSendCode = () => {
return
t
(
'user:password.get_code'
);
return
t
(
'user:password.get_code'
);
},
[
codeCountDown
,
codeSending
,
t
]);
},
[
codeCountDown
,
codeSending
,
t
]);
const
{
isOpen
:
openCodeAuthModal
,
onOpen
:
onOpenCodeAuthModal
,
onClose
:
onCloseCodeAuthModal
}
=
useDisclosure
();
const
SendCodeBox
=
useMemoizedFn
(({
username
,
...
styles
}:
BoxProps
&
{
username
:
string
})
=>
{
return
(
<>
<
Box
position=
{
'absolute'
}
right=
{
3
}
zIndex=
{
1
}
fontSize=
{
'sm'
}
{
...
styles
}
{
...
(
codeCountDown
>
0
?
{
color
:
'myGray.500'
}
:
{
color
:
'primary.700'
,
cursor
:
'pointer'
,
onClick
:
()
=>
{
if
(
!
username
)
{
toast
({
status
:
'warning'
,
title
:
t
(
'common:error.username_empty'
)
});
}
else
{
onOpenCodeAuthModal
();
}
}
}
)}
>
{
sendCodeText
}
</
Box
>
{
openCodeAuthModal
&&
(
<
SendCodeAuthModal
onClose=
{
onCloseCodeAuthModal
}
username=
{
username
}
onSending=
{
codeSending
}
onSendCode=
{
sendCode
}
/>
)
}
</>
);
});
return
{
return
{
codeSending
,
codeSending
,
sendCode
,
sendCode
,
sendCodeText
,
sendCodeText
,
codeCountDown
codeCountDown
,
SendCodeBox
};
};
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment