From 841475b3054471566f9130ca1a314fd5c9a0fca1 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 4 Mar 2024 10:49:24 +0800 Subject: [PATCH 1/3] Fix: verify email page - error hint --- src/pages/Sign/Verify.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pages/Sign/Verify.tsx b/src/pages/Sign/Verify.tsx index be3ef19..26efe94 100644 --- a/src/pages/Sign/Verify.tsx +++ b/src/pages/Sign/Verify.tsx @@ -2,6 +2,7 @@ import { COLOR_BACKGROUND, PERMISSION_ACCOUNT_NEED_INIT, PERMISSION_NO_VERIFICATION_REQUIRED, + PERMISSION_RESEND_SUCCESS, PERMISSION_VERIFY_SUCCESS, SYSTEM_MATCH_SENSITIVE_WORD } from '@/constants/common.constants' @@ -74,10 +75,16 @@ const Verify = () => { void r_auth_resend() .then((res) => { const response = res.data - if (response.success) { - void message.success('已发送验证邮件,请查收') - } else { - void message.error('出错了,请稍后重试') + switch (response.code) { + case PERMISSION_RESEND_SUCCESS: + void message.success('已发送验证邮件,请查收') + break + case PERMISSION_NO_VERIFICATION_REQUIRED: + void message.warning('账户已验证') + navigate('/') + break + default: + void message.error('出错了,请稍后重试') } }) .finally(() => { -- 2.49.1 From db28fba694148952d65d0dfada96ed5000dcc485 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 4 Mar 2024 14:48:04 +0800 Subject: [PATCH 2/3] Fix: sign page - turnstile on every page load at the same time --- src/assets/css/pages/sign.scss | 5 --- src/pages/Sign/Forget.tsx | 79 +++++++++++++++------------------- src/pages/Sign/SignIn.tsx | 44 +++++++++---------- src/pages/Sign/SignUp.tsx | 45 ++++++++++--------- 4 files changed, 78 insertions(+), 95 deletions(-) diff --git a/src/assets/css/pages/sign.scss b/src/assets/css/pages/sign.scss index 96ffe38..ad54058 100644 --- a/src/assets/css/pages/sign.scss +++ b/src/assets/css/pages/sign.scss @@ -85,11 +85,6 @@ } .sign-up, .sign-in, .forget { - .loading-turnstile { - display: flex; - justify-content: center; - } - .footer { a { font-weight: bolder; diff --git a/src/pages/Sign/Forget.tsx b/src/pages/Sign/Forget.tsx index 63d7121..b84290a 100644 --- a/src/pages/Sign/Forget.tsx +++ b/src/pages/Sign/Forget.tsx @@ -6,7 +6,6 @@ import { PERMISSION_RETRIEVE_CODE_ERROR_OR_EXPIRED, PERMISSION_RETRIEVE_SUCCESS, PERMISSION_USER_NOT_FOUND, - SIZE_ICON_MD, SYSTEM_INVALID_CAPTCHA_CODE } from '@/constants/common.constants' import { r_auth_forget, r_auth_retrieve } from '@/services/auth' @@ -17,27 +16,8 @@ const Forget = () => { const navigate = useNavigate() const [searchParams] = useSearchParams() const turnstileRef = useRef() - const turnstileRefCallback = useCallback( - (node: TurnstileInstance) => { - turnstileRef.current = node - - if (location.pathname === '/forget' && !searchParams.get('code')) { - turnstileRef.current?.execute() - } - }, - [location.pathname, searchParams] - ) const retrieveTurnstileRef = useRef() - const retrieveTurnstileRefCallback = useCallback( - (node: TurnstileInstance) => { - retrieveTurnstileRef.current = node - - if (location.pathname === '/forget' && searchParams.get('code')) { - retrieveTurnstileRef.current?.execute() - } - }, - [location.pathname, searchParams] - ) + const [refreshTime, setRefreshTime] = useState(0) const [isSending, setIsSending] = useState(false) const [isSent, setIsSent] = useState(false) const [isChanging, setIsChanging] = useState(false) @@ -45,6 +25,25 @@ const Forget = () => { const [captchaCode, setCaptchaCode] = useState('') const [retrieveCaptchaCode, setRetrieveCaptchaCode] = useState('') + useEffect(() => { + const timer = setInterval(() => { + if (window.turnstile) { + clearInterval(timer) + setRefreshTime(Date.now()) + if (location.pathname === '/forget' && !searchParams.get('code')) { + setTimeout(() => { + turnstileRef.current?.execute() + }, 500) + } + if (location.pathname === '/forget' && searchParams.get('code')) { + setTimeout(() => { + retrieveTurnstileRef.current?.execute() + }, 500) + } + } + }) + }, [location.pathname]) + useEffect(() => { if (!isSending) { setCaptchaCode('') @@ -161,22 +160,17 @@ const Forget = () => { /> - {!turnstileRef.current && ( -
- -
- )}
@@ -243,22 +237,17 @@ const Forget = () => { /> - {!turnstileRef.current && ( -
- -
- )}
diff --git a/src/pages/Sign/SignIn.tsx b/src/pages/Sign/SignIn.tsx index 854886e..0eaac4e 100644 --- a/src/pages/Sign/SignIn.tsx +++ b/src/pages/Sign/SignIn.tsx @@ -8,7 +8,6 @@ import { PERMISSION_TWO_FACTOR_VERIFICATION_CODE_ERROR, PERMISSION_USER_DISABLE, PERMISSION_USERNAME_NOT_FOUND, - SIZE_ICON_MD, SYSTEM_INVALID_CAPTCHA_CODE } from '@/constants/common.constants' import { getUserInfo, setToken } from '@/util/auth' @@ -24,19 +23,25 @@ const SignIn = () => { const navigate = useNavigate() const [searchParams] = useSearchParams() const turnstileRef = useRef() - const turnstileRefCallback = useCallback( - (node: TurnstileInstance) => { - turnstileRef.current = node - if (location.pathname === '/login') { - turnstileRef.current?.execute() - } - }, - [location.pathname] - ) + const [refreshTime, setRefreshTime] = useState(0) const [twoFactorForm] = AntdForm.useForm<{ twoFactorCode: string }>() const [isSigningIn, setIsSigningIn] = useState(false) const [captchaCode, setCaptchaCode] = useState('') + useEffect(() => { + const timer = setInterval(() => { + if (window.turnstile) { + clearInterval(timer) + setRefreshTime(Date.now()) + if (location.pathname === '/login') { + setTimeout(() => { + turnstileRef.current?.execute() + }, 500) + } + } + }) + }, [location.pathname]) + useEffect(() => { if (!isSigningIn) { setCaptchaCode('') @@ -227,22 +232,17 @@ const SignIn = () => { /> - {!turnstileRef.current && ( -
- -
- )}
diff --git a/src/pages/Sign/SignUp.tsx b/src/pages/Sign/SignUp.tsx index 23ce21b..4a52b4e 100644 --- a/src/pages/Sign/SignUp.tsx +++ b/src/pages/Sign/SignUp.tsx @@ -4,7 +4,6 @@ import { DATABASE_DUPLICATE_KEY, H_CAPTCHA_SITE_KEY, PERMISSION_REGISTER_SUCCESS, - SIZE_ICON_MD, SYSTEM_INVALID_CAPTCHA_CODE, SYSTEM_MATCH_SENSITIVE_WORD } from '@/constants/common.constants' @@ -17,21 +16,26 @@ const SignUp = () => { const location = useLocation() const navigate = useNavigate() const turnstileRef = useRef() - const turnstileRefCallback = useCallback( - (node: TurnstileInstance) => { - turnstileRef.current = node - - if (location.pathname === '/register') { - turnstileRef.current?.execute() - } - }, - [location.pathname] - ) + const [refreshTime, setRefreshTime] = useState(0) const [isSigningUp, setIsSigningUp] = useState(false) const [isFinish, setIsFinish] = useState(false) const [isSending, setIsSending] = useState(false) const [captchaCode, setCaptchaCode] = useState('') + useEffect(() => { + const timer = setInterval(() => { + if (window.turnstile) { + clearInterval(timer) + setRefreshTime(Date.now()) + if (location.pathname === '/register') { + setTimeout(() => { + turnstileRef.current?.execute() + }, 500) + } + } + }) + }, [location.pathname]) + useEffect(() => { if (!isSigningUp) { setCaptchaCode('') @@ -201,22 +205,17 @@ const SignUp = () => { /> - {!turnstileRef.current && ( -
- -
- )}
-- 2.49.1 From 65fc6e9c287e8db8e350d0a1cfd6990d7660f286 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 4 Mar 2024 15:01:38 +0800 Subject: [PATCH 3/3] Optimize: two-factor - remove autocomplete when typing --- src/pages/Sign/Forget.tsx | 2 ++ src/pages/Sign/SignIn.tsx | 6 +++++- src/pages/Sign/SignUp.tsx | 2 ++ src/pages/User/index.tsx | 12 ++++++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pages/Sign/Forget.tsx b/src/pages/Sign/Forget.tsx index b84290a..4c1f4ca 100644 --- a/src/pages/Sign/Forget.tsx +++ b/src/pages/Sign/Forget.tsx @@ -204,6 +204,7 @@ const Forget = () => { ]} > 新  密  码 } @@ -231,6 +232,7 @@ const Forget = () => { ]} > { style={{ marginTop: 10 }} rules={[{ required: true, len: 6 }]} > - + diff --git a/src/pages/Sign/SignUp.tsx b/src/pages/Sign/SignUp.tsx index 4a52b4e..99d6db4 100644 --- a/src/pages/Sign/SignUp.tsx +++ b/src/pages/Sign/SignUp.tsx @@ -177,6 +177,7 @@ const SignUp = () => { ]} > } placeholder={'密码'} disabled={isSigningUp} @@ -199,6 +200,7 @@ const SignUp = () => { ]} > } placeholder={'确认密码'} disabled={isSigningUp} diff --git a/src/pages/User/index.tsx b/src/pages/User/index.tsx index 249247f..6d4c2fd 100644 --- a/src/pages/User/index.tsx +++ b/src/pages/User/index.tsx @@ -257,7 +257,11 @@ const User = () => { style={{ marginTop: 10 }} rules={[{ required: true, len: 6 }]} > - + @@ -336,7 +340,11 @@ const User = () => { style={{ marginTop: 10, marginRight: 30 }} rules={[{ required: true, len: 6 }]} > - + -- 2.49.1