完善登录bug
This commit is contained in:
@@ -40,10 +40,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
public async Task<Result> Login(user _user)
|
public async Task<Result> Login(user _user)
|
||||||
{
|
{
|
||||||
var user_data = await _userService.Login(_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)
|
if ( user_data!=null)
|
||||||
{
|
{
|
||||||
var token = MakeJwt.app(new jwtUser() {user=user_data,menuIds= menuList});
|
var token = MakeJwt.app(new jwtUser() {user=user_data});
|
||||||
return Result.Success().SetData(new { user = new { _user.id, _user.username, _user.introduction, _user.icon, _user.nick }, token });
|
return Result.Success().SetData(new { user = new { _user.id, _user.username, _user.introduction, _user.icon, _user.nick }, token });
|
||||||
}
|
}
|
||||||
return Result.Error();
|
return Result.Error();
|
||||||
@@ -148,10 +149,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
user_data.nick = pwdDto.user.nick;
|
user_data.nick = pwdDto.user.nick;
|
||||||
|
|
||||||
await _userService.UpdateAsync(user_data);
|
await _userService.UpdateAsync(user_data);
|
||||||
|
|
||||||
|
|
||||||
return Result.Success(msg);
|
return Result.Success(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<Result> UpdataIcon()
|
||||||
|
{
|
||||||
|
return Result.Success();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
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<IFormFile> files )
|
||||||
|
//{
|
||||||
|
// HttpContext.Request[""];
|
||||||
|
// return new FileStreamResult();
|
||||||
|
//}
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetFile()
|
||||||
|
{
|
||||||
|
var userdata = await _userService.GetAllEntitiesTrueAsync();
|
||||||
|
var userList = userdata.ToList();
|
||||||
|
Dictionary<string, string> dt = new ();
|
||||||
|
dt.Add("sc", "user");
|
||||||
|
var bt = Excel.ExportExcel(userList, dt);
|
||||||
|
MemoryStream ms = new(bt);
|
||||||
|
return new FileStreamResult(ms, "application/vnd.ms-excel");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,22 +28,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
public async Task<Result> GetRole()
|
public async Task<Result> GetRole()
|
||||||
{
|
{
|
||||||
return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync());
|
return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync());
|
||||||
}
|
}
|
||||||
[HttpPost]
|
|
||||||
public async Task<IActionResult> GetRoleFlie()
|
|
||||||
{
|
|
||||||
var roleList = await _roleService.GetAllEntitiesTrueAsync();
|
|
||||||
Dictionary<string, string> 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更
|
/// 更
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -107,13 +92,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单
|
/// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="role"></param>
|
/// <param name="roleId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<Result> GetTopMenusByRoleId(role role)
|
public async Task<Result> GetTopMenusByRoleId(int roleId)
|
||||||
{
|
{
|
||||||
|
|
||||||
return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(role.id) ); ;
|
return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(roleId) ); ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
private readonly ILogger<UserController> _logger;
|
private readonly ILogger<UserController> _logger;
|
||||||
|
|
||||||
private IUserService _userService;
|
private IUserService _userService;
|
||||||
public UserController(ILogger<UserController> logger, IUserService userService)
|
private IMenuService _menuService;
|
||||||
|
public UserController(ILogger<UserController> logger, IUserService userService, IMenuService menuService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
|
_menuService = menuService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -120,8 +122,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<Result> GetAxiosByRouter(string router)
|
public async Task<Result> GetAxiosByRouter(string router)
|
||||||
{
|
{
|
||||||
var _user = HttpContext.GetCurrentUserInfo(out List<int> menuIds);
|
var _user = HttpContext.GetCurrentUserInfo();
|
||||||
var menuList= await _userService.GetAxiosByRouter(router, _user.id, menuIds);
|
var menuList = await _menuService.GetTopMenuByUserId(_user.id);
|
||||||
|
if (menuList == null)
|
||||||
|
{
|
||||||
|
return Result.Error();
|
||||||
|
}
|
||||||
|
List<int> menuIds = new();
|
||||||
|
menuList.ForEach(u =>
|
||||||
|
{
|
||||||
|
var id = u.id;
|
||||||
|
menuIds.Add(id);
|
||||||
|
});
|
||||||
|
var childrenList = await _userService.GetAxiosByRouter(router, _user.id, menuIds);
|
||||||
AxiosUrlsModel urlsModel = new();
|
AxiosUrlsModel urlsModel = new();
|
||||||
menuList.ForEach(u =>
|
menuList.ForEach(u =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,4 +24,9 @@
|
|||||||
<ProjectReference Include="..\Yi.Framework.WebCore\Yi.Framework.WebCore.csproj" />
|
<ProjectReference Include="..\Yi.Framework.WebCore\Yi.Framework.WebCore.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="wwwroot\imgae\" />
|
||||||
|
<Folder Include="wwwroot\file\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Yi.Framework.Core
|
|||||||
public class jwtUser
|
public class jwtUser
|
||||||
{
|
{
|
||||||
public user user { get; set; }
|
public user user { get; set; }
|
||||||
public List<menu> menuIds { get; set; }
|
//public List<menu> 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(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}"));
|
||||||
claims.Add(new Claim(ClaimTypes.Name, _user.user.username));
|
claims.Add(new Claim(ClaimTypes.Name, _user.user.username));
|
||||||
claims.Add(new Claim(ClaimTypes.Sid, _user.user.id.ToString()));
|
claims.Add(new Claim(ClaimTypes.Sid, _user.user.id.ToString()));
|
||||||
foreach (var k in _user.menuIds)
|
//foreach (var k in _user.menuIds)
|
||||||
{
|
//{
|
||||||
claims.Add(new Claim("menuIds",k.id.ToString()));
|
// claims.Add(new Claim("menuIds",k.id.ToString()));
|
||||||
}
|
//}
|
||||||
foreach (var k in _user.user.roles)
|
//foreach (var k in _user.user.roles)
|
||||||
{
|
//{
|
||||||
claims.Add(new Claim(ClaimTypes.Role, k.role_name));
|
// claims.Add(new Claim(ClaimTypes.Role, k.role_name));
|
||||||
}
|
//}
|
||||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey));
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey));
|
||||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||||
|
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ export default {
|
|||||||
|
|
||||||
isPasswordVisible: false,
|
isPasswordVisible: false,
|
||||||
form: {
|
form: {
|
||||||
username: "",
|
username: "admin",
|
||||||
password: "",
|
password: "123",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
Reference in New Issue
Block a user