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
3e64f46d
authored
Sep 27, 2024
by
papapatrick
Committed by
GitHub
Sep 27, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: change ip detect url (#2827)
parent
0335f167
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
26 deletions
+20
-26
projects/app/src/pages/login/index.tsx
+20
-26
No files found.
projects/app/src/pages/login/index.tsx
View file @
3e64f46d
...
@@ -26,12 +26,15 @@ import { useLocalStorageState, useMount } from 'ahooks';
...
@@ -26,12 +26,15 @@ import { useLocalStorageState, useMount } from 'ahooks';
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
I18nLngSelector
from
'@/components/Select/I18nLngSelector'
;
import
I18nLngSelector
from
'@/components/Select/I18nLngSelector'
;
import
{
useSystem
}
from
'@fastgpt/web/hooks/useSystem'
;
import
{
useSystem
}
from
'@fastgpt/web/hooks/useSystem'
;
import
{
GET
}
from
'@/web/common/api/request'
;
const
RegisterForm
=
dynamic
(()
=>
import
(
'./components/RegisterForm'
));
const
RegisterForm
=
dynamic
(()
=>
import
(
'./components/RegisterForm'
));
const
ForgetPasswordForm
=
dynamic
(()
=>
import
(
'./components/ForgetPasswordForm'
));
const
ForgetPasswordForm
=
dynamic
(()
=>
import
(
'./components/ForgetPasswordForm'
));
const
WechatForm
=
dynamic
(()
=>
import
(
'./components/LoginForm/WechatForm'
));
const
WechatForm
=
dynamic
(()
=>
import
(
'./components/LoginForm/WechatForm'
));
const
CommunityModal
=
dynamic
(()
=>
import
(
'@/components/CommunityModal'
));
const
CommunityModal
=
dynamic
(()
=>
import
(
'@/components/CommunityModal'
));
const
ipDetectURL
=
'https://qifu-api.baidubce.com/ip/local/geo/v1/district'
;
const
Login
=
({
ChineseRedirectUrl
}:
{
ChineseRedirectUrl
:
string
})
=>
{
const
Login
=
({
ChineseRedirectUrl
}:
{
ChineseRedirectUrl
:
string
})
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
...
@@ -48,6 +51,21 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
...
@@ -48,6 +51,21 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
onClose
:
onCloseRedirect
onClose
:
onCloseRedirect
}
=
useDisclosure
();
}
=
useDisclosure
();
const
[
showRedirect
,
setShowRedirect
]
=
useLocalStorageState
<
boolean
>
(
'showRedirect'
,
{
defaultValue
:
true
});
const
checkIpInChina
=
useCallback
(
()
=>
GET
(
ipDetectURL
).
then
((
res
:
any
)
=>
{
const
country
=
res
?.
country
;
if
(
country
&&
country
===
'中国'
&&
res
.
city
!==
'中国香港'
)
{
onOpenRedirect
();
}
}),
[
onOpenRedirect
]
);
const
loginSuccess
=
useCallback
(
const
loginSuccess
=
useCallback
(
(
res
:
ResLogin
)
=>
{
(
res
:
ResLogin
)
=>
{
// init store
// init store
...
@@ -85,27 +103,10 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
...
@@ -85,27 +103,10 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
useMount
(()
=>
{
useMount
(()
=>
{
clearToken
();
clearToken
();
ChineseRedirectUrl
&&
showRedirect
&&
checkIpInChina
();
router
.
prefetch
(
'/app/list'
);
router
.
prefetch
(
'/app/list'
);
});
});
const
[
showRedirect
,
setShowRedirect
]
=
useLocalStorageState
<
boolean
>
(
'chinese_ip_redirect'
,
{
defaultValue
:
true
});
const
checkIpInChina
=
useCallback
(()
=>
{
const
onSuccess
=
(
res
:
any
)
=>
{
if
(
!
res
.
country
.
iso_code
)
{
return
;
}
const
country
=
res
.
country
.
iso_code
.
toLowerCase
();
if
(
country
===
'cn'
)
{
onOpenRedirect
();
}
};
const
onError
=
(
e
:
any
)
=>
console
.
log
(
e
);
geoip2
&&
geoip2
.
country
(
onSuccess
,
onError
);
},
[
onOpenRedirect
]);
return
(
return
(
<>
<>
{
feConfigs
.
googleClientVerKey
&&
(
{
feConfigs
.
googleClientVerKey
&&
(
...
@@ -114,14 +115,6 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
...
@@ -114,14 +115,6 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
></
Script
>
></
Script
>
)
}
)
}
{
ChineseRedirectUrl
&&
showRedirect
&&
(
<
Script
src=
"//geoip-js.com/js/apis/geoip2/v2.1/geoip2.js"
type=
"text/javascript"
onLoad=
{
checkIpInChina
}
></
Script
>
)
}
<
Flex
<
Flex
alignItems=
{
'center'
}
alignItems=
{
'center'
}
justifyContent=
{
'center'
}
justifyContent=
{
'center'
}
...
@@ -174,6 +167,7 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
...
@@ -174,6 +167,7 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
{
isOpen
&&
<
CommunityModal
onClose=
{
onClose
}
/>
}
{
isOpen
&&
<
CommunityModal
onClose=
{
onClose
}
/>
}
</
Flex
>
</
Flex
>
{
showRedirect
&&
(
{
showRedirect
&&
(
<
RedirectDrawer
<
RedirectDrawer
isOpen=
{
isOpenRedirect
}
isOpen=
{
isOpenRedirect
}
...
...
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