|
@@ -8,6 +8,7 @@ using GxPress.EnumConst;
|
|
|
using GxPress.Repository.Interface;
|
|
|
using GxPress.Request.Admin;
|
|
|
using GxPress.Result.Admin;
|
|
|
+using GxPress.Service.Interface.Role;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Logging;
|
|
@@ -27,11 +28,14 @@ namespace GxPress.Api.AdminControllers
|
|
|
private readonly ILogger<AdminController> _logger;
|
|
|
private readonly IAdminRepository _adminRepository;
|
|
|
|
|
|
- public AdminController(IOptions<JwtOptions> jwtOptions, ILogger<AdminController> logger, IAdminRepository adminRepository)
|
|
|
+ private readonly IRoleService roleService;
|
|
|
+
|
|
|
+ public AdminController(IOptions<JwtOptions> jwtOptions, ILogger<AdminController> logger, IAdminRepository adminRepository, IRoleService roleService)
|
|
|
{
|
|
|
_jwtOptions = jwtOptions.Value;
|
|
|
_logger = logger;
|
|
|
_adminRepository = adminRepository;
|
|
|
+ this.roleService = roleService;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -44,12 +48,14 @@ namespace GxPress.Api.AdminControllers
|
|
|
public async Task<AdminSignInResult> SignIn(AdminSignInRequest request)
|
|
|
{
|
|
|
var result = await _adminRepository.SignInAsync(request);
|
|
|
+ //获取菜单
|
|
|
+ result.MenuInResult = await roleService.GetMenusAllAsync(result.RoleId);
|
|
|
var claims = new[]
|
|
|
{
|
|
|
new Claim(ClaimTypes.NameIdentifier,result.AdminId.ToString()),
|
|
|
new Claim(ClaimTypes.Role,AccountTypeConst.Admin.ToString()),
|
|
|
new Claim(ClaimTypes.Actor,result.Name)
|
|
|
- };
|
|
|
+ };
|
|
|
result.Token = TokenHelper.BuildToken(_jwtOptions, claims);
|
|
|
_logger.LogInformation("admin token:{token}", result.Token);
|
|
|
return result;
|
|
@@ -61,7 +67,7 @@ namespace GxPress.Api.AdminControllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("signup")]
|
|
|
- public async Task<int> SignUp([FromBody]AdminSignUpRequest request)
|
|
|
+ public async Task<int> SignUp([FromBody] AdminSignUpRequest request)
|
|
|
{
|
|
|
return await _adminRepository.SignUpAsync(request);
|
|
|
}
|
|
@@ -105,7 +111,7 @@ namespace GxPress.Api.AdminControllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPut("updatemenu")]
|
|
|
- public async Task<bool> UpdateMenu( [FromBody] Admin request)
|
|
|
+ public async Task<bool> UpdateMenu([FromBody] Admin request)
|
|
|
{
|
|
|
return await _adminRepository.UpdateQAsync(request);
|
|
|
}
|
|
@@ -115,7 +121,7 @@ namespace GxPress.Api.AdminControllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("page")]
|
|
|
- public async Task<PagedList<AdminPageResult>> GetPagedList([FromBody]AdminPageSearchRequest request)
|
|
|
+ public async Task<PagedList<AdminPageResult>> GetPagedList([FromBody] AdminPageSearchRequest request)
|
|
|
{
|
|
|
return await _adminRepository.GetPagedList(request);
|
|
|
}
|