mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-28 00:56:26 +00:00
fix: change ip detect url (#2827)
This commit is contained in:
@@ -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 }) => {
|
|||||||
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 }) => {
|
|||||||
|
|
||||||
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 }) => {
|
|||||||
></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 }) => {
|
|||||||
|
|
||||||
{isOpen && <CommunityModal onClose={onClose} />}
|
{isOpen && <CommunityModal onClose={onClose} />}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{showRedirect && (
|
{showRedirect && (
|
||||||
<RedirectDrawer
|
<RedirectDrawer
|
||||||
isOpen={isOpenRedirect}
|
isOpen={isOpenRedirect}
|
||||||
|
Reference in New Issue
Block a user