feat(系统设置): 认证登陆调试完成

This commit is contained in:
guoyuqi 2024-07-09 15:42:51 +08:00 committed by 刘瑞斌
parent 312e6dc8c5
commit 695f18fe47
3 changed files with 51 additions and 13 deletions

View File

@ -11,7 +11,7 @@ public class FilterChainUtils {
filterChainDefinitionMap.put("/login", "anon"); filterChainDefinitionMap.put("/login", "anon");
filterChainDefinitionMap.put("/ldap/login", "anon"); filterChainDefinitionMap.put("/ldap/login", "anon");
filterChainDefinitionMap.put("/authentication/get-list", "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("/we_com/info", "anon");
filterChainDefinitionMap.put("/ding_talk/info", "anon"); filterChainDefinitionMap.put("/ding_talk/info", "anon");
filterChainDefinitionMap.put("/lark/info", "anon"); filterChainDefinitionMap.put("/lark/info", "anon");

View File

@ -205,6 +205,46 @@ const useUserStore = defineStore('user', {
return false; 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<UserState>) { updateLocalConfig(partial: Partial<UserState>) {
this.$patch(partial); this.$patch(partial);

View File

@ -118,12 +118,13 @@
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
import { Message, SelectOptionData } from '@arco-design/web-vue'; import { Message, SelectOptionData } from '@arco-design/web-vue';
import { partial } from 'lodash-es';
import TabQrCode from '@/views/login/components/tabQrCode.vue'; import TabQrCode from '@/views/login/components/tabQrCode.vue';
import { getProjectInfo } from '@/api/modules/project-management/basicInfo'; import { getProjectInfo } from '@/api/modules/project-management/basicInfo';
import { getAuthDetail, getAuthDetailByType } from '@/api/modules/setting/config'; 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 { GetLoginLogoUrl } from '@/api/requrls/setting/config';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useLoading from '@/hooks/useLoading'; import useLoading from '@/hooks/useLoading';
@ -131,6 +132,7 @@
import { NO_PROJECT_ROUTE_NAME, NO_RESOURCE_ROUTE_NAME } from '@/router/constants'; import { NO_PROJECT_ROUTE_NAME, NO_RESOURCE_ROUTE_NAME } from '@/router/constants';
import { useAppStore, useUserStore } from '@/store'; import { useAppStore, useUserStore } from '@/store';
import useLicenseStore from '@/store/modules/setting/license'; import useLicenseStore from '@/store/modules/setting/license';
import { UserState } from '@/store/modules/user/types';
import { encrypted } from '@/utils'; import { encrypted } from '@/utils';
import { setLoginExpires, setToken } from '@/utils/auth'; import { setLoginExpires, setToken } from '@/utils/auth';
import { getFirstRouteNameByPermission, routerNameHasPermission } from '@/utils/permission'; import { getFirstRouteNameByPermission, routerNameHasPermission } from '@/utils/permission';
@ -366,15 +368,13 @@
// //
const params = query.split('&'); const params = query.split('&');
// _token // _token
let variableValue; let variableValue;
params.forEach((param) => { params.forEach((param) => {
const pair = param.split('='); const equalIndex = param.indexOf('=');
if (pair[0] === variable) { const variableName = param.substring(0, equalIndex);
console.log(pair[1]); if (variableName === variable) {
// eslint-disable-next-line prefer-destructuring variableValue = param.substring(equalIndex + 1);
variableValue = pair[1];
} }
}); });
return variableValue; return variableValue;
@ -385,12 +385,10 @@
const TOKEN = getQueryVariable('_token'); const TOKEN = getQueryVariable('_token');
const CSRF = getQueryVariable('_csrf'); const CSRF = getQueryVariable('_csrf');
const pId = getQueryVariable('_pId'); const pId = getQueryVariable('_pId');
const orgId = getQueryVariable('orgId'); const orgId = getQueryVariable('_orgId');
if (TOKEN !== null && TOKEN !== undefined && CSRF !== null && CSRF !== undefined) { if (TOKEN !== null && TOKEN !== undefined && CSRF !== null && CSRF !== undefined) {
setToken(TOKEN, CSRF); setToken(window.atob(TOKEN), CSRF);
appStore.setCurrentOrgId(pId || ''); await userStore.setUserInfoByAuth(pId || '', orgId || '');
appStore.setCurrentProjectId(orgId || '');
await userStore.checkIsLogin(true);
} }
} }