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

@@ -58,6 +58,21 @@
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.UpdatePasswordAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.UpdatePasswordDto)">
<summary>
更新密码
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.RestPasswordAsync(System.Int64,Yi.RBAC.Application.Contracts.Identity.Dtos.Account.RestPasswordDto)">
<summary>
重置密码
</summary>
<param name="userId"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.DeptService">
<summary>
Dept服务实现
@@ -81,6 +96,13 @@
Menu服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.MenuService.GetListRoleIdAsync(System.Int64)">
<summary>
查询当前角色的菜单
</summary>
<param name="roleId"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.PostService">
<summary>
Post服务实现
@@ -91,6 +113,13 @@
Role服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.RoleService.CreateAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.RoleCreateInputVo)">
<summary>
添加角色
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.UserService">
<summary>
User服务实现

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;
}
}
}