完善登录
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Yi.RBAC.Application.Identity
|
||||
[Autowired]
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
[Autowired]
|
||||
private UserManager _userManager { get; set; }
|
||||
private AccountManager _accountManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
@@ -38,16 +38,18 @@ namespace Yi.RBAC.Application.Identity
|
||||
{
|
||||
UserEntity user = new();
|
||||
//登录成功
|
||||
await _userManager.LoginValidationAsync(input.UserName, input.Password, x => user = x);
|
||||
await _accountManager.LoginValidationAsync(input.UserName, input.Password, x => user = x);
|
||||
|
||||
//获取用户信息
|
||||
var userInfo = await _userRepository.GetUserAllInfoAsync(user.Id);
|
||||
|
||||
//发送令牌
|
||||
var claimDic = new Dictionary<string, object>();
|
||||
claimDic.Add(nameof(ICurrentUser.Id), 123456);
|
||||
if (userInfo.PermissionCodes.Count == 0)
|
||||
{
|
||||
throw new UserFriendlyException(UserConst.用户无权限分配);
|
||||
}
|
||||
|
||||
var token = _jwtTokenManager.CreateToken(claimDic);
|
||||
//创建token
|
||||
var token = _jwtTokenManager.CreateToken(_accountManager.UserInfoToClaim(userInfo));
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Yi.RBAC.Application.Contracts.Identity;
|
||||
using NET.AutoWebApi.Setting;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
using Yi.Framework.Ddd.Services;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Dept服务实现
|
||||
/// </summary>
|
||||
[AppService]
|
||||
public class DeptService : CrudAppService<DeptEntity, DeptGetOutputDto, DeptGetListOutputDto, long, DeptGetListInputVo, DeptCreateInputVo, DeptUpdateInputVo>,
|
||||
IDeptService, IAutoApiService
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity.MapperConfig
|
||||
{
|
||||
public class DeptProfile: Profile
|
||||
{
|
||||
public DeptProfile()
|
||||
{
|
||||
CreateMap<DeptGetListInputVo, DeptEntity>();
|
||||
CreateMap<DeptCreateInputVo, DeptEntity>();
|
||||
CreateMap<DeptUpdateInputVo, DeptEntity>();
|
||||
CreateMap<DeptEntity, DeptGetListOutputDto>();
|
||||
CreateMap<DeptEntity, DeptGetOutputDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity.MapperConfig
|
||||
{
|
||||
public class MenuProfile: Profile
|
||||
{
|
||||
public MenuProfile()
|
||||
{
|
||||
CreateMap<MenuGetListInputVo, MenuEntity>();
|
||||
CreateMap<MenuCreateInputVo, MenuEntity>();
|
||||
CreateMap<MenuUpdateInputVo, MenuEntity>();
|
||||
CreateMap<MenuEntity, MenuGetListOutputDto>();
|
||||
CreateMap<MenuEntity, MenuGetOutputDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity.MapperConfig
|
||||
{
|
||||
public class PostProfile: Profile
|
||||
{
|
||||
public PostProfile()
|
||||
{
|
||||
CreateMap<PostGetListInputVo, PostEntity>();
|
||||
CreateMap<PostCreateInputVo, PostEntity>();
|
||||
CreateMap<PostUpdateInputVo, PostEntity>();
|
||||
CreateMap<PostEntity, PostGetListOutputDto>();
|
||||
CreateMap<PostEntity, PostGetOutputDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity.MapperConfig
|
||||
{
|
||||
public class RoleProfile: Profile
|
||||
{
|
||||
public RoleProfile()
|
||||
{
|
||||
CreateMap<RoleGetListInputVo, RoleEntity>();
|
||||
CreateMap<RoleCreateInputVo, RoleEntity>();
|
||||
CreateMap<RoleUpdateInputVo, RoleEntity>();
|
||||
CreateMap<RoleEntity, RoleGetListOutputDto>();
|
||||
CreateMap<RoleEntity, RoleGetOutputDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Yi.RBAC.Application.Contracts.Identity;
|
||||
using NET.AutoWebApi.Setting;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
using Yi.Framework.Ddd.Services;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Menu服务实现
|
||||
/// </summary>
|
||||
[AppService]
|
||||
public class MenuService : CrudAppService<MenuEntity, MenuGetOutputDto, MenuGetListOutputDto, long, MenuGetListInputVo, MenuCreateInputVo, MenuUpdateInputVo>,
|
||||
IMenuService, IAutoApiService
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Yi.RBAC.Application.Contracts.Identity;
|
||||
using NET.AutoWebApi.Setting;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
using Yi.Framework.Ddd.Services;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Post服务实现
|
||||
/// </summary>
|
||||
[AppService]
|
||||
public class PostService : CrudAppService<PostEntity, PostGetOutputDto, PostGetListOutputDto, long, PostGetListInputVo, PostCreateInputVo, PostUpdateInputVo>,
|
||||
IPostService, IAutoApiService
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Yi.RBAC.Application.Contracts.Identity;
|
||||
using NET.AutoWebApi.Setting;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
using Yi.Framework.Ddd.Services;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Role服务实现
|
||||
/// </summary>
|
||||
[AppService]
|
||||
public class RoleService : CrudAppService<RoleEntity, RoleGetOutputDto, RoleGetListOutputDto, long, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>,
|
||||
IRoleService, IAutoApiService
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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.Shared.Identity.ConstClasses;
|
||||
using Yi.RBAC.Domain.Identity;
|
||||
using Yi.Framework.Uow;
|
||||
|
||||
namespace Yi.RBAC.Application.Identity
|
||||
{
|
||||
@@ -13,5 +16,41 @@ namespace Yi.RBAC.Application.Identity
|
||||
public class UserService : CrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, long, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,
|
||||
IUserService, IAutoApiService
|
||||
{
|
||||
[Autowired]
|
||||
private UserManager _userManager { get; set; }
|
||||
|
||||
[Autowired]
|
||||
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.Password))
|
||||
{
|
||||
throw new UserFriendlyException(UserConst.添加失败_密码为空);
|
||||
}
|
||||
if (await _repository.IsAnyAsync(u => input.UserName.Equals(u.UserName)))
|
||||
{
|
||||
throw new UserFriendlyException(UserConst.添加失败_用户存在);
|
||||
}
|
||||
var entities = await MapToEntityAsync(input);
|
||||
|
||||
entities.BuildPassword();
|
||||
|
||||
using (var uow = _unitOfWorkManager.CreateContext())
|
||||
{
|
||||
var returnEntity = await _repository.InsertReturnEntityAsync(entities);
|
||||
await _userManager.GiveUserSetRoleAsync(new List<long> { returnEntity.Id }, input.RoleIds);
|
||||
await _userManager.GiveUserSetPostAsync(new List<long> { returnEntity.Id }, input.PostIds);
|
||||
uow.Commit();
|
||||
|
||||
var result = await MapToGetOutputDtoAsync(returnEntity);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user