diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs
index 21678b45..9e1937df 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs
@@ -47,7 +47,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
UserEntity user = new();
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
{
- return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(user) });
+ var userRoleMenu= await _iUserService.GetUserAllInfo(user.Id);
+ return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User,userRoleMenu.Menus) });
}
return Result.SuccessError("登录失败!用户名或者密码错误!");
}
@@ -80,6 +81,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
///
///
[HttpGet]
+ [Authorize]
public async Task GetUserAllInfo()
{
//通过鉴权jwt获取到用户的id
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
index a7251a4c..e4084ba3 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
@@ -45,7 +45,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
///
[HttpGet]
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
- // 规范:控制器不建议使用切换仓储方法、控制器严禁使用DB上下文对象,其它怎么爽怎么来!
+ // 规范:控制器严禁使用DB上下文对象,其它怎么爽怎么来!
public async Task DbTest()
{
//非常好,使用UserService的特有方法
@@ -60,7 +60,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
//挺不错,依赖注入其他仓储
await _iRoleService._repository.GetListAsync();
- //不建议操作,直接切换其他仓储
+ //还行,直接切换其他仓储,怎么爽怎么来
await _iUserService._repository.ChangeRepository>().GetListAsync();
//最好不要直接操作Db对象
@@ -74,7 +74,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
///
///
[HttpGet]
- //简单语句不推荐!
+ //简单语句不推荐使用sql!
public async Task SqlTest()
{
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync("select * from User"));
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db
index 3913d1ee..1ae5c4f1 100644
Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ
diff --git a/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs b/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
index e599ff74..dbaf0e95 100644
--- a/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
@@ -23,15 +23,15 @@ namespace Yi.Framework.Core
}
public string GetRefreshToken(UserEntity user)
{
- return this.GetToken(_JWTTokenOptions.ReExpiration, user, true);
+ return this.GetToken(_JWTTokenOptions.ReExpiration, user,null, true);
}
- public string GetAccessToken(UserEntity user)
+ public string GetAccessToken(UserEntity user,HashSet menus)
{
- return this.GetToken(_JWTTokenOptions.Expiration, user);
+ return this.GetToken(_JWTTokenOptions.Expiration, user, menus);
}
- private string GetToken(int minutes, UserEntity user, bool isRefresh = false)
+ private string GetToken(int minutes, UserEntity user, HashSet menus,bool isRefresh = false)
{
List claims = new List();
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
@@ -39,8 +39,11 @@ namespace Yi.Framework.Core
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
//-----------------------------以下从user的权限表中添加权限-----------------------例如:
- claims.Add(new Claim("permission", "userentity:get:list"));
- claims.Add(new Claim("permission", "userentity:get:one"));
+
+ foreach (var m in menus)
+ {
+ claims.Add(new Claim("permission", m.PermissionCode));
+ }
if (isRefresh)
{
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs
index 78f8655b..fa16fc8f 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs
@@ -3,6 +3,7 @@ using Microsoft.IdentityModel.JsonWebTokens;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Yi.Framework.WebCore.AttributeExtend
@@ -40,11 +41,21 @@ namespace Yi.Framework.WebCore.AttributeExtend
var perList = context.HttpContext.User.Claims.Where(u => u.Type == "permission").Select(u=> u.Value.ToString().ToLower()). ToList();
//判断权限是否存在Redis中,或者jwt中
- //if (perList.Contains(permission.ToLower()))
- //{
- // result = true;
- //}
- result = true;
+ //进行正则表达式的匹配,以code开头
+ Regex regex = new Regex($"^{permission.ToLower()}");
+ foreach (var p in perList)
+ {
+ if (regex.IsMatch(p))
+ {
+ result = true;
+ break;
+ }
+ }
+ //用户的增删改查直接可以user:*即可
+
+
+ //这里暂时全部放行即可
+ result = true;
if (!result)
diff --git a/Yi.Vue2.x/src/api/roleApi.js b/Yi.Vue2.x/src/api/roleApi.js
index 5252affb..c4bda7df 100644
--- a/Yi.Vue2.x/src/api/roleApi.js
+++ b/Yi.Vue2.x/src/api/roleApi.js
@@ -1,22 +1,11 @@
import myaxios from '@/util/myaxios'
+import {objctToDic} from '@/util/objctHandle'
export default {
getList() {
return myaxios({
url: '/Role/GetList',
method: 'post',
- data: {
- parameters: [
- {
- key: "isDeleted",
- value: "0",
- type: 0
-
- }
- ],
- orderBys: [
- "id"
- ]
- }
+ data: objctToDic()
})
},
giveRoleSetMenu(roleList, menuList) {
diff --git a/Yi.Vue2.x/src/api/userApi.js b/Yi.Vue2.x/src/api/userApi.js
index a7131676..728e97a5 100644
--- a/Yi.Vue2.x/src/api/userApi.js
+++ b/Yi.Vue2.x/src/api/userApi.js
@@ -1,14 +1,5 @@
import myaxios from '@/util/myaxios'
export default {
- SetRoleByUser(userIds, roleIds) {
- return myaxios({
- url: '/User/SetRoleByUser',
- method: 'post',
- data: { "ids1": userIds, "ids2": roleIds }
- })
- },
-
-
GetUserInRolesByHttpUser() {
return myaxios({
diff --git a/Yi.Vue2.x/src/components/TableApi.js b/Yi.Vue2.x/src/components/TableApi.js
index 3c4d26a6..2dcb0487 100644
--- a/Yi.Vue2.x/src/components/TableApi.js
+++ b/Yi.Vue2.x/src/components/TableApi.js
@@ -1,22 +1,11 @@
import myaxios from '@/util/myaxios'
+import {objctToDic} from '@/util/objctHandle'
export default {
getItem(url) {
return myaxios({
url: url,
method: 'post',
- data: {
- parameters: [
- {
- key: "isDeleted",
- value: "0",
- type: 0
-
- }
- ],
- orderBys: [
- "id"
- ]
- }
+ data: objctToDic()
})
},
addItem(url, data) {
diff --git a/Yi.Vue2.x/src/components/ccTreeview.vue b/Yi.Vue2.x/src/components/ccTreeview.vue
index a63bfa1d..c1e4acaf 100644
--- a/Yi.Vue2.x/src/components/ccTreeview.vue
+++ b/Yi.Vue2.x/src/components/ccTreeview.vue
@@ -53,8 +53,7 @@
item-text="menuName"
>
- 编号:{{ item.id }}
- 权限:{{ item.permissionCode }}
+ 权限:{{ item.permissionCode }}