Просмотр исходного кода

!1679 修复测试过程发现的问题,取消登录地址缓存租户id,靠用户修改不可行
Merge pull request !1679 from Lzh666/N/A

zuohuaijun 1 год назад
Родитель
Сommit
8900dd6209

+ 6 - 4
Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs

@@ -117,18 +117,20 @@ public class SysAuthService : IDynamicApiController, ITransient
     public async Task<(SysTenant tenant, SysUser user)> GetLoginUserAndTenant(long? tenantId, string account = null, string phone = null)
     {
         // 账号是否存在
-        var user = await _sysUserRep.AsQueryable().Includes(t => t.SysOrg).ClearFilter()
+        var user = await _sysUserRep.AsQueryable().Includes(u => u.SysOrg).ClearFilter()
+            .WhereIF(tenantId > 0, u => (u.AccountType == AccountTypeEnum.SuperAdmin || u.TenantId == tenantId))
             .WhereIF(!string.IsNullOrWhiteSpace(account), u => u.Account.Equals(account))
             .WhereIF(!string.IsNullOrWhiteSpace(phone), u => u.Phone.Equals(phone)).FirstAsync();
         _ = user ?? throw Oops.Oh(ErrorCodeEnum.D0009);
 
         // 租户是否存在或已禁用
-        var tenant = await _sysUserRep.ChangeRepository<SqlSugarRepository<SysTenant>>().GetFirstAsync(u => u.Id == user.TenantId);
+        var tenant = await _sysUserRep.ChangeRepository<SqlSugarRepository<SysTenant>>().AsQueryable()
+            .WhereIF(tenantId > 0, u => u.Id == tenantId).WhereIF(tenantId.ToLong() == 0, u => u.Id == user.TenantId).FirstAsync();
         if (tenant?.Status != StatusEnum.Enable) throw Oops.Oh(ErrorCodeEnum.Z1003);
 
         // 如果是超级管理员,则引用登录选择的租户进入系统
-        if (tenantId > 0)
-            if (user.AccountType == AccountTypeEnum.SuperAdmin) user.TenantId = tenantId;
+        if (tenantId > 0 && user.AccountType == AccountTypeEnum.SuperAdmin)
+            user.TenantId = tenantId;
 
         return (tenant, user);
     }

+ 1 - 2
Web/src/router/index.ts

@@ -102,8 +102,7 @@ router.beforeEach(async (to, from, next) => {
 		NProgress.done();
 	} else {
 		if (!token) {
-			const addQuery = Local.get('t') ? `&t=${Local.get('t')}` : '';
-			next(`/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}${addQuery}`);
+			next(`/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}`);
 			Session.clear();
 			NProgress.done();
 		} else if (token && to.path === '/login') {

+ 0 - 2
Web/src/stores/userInfo.ts

@@ -83,8 +83,6 @@ export const useUserInfo = defineStore('userInfo', {
 							tenantId: d.tenantId,
 							time: new Date().getTime(),
 						};
-						Local.remove('t');
-						Local.set('t', userInfos.tenantId);
 
 						// vue-next-admin 提交Id:225bce7 提交消息:admin-23.03.26:发布v2.4.32版本
 						// 增加了下面代码,引起当前会话的用户信息不会刷新,如:重新提交的头像不更新,需要新开一个页面才能正确显示

+ 1 - 1
Web/src/views/login/component/account.vue

@@ -229,7 +229,7 @@ const onSignIn = async () => {
 			const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
 			const password = sm2.doEncrypt(state.ruleForm.password, publicKey, 1);
 
-			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value ?? -1;
+			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value ?? undefined;
 			// console.log(state.ruleForm.tenantId);
 			const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthLoginPost({ ...state.ruleForm, password: password } as any));
 			if (err) {

+ 1 - 1
Web/src/views/login/component/mobile.vue

@@ -99,7 +99,7 @@ const getSmsCode = async () => {
 
 // 登录
 const onSignIn = async () => {
-	state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value ?? -1;
+	state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value ?? undefined;
 	const res = await getAPI(SysAuthApi).apiSysAuthLoginPhonePost(state.ruleForm);
 	if (res.data.result?.accessToken == undefined) {
 		ElMessage.error('登录失败,请检查账号!');

+ 1 - 1
Web/src/views/login/component/register.vue

@@ -211,7 +211,7 @@ const onRegister = async () => {
 			const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
 			const password = state.ruleForm.password ? sm2.doEncrypt(state.ruleForm.password, publicKey, 1) : undefined;
 
-			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value ?? -1;
+			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value ?? undefined;
 			const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthUserRegistrationPost({...state.ruleForm, password: password } as any));
 
 			if (res?.data?.code === 200) {

+ 2 - 4
Web/src/views/login/index.vue

@@ -112,13 +112,11 @@ onMounted(async () => {
 // 获取租户信息
 const getTenantInfo = async () => {
 	if (themeConfig.value.hideTenantForLogin) {
-		tenantInfo.value.id = parseInt(route.query.t ? <string>route.query.t : (Local.get('t') ?? '-1'));
-		tenantInfo.value.list = [];
 		return tenantInfo.value;
 	}
 	const host = location.host.toLowerCase();
-	tenantInfo.value.list = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-	const tenant = tenantInfo.value.list.find((item: any) => item.value == route.query.t || (!item.host && item.host === host)) as any;
+	tenantInfo.value.list = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? null);
+	const tenant = tenantInfo.value.list.find((item: any) => !item.host && item.host === host) as any;
 	if (tenant?.value) tenantInfo.value.id = parseInt(tenant?.value);
 	return tenantInfo.value;
 }