完善登录

This commit is contained in:
陈淳
2023-01-31 18:08:27 +08:00
parent b7260ed982
commit 5fb09c1c4a
77 changed files with 2333 additions and 288 deletions

View File

@@ -11,15 +11,38 @@
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.DeptService">
<summary>
Dept服务实现
</summary>
</member>
<member name="T:Yi.RBAC.Application.Identity.MenuService">
<summary>
Menu服务实现
</summary>
</member>
<member name="T:Yi.RBAC.Application.Identity.PostService">
<summary>
Post服务实现
</summary>
</member>
<member name="T:Yi.RBAC.Application.Identity.RoleService">
<summary>
Role服务实现
</summary>
</member>
<member name="T:Yi.RBAC.Application.Identity.UserService">
<summary>
User服务实现
</summary>
</member>
<member name="T:Yi.RBAC.Application.School.StudentService">
<member name="M:Yi.RBAC.Application.Identity.UserService.CreateAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.UserCreateInputVo)">
<summary>
Student服务实现
添加用户
</summary>
<param name="input"></param>
<returns></returns>
<exception cref="T:Yi.Framework.Core.Exceptions.UserFriendlyException"></exception>
</member>
</members>
</doc>

View File

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

View File

@@ -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
{
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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
{
}
}

View File

@@ -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
{
}
}

View File

@@ -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
{
}
}

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

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.School.Dtos;
using Yi.RBAC.Domain.School.Entities;
namespace Yi.RBAC.Application.School.MapperConfig
{
public class StudentProfile: Profile
{
public StudentProfile()
{
CreateMap<StudentGetListInputVo, StudentEntity>();
CreateMap<StudentCreateInputVo, StudentEntity>();
CreateMap<StudentUpdateInputVo, StudentEntity>();
CreateMap<StudentEntity, StudentGetListOutputDto>();
CreateMap<StudentEntity, StudentGetOutputDto>();
}
}
}

View File

@@ -1,17 +0,0 @@
using Yi.RBAC.Application.Contracts.School;
using NET.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.School.Dtos;
using Yi.RBAC.Domain.School.Entities;
using Yi.Framework.Ddd.Services;
namespace Yi.RBAC.Application.School
{
/// <summary>
/// Student服务实现
/// </summary>
[AppService]
public class StudentService : CrudAppService<StudentEntity, StudentGetOutputDto, StudentGetListOutputDto, long, StudentGetListInputVo, StudentCreateInputVo, StudentUpdateInputVo>,
IStudentService, IAutoApiService
{
}
}