|
@ -1,8 +1,15 @@ |
|
|
|
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
|
|
|
using System.Net.Http; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using DocumentFormat.OpenXml.Drawing.Charts; |
|
|
|
|
|
using IdentityModel.Client; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
using Volo.Abp.Account; |
|
|
using Volo.Abp.Account; |
|
|
using Volo.Abp.AspNetCore.Mvc; |
|
|
using Volo.Abp.AspNetCore.Mvc; |
|
|
using Win_in.Sfs.Auth.Application.Contracts; |
|
|
using Win_in.Sfs.Auth.Application.Contracts; |
|
@ -26,6 +33,9 @@ public class AccountController : AbpController |
|
|
private readonly ITokenService _tokenService; |
|
|
private readonly ITokenService _tokenService; |
|
|
private readonly IUserMenuAppService _userMenuAppService; |
|
|
private readonly IUserMenuAppService _userMenuAppService; |
|
|
private readonly IUserWorkGroupAppService _userWorkGroupAppService; |
|
|
private readonly IUserWorkGroupAppService _userWorkGroupAppService; |
|
|
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory; |
|
|
|
|
|
private readonly ILogger<TokenService> _logger; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
///
|
|
|
///
|
|
@ -38,12 +48,27 @@ public class AccountController : AbpController |
|
|
, ITokenService tokenService |
|
|
, ITokenService tokenService |
|
|
, IUserMenuAppService userMenuAppService |
|
|
, IUserMenuAppService userMenuAppService |
|
|
, IUserWorkGroupAppService userWorkGroupAppService |
|
|
, IUserWorkGroupAppService userWorkGroupAppService |
|
|
) |
|
|
, IConfiguration configuration, IHttpClientFactory httpClientFactory, ILogger<TokenService> logger) |
|
|
{ |
|
|
{ |
|
|
_profileAppService = profileAppService; |
|
|
_profileAppService = profileAppService; |
|
|
_tokenService = tokenService; |
|
|
_tokenService = tokenService; |
|
|
_userMenuAppService = userMenuAppService; |
|
|
_userMenuAppService = userMenuAppService; |
|
|
_userWorkGroupAppService = userWorkGroupAppService; |
|
|
_userWorkGroupAppService = userWorkGroupAppService; |
|
|
|
|
|
_configuration = configuration; |
|
|
|
|
|
_httpClientFactory = httpClientFactory; |
|
|
|
|
|
_logger = logger; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Display] |
|
|
|
|
|
public class LoginModel |
|
|
|
|
|
{ |
|
|
|
|
|
[Display] |
|
|
|
|
|
[Required] |
|
|
|
|
|
public string UserName { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
[Display] |
|
|
|
|
|
[Required] |
|
|
|
|
|
public string Password { get; set; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -55,8 +80,51 @@ public class AccountController : AbpController |
|
|
public virtual async Task<BaererToken> LoginAsync(UserLoginInput userLoginInput) |
|
|
public virtual async Task<BaererToken> LoginAsync(UserLoginInput userLoginInput) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
var token = await _tokenService.GetTokenAsync(userLoginInput.Username, userLoginInput.Password).ConfigureAwait(false); |
|
|
var address = _configuration["AuthServer:Authority"]; |
|
|
return token; |
|
|
var request = new DiscoveryDocumentRequest |
|
|
|
|
|
{ |
|
|
|
|
|
Address = address, |
|
|
|
|
|
Policy = new DiscoveryPolicy { RequireHttps = false } |
|
|
|
|
|
}; |
|
|
|
|
|
var discovery = await _httpClientFactory.CreateClient().GetDiscoveryDocumentAsync(request).ConfigureAwait(false); |
|
|
|
|
|
var clientId = _configuration["AuthServer:ClientId"]; |
|
|
|
|
|
var clientSecret = _configuration["AuthServer:ClientSecret"]; |
|
|
|
|
|
this._logger.LogInformation($"address:{address},TokenEndpoint:{discovery.TokenEndpoint},clientId:{clientId},clientSecret:{clientSecret}"); |
|
|
|
|
|
var result = await _httpClientFactory.CreateClient().RequestPasswordTokenAsync(new PasswordTokenRequest |
|
|
|
|
|
{ |
|
|
|
|
|
Address = $"{address.TrimEnd('/')}/connect/token", |
|
|
|
|
|
GrantType = "password", |
|
|
|
|
|
ClientId = clientId, |
|
|
|
|
|
ClientSecret = clientSecret, |
|
|
|
|
|
UserName = userLoginInput.Username, |
|
|
|
|
|
Password = userLoginInput.Password |
|
|
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
Console.WriteLine($"Result:${(result.IsError ? result.ErrorDescription : result.AccessToken)}"); |
|
|
|
|
|
|
|
|
|
|
|
return new BaererToken() |
|
|
|
|
|
{ |
|
|
|
|
|
refresh_token = result.RefreshToken, |
|
|
|
|
|
access_token = result.AccessToken, |
|
|
|
|
|
scope = result.Scope, |
|
|
|
|
|
token_type = result.TokenType, |
|
|
|
|
|
expires_in = result.ExpiresIn, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//return new JsonResult(new
|
|
|
|
|
|
//{
|
|
|
|
|
|
// result.TokenType,
|
|
|
|
|
|
// result.AccessToken,
|
|
|
|
|
|
// result.ExpiresIn,
|
|
|
|
|
|
// result.RefreshToken,
|
|
|
|
|
|
// result.Scope,
|
|
|
|
|
|
// result.HttpStatusCode,
|
|
|
|
|
|
// result.Error,
|
|
|
|
|
|
// result.HttpErrorReason,
|
|
|
|
|
|
// result.ErrorDescription,
|
|
|
|
|
|
// result.ErrorType,
|
|
|
|
|
|
// result.Exception?.Message,
|
|
|
|
|
|
// Exception = result.Exception?.ToString()
|
|
|
|
|
|
//});
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -95,10 +163,10 @@ public class AccountController : AbpController |
|
|
/// 菜单
|
|
|
/// 菜单
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("menus")] |
|
|
[HttpGet("menus/{userId}")] |
|
|
public virtual async Task<List<PdaMenuGroupDto>> GetMenusAsync() |
|
|
public virtual async Task<List<PdaMenuGroupDto>> GetMenusAsync(Guid userId) |
|
|
{ |
|
|
{ |
|
|
var userId = CurrentUser.Id; |
|
|
//var userId = CurrentUser.Id;
|
|
|
var pdaMenuGroupDtos = new List<PdaMenuGroupDto>();//返回给pda的菜单 已排序
|
|
|
var pdaMenuGroupDtos = new List<PdaMenuGroupDto>();//返回给pda的菜单 已排序
|
|
|
var menusOfUser = await _userMenuAppService.GetPdaMenusOfUserAsync(userId).ConfigureAwait(false); |
|
|
var menusOfUser = await _userMenuAppService.GetPdaMenusOfUserAsync(userId).ConfigureAwait(false); |
|
|
var menuGroups = menusOfUser.GroupBy(p => p.GroupName); |
|
|
var menuGroups = menusOfUser.GroupBy(p => p.GroupName); |
|
|