From 695f18fe478041f899eb6e5de2246070a6982baf Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 9 Jul 2024 15:42:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E7=99=BB=E9=99=86=E8=B0=83=E8=AF=95=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/util/FilterChainUtils.java | 2 +- frontend/src/store/modules/user/index.ts | 40 +++++++++++++++++++ .../src/views/login/components/login-form.vue | 22 +++++----- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java index 5a1427e7b9..b8bda7c3e6 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java @@ -11,7 +11,7 @@ public class FilterChainUtils { filterChainDefinitionMap.put("/login", "anon"); filterChainDefinitionMap.put("/ldap/login", "anon"); filterChainDefinitionMap.put("/authentication/get-list", "anon"); - filterChainDefinitionMap.put("/authentication//get/by/type/**", "anon"); + filterChainDefinitionMap.put("/authentication/get/by/type/**", "anon"); filterChainDefinitionMap.put("/we_com/info", "anon"); filterChainDefinitionMap.put("/ding_talk/info", "anon"); filterChainDefinitionMap.put("/lark/info", "anon"); diff --git a/frontend/src/store/modules/user/index.ts b/frontend/src/store/modules/user/index.ts index 4aea30dfff..f459c0053d 100644 --- a/frontend/src/store/modules/user/index.ts +++ b/frontend/src/store/modules/user/index.ts @@ -205,6 +205,46 @@ const useUserStore = defineStore('user', { return false; } }, + + async setUserInfoByAuth(pId: string, orgId: string) { + const appStore = useAppStore(); + const router = useRouter(); + const res = await userIsLogin(); + this.setInfo(res); + appStore.setCurrentOrgId(orgId); + appStore.setCurrentProjectId(pId); + try { + const HasProjectPermission = await getUserHasProjectPermission(appStore.currentProjectId); + if (!HasProjectPermission) { + // 没有项目权限(用户所在的当前项目被禁用&用户被移除出去该项目) + router.push({ + name: NO_PROJECT_ROUTE_NAME, + }); + return; + } + const resp = await getProjectInfo(appStore.currentProjectId); + if (!resp) { + // 如果项目被删除或者被禁用,跳转到无项目页面 + router.push({ + name: NO_PROJECT_ROUTE_NAME, + }); + } + if (resp) { + appStore.setCurrentMenuConfig(resp?.moduleIds || []); + } + } catch (err) { + appStore.setCurrentMenuConfig([]); + // eslint-disable-next-line no-console + console.log(err); + } + const { isLoginPage } = useUser(); + if (isLoginPage()) { + // 当前页面为登录页面,且已经登录,跳转到首页 + const currentRouteName = getFirstRouteNameByPermission(router.getRoutes()); + router.push({ name: currentRouteName }); + } + }, + // 更新本地设置 updateLocalConfig(partial: Partial) { this.$patch(partial); diff --git a/frontend/src/views/login/components/login-form.vue b/frontend/src/views/login/components/login-form.vue index 6927be370a..2450e7b687 100644 --- a/frontend/src/views/login/components/login-form.vue +++ b/frontend/src/views/login/components/login-form.vue @@ -118,12 +118,13 @@ import { useRouter } from 'vue-router'; import { useStorage } from '@vueuse/core'; import { Message, SelectOptionData } from '@arco-design/web-vue'; + import { partial } from 'lodash-es'; import TabQrCode from '@/views/login/components/tabQrCode.vue'; import { getProjectInfo } from '@/api/modules/project-management/basicInfo'; import { getAuthDetail, getAuthDetailByType } from '@/api/modules/setting/config'; - import { getPlatformParamUrl } from '@/api/modules/user'; + import { getPlatformParamUrl, isLogin as userIsLogin } from '@/api/modules/user'; import { GetLoginLogoUrl } from '@/api/requrls/setting/config'; import { useI18n } from '@/hooks/useI18n'; import useLoading from '@/hooks/useLoading'; @@ -131,6 +132,7 @@ import { NO_PROJECT_ROUTE_NAME, NO_RESOURCE_ROUTE_NAME } from '@/router/constants'; import { useAppStore, useUserStore } from '@/store'; import useLicenseStore from '@/store/modules/setting/license'; + import { UserState } from '@/store/modules/user/types'; import { encrypted } from '@/utils'; import { setLoginExpires, setToken } from '@/utils/auth'; import { getFirstRouteNameByPermission, routerNameHasPermission } from '@/utils/permission'; @@ -366,15 +368,13 @@ // 分割查询参数 const params = query.split('&'); - // 遍历参数,找到 _token 参数的值 let variableValue; params.forEach((param) => { - const pair = param.split('='); - if (pair[0] === variable) { - console.log(pair[1]); - // eslint-disable-next-line prefer-destructuring - variableValue = pair[1]; + const equalIndex = param.indexOf('='); + const variableName = param.substring(0, equalIndex); + if (variableName === variable) { + variableValue = param.substring(equalIndex + 1); } }); return variableValue; @@ -385,12 +385,10 @@ const TOKEN = getQueryVariable('_token'); const CSRF = getQueryVariable('_csrf'); const pId = getQueryVariable('_pId'); - const orgId = getQueryVariable('orgId'); + const orgId = getQueryVariable('_orgId'); if (TOKEN !== null && TOKEN !== undefined && CSRF !== null && CSRF !== undefined) { - setToken(TOKEN, CSRF); - appStore.setCurrentOrgId(pId || ''); - appStore.setCurrentProjectId(orgId || ''); - await userStore.checkIsLogin(true); + setToken(window.atob(TOKEN), CSRF); + await userStore.setUserInfoByAuth(pId || '', orgId || ''); } }