From e379f71efbea7c0cf331c3cdf6bf69c5768ca1bd Mon Sep 17 00:00:00 2001 From: Lazy <2211717435@qq.com> Date: Sat, 13 Jan 2024 20:41:16 +0800 Subject: [PATCH] Fix: banned user login --- frontend/src/stores/useAppStateStore.ts | 19 ++++++++++++------- frontend/src/widgets/LoginCard.vue | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/frontend/src/stores/useAppStateStore.ts b/frontend/src/stores/useAppStateStore.ts index e829a1ff..3a6bccc6 100644 --- a/frontend/src/stores/useAppStateStore.ts +++ b/frontend/src/stores/useAppStateStore.ts @@ -31,15 +31,20 @@ export const useAppStateStore = createGlobalState(() => { const isLogged = computed(() => Number(state.userInfo?.permission) > 0); const updateUserInfo = async (userInfo?: LoginUserInfo) => { - if (userInfo) { - state.userInfo = userInfo; - } else { - const info = await reqUserInfo(); - if (info.value) { - state.userInfo = info.value; + try { + if (userInfo) { + state.userInfo = userInfo; } else { - throw new Error("Failed to get user information from server!"); + const info = await reqUserInfo(); + if (info.value) { + state.userInfo = info.value; + } else { + throw new Error("Failed to get user information from server!"); + } } + } catch (err: any) { + console.error(err); + throw new Error(err.message); } }; diff --git a/frontend/src/widgets/LoginCard.vue b/frontend/src/widgets/LoginCard.vue index a53b6269..18c620a1 100644 --- a/frontend/src/widgets/LoginCard.vue +++ b/frontend/src/widgets/LoginCard.vue @@ -7,6 +7,7 @@ import { LockOutlined, UserOutlined } from "@ant-design/icons-vue"; +import { Modal } from "ant-design-vue"; import { onMounted, reactive, ref } from "vue"; import { router } from "@/config/router"; import { loginPageInfo, loginUser } from "@/services/apis"; @@ -50,16 +51,29 @@ const handleLogin = async () => { ...formData } }); - loginStep.value++; - await sleep(1200); - await updateUserInfo(); - await loginSuccess(); + await handleNext(); } catch (error: any) { reportError(error.message ? error.message : error); loginStep.value--; } }; +const handleNext = async () => { + try { + await updateUserInfo(); + loginStep.value++; + await sleep(1200); + loginSuccess(); + } catch (error: any) { + console.error(error); + Modal.error({ + title: t("网页无法正确运作"), + content: t("无法获取身份数据,可能是您已被封禁,或者网络问题,请尝试刷新页面 ") + }); + loginStep.value--; + } +}; + const loginSuccess = () => { loginStep.value++; if (isAdmin.value) {