feat: 添加用户、角色功能

This commit is contained in:
chenchun
2023-02-12 18:43:11 +08:00
parent bc42efe703
commit 158cab9f9b
22 changed files with 304 additions and 92 deletions

View File

@@ -140,5 +140,37 @@ namespace Yi.RBAC.Application.Identity
var imgbyte = _securityCode.GetEnDigitalCodeByte(code);
return new CaptchaImageDto { Img = imgbyte, Uuid = code };
}
/// <summary>
/// 更新密码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> UpdatePasswordAsync(UpdatePasswordDto input)
{
if (input.OldPassword.Equals(input.NewPassword))
{
throw new UserFriendlyException("无效更新!输入的数据,新密码不能与老密码相同");
}
await _accountManager.UpdatePasswordAsync(_currentUser.Id, input.NewPassword, input.OldPassword);
return true;
}
/// <summary>
/// 重置密码
/// </summary>
/// <param name="userId"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPut]
public async Task<bool> RestPasswordAsync(long userId, RestPasswordDto input)
{
if (!string.IsNullOrEmpty(input.Password))
{
throw new UserFriendlyException("重置密码不能为空!");
}
await _accountManager.RestPasswordAsync(userId, input.Password);
return true;
}
}
}

View File

@@ -3,6 +3,7 @@ using NET.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using SqlSugar;
namespace Yi.RBAC.Application.Identity
{
@@ -13,5 +14,16 @@ namespace Yi.RBAC.Application.Identity
public class MenuService : CrudAppService<MenuEntity, MenuGetOutputDto, MenuGetListOutputDto, long, MenuGetListInputVo, MenuCreateInputVo, MenuUpdateInputVo>,
IMenuService, IAutoApiService
{
/// <summary>
/// 查询当前角色的菜单
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public async Task<List<MenuGetListOutputDto>> GetListRoleIdAsync(long roleId)
{
var entities= await _DbQueryable.Where(m => SqlFunc.Subqueryable<RoleMenuEntity>().Where(rm => rm.RoleId == roleId && rm.MenuId == m.Id).Any()).ToListAsync();
return await MapToGetListOutputDtosAsync(entities);
}
}
}

View File

@@ -3,6 +3,9 @@ using NET.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Domain.Identity;
using Microsoft.AspNetCore.Identity;
using Yi.Framework.Uow;
namespace Yi.RBAC.Application.Identity
{
@@ -13,5 +16,30 @@ namespace Yi.RBAC.Application.Identity
public class RoleService : CrudAppService<RoleEntity, RoleGetOutputDto, RoleGetListOutputDto, long, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>,
IRoleService, IAutoApiService
{
[Autowired]
private RoleManager _roleManager { get; set; }
[Autowired]
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
/// <summary>
/// 添加角色
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
{
RoleGetOutputDto outputDto;
using (var uow = _unitOfWorkManager.CreateContext())
{
var entity = await MapToEntityAsync(input);
await _repository.InsertAsync(entity);
outputDto = await MapToGetOutputDtoAsync(entity);
await _roleManager.GiveRoleSetMenuAsync(new List<long> { entity.Id }, input.MenuIds);
uow.Commit();
}
return outputDto;
}
}
}