From 21fa91ae32746905fb3c49e90190188ab448f797 Mon Sep 17 00:00:00 2001 From: lzw <605106923@qq.com> Date: Mon, 1 Nov 2021 22:06:08 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E5=AE=8C=E5=96=84=E7=99=BB=E5=BD=95b?= =?UTF-8?q?ug"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b59a1522244d4c1df2cbeb6c7f692b1c04d3674b. --- .../Controllers/AccountController.cs | 15 ++---- .../Controllers/FileController.cs | 49 ------------------- .../Controllers/RoleController.cs | 23 +++++++-- .../Controllers/UserController.cs | 19 ++----- .../Yi.Framework.ApiMicroservice.csproj | 5 -- Yi.Framework/Yi.Framework.Core/MakeJwt.cs | 18 +++---- Yi.Vue/src/views/login.vue | 4 +- 7 files changed, 37 insertions(+), 96 deletions(-) delete mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index f2a45efe..b2ca8438 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -40,11 +40,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task Login(user _user) { var user_data = await _userService.Login(_user); - //var menuList = await _menuService.GetTopMenuByUserId(user_data.id); - + var menuList = await _menuService.GetTopMenuByUserId(user_data.id); if ( user_data!=null) - { - var token = MakeJwt.app(new jwtUser() {user=user_data}); + { + var token = MakeJwt.app(new jwtUser() {user=user_data,menuIds= menuList}); return Result.Success().SetData(new { user = new { _user.id, _user.username, _user.introduction, _user.icon, _user.nick }, token }); } return Result.Error(); @@ -149,16 +148,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers user_data.nick = pwdDto.user.nick; await _userService.UpdateAsync(user_data); - + return Result.Success(msg); } - [HttpPost] - public async Task UpdataIcon() - { - return Result.Success(); - - } } } \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs deleted file mode 100644 index 33df3c66..00000000 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Yi.Framework.Common.Models; -using Yi.Framework.Interface; -using Yi.Framework.WebCore; - -namespace Yi.Framework.ApiMicroservice.Controllers -{ - - [Route("api/[controller]/[action]")] - public class FileController : Controller - { - private IUserService _userService; - public FileController(IUserService userService) - { - _userService = userService; - } - //[HttpGet] - //[Route("{type}/{imageNmae}")] - //public IActionResult Get(string type, string imageNmae) - //{ - // return new FileStreamResult(); - //} - - //[HttpPost] - //[Route("{type}/{imageNmae}")] - //public IActionResult Upload(string type,List files ) - //{ - // HttpContext.Request[""]; - // return new FileStreamResult(); - //} - [HttpGet] - public async Task GetFile() - { - var userdata = await _userService.GetAllEntitiesTrueAsync(); - var userList = userdata.ToList(); - Dictionary dt = new (); - dt.Add("sc", "user"); - var bt = Excel.ExportExcel(userList, dt); - MemoryStream ms = new(bt); - return new FileStreamResult(ms, "application/vnd.ms-excel"); - } - } -} diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index 619596a3..c7fb0744 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -28,7 +28,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task GetRole() { return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync()); - } + } + [HttpPost] + public async Task GetRoleFlie() + { + var roleList = await _roleService.GetAllEntitiesTrueAsync(); + Dictionary dt = new(); + dt.Add("输出", "文件"); + var byteStream = Excel.ExportExcel(roleList.ToList(), dt).ToString(); + MemoryStream s = new MemoryStream(); + StreamWriter writer = new StreamWriter(s); + writer.Write(byteStream); + writer.Flush(); + //stream.Read(byteStream, 0, byteStream.Length); + return new FileStreamResult(s, "application/vnd.ms-excel"); + } + /// /// 更 /// @@ -92,13 +107,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单 /// - /// + /// /// [HttpGet] - public async Task GetTopMenusByRoleId(int roleId) + public async Task GetTopMenusByRoleId(role role) { - return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(roleId) ); ; + return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(role.id) ); ; } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 86cbed15..f8eb206a 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -21,12 +21,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers private readonly ILogger _logger; private IUserService _userService; - private IMenuService _menuService; - public UserController(ILogger logger, IUserService userService, IMenuService menuService) + public UserController(ILogger logger, IUserService userService) { _logger = logger; _userService = userService; - _menuService = menuService; } /// @@ -122,19 +120,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpGet] public async Task GetAxiosByRouter(string router) { - var _user = HttpContext.GetCurrentUserInfo(); - var menuList = await _menuService.GetTopMenuByUserId(_user.id); - if (menuList == null) - { - return Result.Error(); - } - List menuIds = new(); - menuList.ForEach(u => - { - var id = u.id; - menuIds.Add(id); - }); - var childrenList = await _userService.GetAxiosByRouter(router, _user.id, menuIds); + var _user = HttpContext.GetCurrentUserInfo(out List menuIds); + var menuList= await _userService.GetAxiosByRouter(router, _user.id, menuIds); AxiosUrlsModel urlsModel = new(); menuList.ForEach(u => { diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj b/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj index a0bec50e..b4833ceb 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj @@ -24,9 +24,4 @@ - - - - - diff --git a/Yi.Framework/Yi.Framework.Core/MakeJwt.cs b/Yi.Framework/Yi.Framework.Core/MakeJwt.cs index 11e9ad7b..f1ad675c 100644 --- a/Yi.Framework/Yi.Framework.Core/MakeJwt.cs +++ b/Yi.Framework/Yi.Framework.Core/MakeJwt.cs @@ -17,7 +17,7 @@ namespace Yi.Framework.Core public class jwtUser { public user user { get; set; } - //public List menuIds { get; set; } + public List menuIds { get; set; } } @@ -37,14 +37,14 @@ namespace Yi.Framework.Core claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}")); claims.Add(new Claim(ClaimTypes.Name, _user.user.username)); claims.Add(new Claim(ClaimTypes.Sid, _user.user.id.ToString())); - //foreach (var k in _user.menuIds) - //{ - // claims.Add(new Claim("menuIds",k.id.ToString())); - //} - //foreach (var k in _user.user.roles) - //{ - // claims.Add(new Claim(ClaimTypes.Role, k.role_name)); - //} + foreach (var k in _user.menuIds) + { + claims.Add(new Claim("menuIds",k.id.ToString())); + } + foreach (var k in _user.user.roles) + { + claims.Add(new Claim(ClaimTypes.Role, k.role_name)); + } var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); diff --git a/Yi.Vue/src/views/login.vue b/Yi.Vue/src/views/login.vue index 045caee5..30b91141 100644 --- a/Yi.Vue/src/views/login.vue +++ b/Yi.Vue/src/views/login.vue @@ -112,8 +112,8 @@ export default { isPasswordVisible: false, form: { - username: "admin", - password: "123", + username: "", + password: "", }, }), methods: {