Merge branch 'refs/heads/pure-dev' into abp

This commit is contained in:
橙子
2024-09-05 23:13:18 +08:00
620 changed files with 104979 additions and 68 deletions

View File

@@ -4,17 +4,17 @@ using Yi.Framework.Ddd.Application.Contracts;
namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Config
{
/// <summary>
/// <EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// 配置查询参数
/// </summary>
public class ConfigGetListInputVo : PagedAllResultRequestDto
{
/// <summary>
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// 配置名称
/// </summary>
public string? ConfigName { get; set; }
/// <summary>
/// <EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>
/// 配置键
/// </summary>
public string? ConfigKey { get; set; }

View File

@@ -5,14 +5,11 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Dept
/// </summary>
public class DeptCreateInputVo
{
public Guid Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public Guid? CreatorId { get; set; }
public bool State { get; set; }
public string DeptName { get; set; } = string.Empty;
public string DeptCode { get; set; } = string.Empty;
public string DeptName { get; set; }
public string DeptCode { get; set; }
public string? Leader { get; set; }
public Guid ParentId { get; set; }
public Guid? ParentId { get; set; }=Guid.Empty;
public string? Remark { get; set; }
}
}

View File

@@ -2,14 +2,11 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Dept
{
public class DeptUpdateInputVo
{
public Guid Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public Guid? CreatorId { get; set; }
public bool State { get; set; }
public string DeptName { get; set; } = string.Empty;
public string DeptCode { get; set; } = string.Empty;
public string? Leader { get; set; }
public Guid ParentId { get; set; }
public Guid? ParentId { get; set; }=Guid.Empty;
public string? Remark { get; set; }
}
}

View File

@@ -5,12 +5,9 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Post
/// </summary>
public class PostCreateInputVo
{
public Guid Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public bool? State { get; set; }
public string PostCode { get; set; } = string.Empty;
public string PostName { get; set; } = string.Empty;
public string PostCode { get; set; }
public string PostName { get; set; }
public string? Remark { get; set; }
}
}

View File

@@ -2,12 +2,9 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Post
{
public class PostUpdateInputVo
{
public Guid Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public Guid? CreatorId { get; set; }
public bool? State { get; set; }
public string PostCode { get; set; } = string.Empty;
public string PostName { get; set; } = string.Empty;
public string PostCode { get; set; }
public string PostName { get; set; }
public string? Remark { get; set; }
}
}

View File

@@ -1,6 +1,8 @@
using System.Text.RegularExpressions;
using Lazy.Captcha.Core;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;
@@ -25,6 +27,7 @@ using Yi.Framework.Rbac.Domain.Repositories;
using Yi.Framework.Rbac.Domain.Shared.Caches;
using Yi.Framework.Rbac.Domain.Shared.Consts;
using Yi.Framework.Rbac.Domain.Shared.Dtos;
using Yi.Framework.Rbac.Domain.Shared.Etos;
using Yi.Framework.Rbac.Domain.Shared.Options;
using Yi.Framework.SqlSugarCore.Abstractions;
@@ -40,7 +43,7 @@ namespace Yi.Framework.Rbac.Application.Services
private readonly IAliyunManger _aliyunManger;
private IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> _userCache;
private UserManager _userManager;
private IHttpContextAccessor _httpContextAccessor;
public AccountService(IUserRepository userRepository,
ICurrentUser currentUser,
IAccountManager accountManager,
@@ -51,7 +54,7 @@ namespace Yi.Framework.Rbac.Application.Services
IGuidGenerator guidGenerator,
IOptions<RbacOptions> options,
IAliyunManger aliyunManger,
UserManager userManager)
UserManager userManager, IHttpContextAccessor httpContextAccessor)
{
_userRepository = userRepository;
_currentUser = currentUser;
@@ -64,6 +67,7 @@ namespace Yi.Framework.Rbac.Application.Services
_aliyunManger = aliyunManger;
_userCache = userCache;
_userManager = userManager;
_httpContextAccessor = httpContextAccessor;
}
@@ -109,10 +113,21 @@ namespace Yi.Framework.Rbac.Application.Services
//校验
await _accountManager.LoginValidationAsync(input.UserName, input.Password, x => user = x);
var userInfo = new UserRoleMenuDto();
//获取token
var accessToken = await _accountManager.GetTokenByUserIdAsync(user.Id);
var accessToken = await _accountManager.GetTokenByUserIdAsync(user.Id, (info) => userInfo = info);
var refreshToken = _accountManager.CreateRefreshToken(user.Id);
//这里抛出一个登录的事件,也可以在全部流程走完,在应用层组装
if (_httpContextAccessor.HttpContext is not null)
{
var loginEntity = new LoginLogAggregateRoot().GetInfoByHttpContext(_httpContextAccessor.HttpContext);
var loginEto = loginEntity.Adapt<LoginEventArgs>();
loginEto.UserName = userInfo.User.UserName;
loginEto.UserId = userInfo.User.Id;
await LocalEventBus.PublishAsync(loginEto);
}
return new { Token = accessToken, RefreshToken = refreshToken };
}

View File

@@ -34,13 +34,11 @@ namespace Yi.Framework.Rbac.Domain.Managers
private readonly ILocalEventBus _localEventBus;
private readonly JwtOptions _jwtOptions;
private readonly RbacOptions _options;
private IHttpContextAccessor _httpContextAccessor;
private UserManager _userManager;
private ISqlSugarRepository<RoleAggregateRoot> _roleRepository;
private RefreshJwtOptions _refreshJwtOptions;
public AccountManager(IUserRepository repository
, IHttpContextAccessor httpContextAccessor
, IOptions<JwtOptions> jwtOptions
, ILocalEventBus localEventBus
, UserManager userManager
@@ -49,7 +47,6 @@ namespace Yi.Framework.Rbac.Domain.Managers
, IOptions<RbacOptions> options)
{
_repository = repository;
_httpContextAccessor = httpContextAccessor;
_jwtOptions = jwtOptions.Value;
_localEventBus = localEventBus;
_userManager = userManager;
@@ -62,9 +59,10 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// 根据用户id获取token
/// </summary>
/// <param name="userId"></param>
/// <param name="getUserInfo"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<string> GetTokenByUserIdAsync(Guid userId)
public async Task<string> GetTokenByUserIdAsync(Guid userId,Action<UserRoleMenuDto>? getUserInfo=null)
{
//获取用户信息
var userInfo = await _userManager.GetInfoAsync(userId);
@@ -79,23 +77,18 @@ namespace Yi.Framework.Rbac.Domain.Managers
{
throw new UserFriendlyException(UserConst.No_Role);
}
if (userInfo.PermissionCodes.Count() == 0)
if (!userInfo.PermissionCodes.Any())
{
throw new UserFriendlyException(UserConst.No_Permission);
}
//这里抛出一个登录的事件,也可以在全部流程走完,在应用层组装
if (_httpContextAccessor.HttpContext is not null)
if (getUserInfo is not null)
{
var loginEntity = new LoginLogAggregateRoot().GetInfoByHttpContext(_httpContextAccessor.HttpContext);
var loginEto = loginEntity.Adapt<LoginEventArgs>();
loginEto.UserName = userInfo.User.UserName;
loginEto.UserId = userInfo.User.Id;
await _localEventBus.PublishAsync(loginEto);
getUserInfo(userInfo);
}
var accessToken = CreateToken(this.UserInfoToClaim(userInfo));
//将用户信息添加到缓存中,需要考虑的是更改了用户、角色、菜单等整个体系都需要将缓存进行刷新,看具体业务进行选择
return accessToken;
}

View File

@@ -5,14 +5,15 @@ using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Shared.Dtos;
namespace Yi.Framework.Rbac.Domain.Managers
{
public interface IAccountManager : IDomainService
{
string CreateRefreshToken(Guid userId);
Task<string> GetTokenByUserIdAsync(Guid userId);
Task LoginValidationAsync(string userName, string password, Action<UserAggregateRoot> userAction = null);
Task<string> GetTokenByUserIdAsync(Guid userId,Action<UserRoleMenuDto>? getUserInfo=null);
Task LoginValidationAsync(string userName, string password, Action<UserAggregateRoot>? userAction = null);
Task RegisterAsync(string userName, string password, long phone);
Task<bool> RestPasswordAsync(Guid userId, string password);
Task UpdatePasswordAsync(Guid userId, string newPassword, string oldPassword);

View File

@@ -162,14 +162,23 @@ namespace Yi.Framework.Rbac.Domain.Managers
}
/// <summary>
/// 查询用户信息,缓存
/// 查询用户信息,取消缓存
/// </summary>
/// <returns></returns>
public async Task<UserRoleMenuDto> GetInfoAsync(Guid userId)
{
var output = await GetInfoByCacheAsync(userId);
return output;
var user = await _userRepository.GetUserAllInfoAsync(userId);
var data = EntityMapToDto(user);
//系统用户数据被重置,老前端访问重新授权
if (data is null)
{
throw new AbpAuthorizationException();
}
//data.Menus.Clear();
// output = data;
return data;
// var output = await GetInfoByCacheAsync(userId);
// return output;
}
private async Task<UserRoleMenuDto> GetInfoByCacheAsync(Guid userId)
{