|
@ -72,9 +72,9 @@ namespace BaseService.Systems.UserManagement |
|
|
[Route("{id}")] |
|
|
[Route("{id}")] |
|
|
public async Task<IdentityUserUpdateDto> GetAsync(Guid id) |
|
|
public async Task<IdentityUserUpdateDto> GetAsync(Guid id) |
|
|
{ |
|
|
{ |
|
|
var user = await UserManager.GetByIdAsync(id); |
|
|
var user = await UserManager.GetByIdAsync(id).ConfigureAwait(false); |
|
|
var dto = Mapper.Map<IdentityUserUpdateDto>(user); |
|
|
var dto = Mapper.Map<IdentityUserUpdateDto>(user); |
|
|
dto.RoleNames = (await UserRepository.GetRoleNamesAsync(id)).ToArray(); |
|
|
dto.RoleNames = (await UserRepository.GetRoleNamesAsync(id).ConfigureAwait(false)).ToArray(); |
|
|
return dto; |
|
|
return dto; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -88,7 +88,7 @@ namespace BaseService.Systems.UserManagement |
|
|
public async Task<IdentityUserDto> GetCurrentUserAsync() |
|
|
public async Task<IdentityUserDto> GetCurrentUserAsync() |
|
|
{ |
|
|
{ |
|
|
var id = CurrentUser.GetId(); |
|
|
var id = CurrentUser.GetId(); |
|
|
var currentUser = await UserManager.GetByIdAsync(id); |
|
|
var currentUser = await UserManager.GetByIdAsync(id).ConfigureAwait(false); |
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(currentUser); |
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(currentUser); |
|
|
|
|
|
|
|
|
return dto; |
|
|
return dto; |
|
@ -107,12 +107,12 @@ namespace BaseService.Systems.UserManagement |
|
|
|
|
|
|
|
|
input.MapExtraPropertiesTo(user); |
|
|
input.MapExtraPropertiesTo(user); |
|
|
|
|
|
|
|
|
(await UserManager.CreateAsync(user, input.Password)).CheckErrors(); |
|
|
(await UserManager.CreateAsync(user, input.Password).ConfigureAwait(false)).CheckErrors(); |
|
|
await UpdateAsync(user, input); |
|
|
await UpdateAsync(user, input).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); |
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); |
|
|
|
|
|
|
|
|
await CurrentUnitOfWork.SaveChangesAsync(); |
|
|
await CurrentUnitOfWork.SaveChangesAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
|
return dto; |
|
|
return dto; |
|
|
} |
|
|
} |
|
@ -122,25 +122,25 @@ namespace BaseService.Systems.UserManagement |
|
|
[Authorize(IdentityPermissions.Users.Update)] |
|
|
[Authorize(IdentityPermissions.Users.Update)] |
|
|
public async Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) |
|
|
public async Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) |
|
|
{ |
|
|
{ |
|
|
var user = await UserManager.GetByIdAsync(id); |
|
|
var user = await UserManager.GetByIdAsync(id).ConfigureAwait(false); |
|
|
user.ConcurrencyStamp = input.ConcurrencyStamp; |
|
|
user.ConcurrencyStamp = input.ConcurrencyStamp; |
|
|
|
|
|
|
|
|
(await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); |
|
|
(await UserManager.SetUserNameAsync(user, input.UserName).ConfigureAwait(false)).CheckErrors(); |
|
|
|
|
|
|
|
|
await UpdateAsync(user, input); |
|
|
await UpdateAsync(user, input).ConfigureAwait(false); |
|
|
input.MapExtraPropertiesTo(user); |
|
|
input.MapExtraPropertiesTo(user); |
|
|
|
|
|
|
|
|
(await UserManager.UpdateAsync(user)).CheckErrors(); |
|
|
(await UserManager.UpdateAsync(user).ConfigureAwait(false)).CheckErrors(); |
|
|
|
|
|
|
|
|
if (!input.Password.IsNullOrEmpty()) |
|
|
if (!input.Password.IsNullOrEmpty()) |
|
|
{ |
|
|
{ |
|
|
(await UserManager.RemovePasswordAsync(user)).CheckErrors(); |
|
|
(await UserManager.RemovePasswordAsync(user).ConfigureAwait(false)).CheckErrors(); |
|
|
(await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors(); |
|
|
(await UserManager.AddPasswordAsync(user, input.Password).ConfigureAwait(false)).CheckErrors(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); |
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); |
|
|
|
|
|
|
|
|
await CurrentUnitOfWork.SaveChangesAsync(); |
|
|
await CurrentUnitOfWork.SaveChangesAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
|
return dto; |
|
|
return dto; |
|
|
} |
|
|
} |
|
@ -148,9 +148,9 @@ namespace BaseService.Systems.UserManagement |
|
|
[HttpGet] |
|
|
[HttpGet] |
|
|
public async Task<PagedResultDto<IdentityUserDto>> GetAll(GetIdentityUsersInput input) |
|
|
public async Task<PagedResultDto<IdentityUserDto>> GetAll(GetIdentityUsersInput input) |
|
|
{ |
|
|
{ |
|
|
var totalCount = await UserRepository.GetCountAsync(input.Filter); |
|
|
var totalCount = await UserRepository.GetCountAsync(input.Filter).ConfigureAwait(false); |
|
|
var items = await UserRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, |
|
|
var items = await UserRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, |
|
|
input.Filter); |
|
|
input.Filter).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
var dtos = ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(items); |
|
|
var dtos = ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(items); |
|
|
|
|
|
|
|
@ -163,24 +163,24 @@ namespace BaseService.Systems.UserManagement |
|
|
{ |
|
|
{ |
|
|
if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase)) |
|
|
if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase)) |
|
|
{ |
|
|
{ |
|
|
(await UserManager.SetEmailAsync(user, input.Email)).CheckErrors(); |
|
|
(await UserManager.SetEmailAsync(user, input.Email).ConfigureAwait(false)).CheckErrors(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase)) |
|
|
if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase)) |
|
|
{ |
|
|
{ |
|
|
(await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); |
|
|
(await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber).ConfigureAwait(false)).CheckErrors(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//说明:从3.1升级到3.3后,去掉了TwoFactorEnabled属性
|
|
|
//说明:从3.1升级到3.3后,去掉了TwoFactorEnabled属性
|
|
|
//(await UserManager.SetTwoFactorEnabledAsync(user, input.TwoFactorEnabled)).CheckErrors();
|
|
|
//(await UserManager.SetTwoFactorEnabledAsync(user, input.TwoFactorEnabled)).CheckErrors();
|
|
|
(await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors(); |
|
|
(await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled).ConfigureAwait(false)).CheckErrors(); |
|
|
|
|
|
|
|
|
user.Name = input.Name; |
|
|
user.Name = input.Name; |
|
|
user.Surname = input.Surname; |
|
|
user.Surname = input.Surname; |
|
|
|
|
|
|
|
|
if (input.RoleNames != null) |
|
|
if (input.RoleNames != null) |
|
|
{ |
|
|
{ |
|
|
(await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); |
|
|
(await UserManager.SetRolesAsync(user, input.RoleNames).ConfigureAwait(false)).CheckErrors(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -195,7 +195,7 @@ namespace BaseService.Systems.UserManagement |
|
|
{ |
|
|
{ |
|
|
var branchList = new List<BranchRoleDto>(); |
|
|
var branchList = new List<BranchRoleDto>(); |
|
|
//获取用户的所有分支
|
|
|
//获取用户的所有分支
|
|
|
var branchRoles = await GetUserBranchRolesAsync(CurrentUsers.GetId()); |
|
|
var branchRoles = await GetUserBranchRolesAsync(CurrentUsers.GetId()).ConfigureAwait(false); |
|
|
var groupBranchRoles = branchRoles.GroupBy(x => x.BranchId) |
|
|
var groupBranchRoles = branchRoles.GroupBy(x => x.BranchId) |
|
|
.Select(y => new { xx = new { BranchId = y.Key }, items = y }); |
|
|
.Select(y => new { xx = new { BranchId = y.Key }, items = y }); |
|
|
foreach (var group in groupBranchRoles |
|
|
foreach (var group in groupBranchRoles |
|
@ -204,7 +204,7 @@ namespace BaseService.Systems.UserManagement |
|
|
var mybranchrole = new BranchRoleDto |
|
|
var mybranchrole = new BranchRoleDto |
|
|
{ |
|
|
{ |
|
|
BranchId = @group.xx.BranchId, |
|
|
BranchId = @group.xx.BranchId, |
|
|
BranchName = (await _branchRepository.GetListAsync()) |
|
|
BranchName = (await _branchRepository.GetListAsync().ConfigureAwait(false)) |
|
|
.FirstOrDefault(_ => _.Id == @group.xx.BranchId)?.Name |
|
|
.FirstOrDefault(_ => _.Id == @group.xx.BranchId)?.Name |
|
|
}; |
|
|
}; |
|
|
branchList.Add(mybranchrole); |
|
|
branchList.Add(mybranchrole); |
|
@ -224,7 +224,7 @@ namespace BaseService.Systems.UserManagement |
|
|
{ |
|
|
{ |
|
|
var branchList = new List<BranchRoleDto>(); |
|
|
var branchList = new List<BranchRoleDto>(); |
|
|
//获取用户的所有分支
|
|
|
//获取用户的所有分支
|
|
|
var branchRoles = await GetUserBranchRolesAsync(userId); |
|
|
var branchRoles = await GetUserBranchRolesAsync(userId).ConfigureAwait(false); |
|
|
var groupBranchRoles = branchRoles.GroupBy(x => x.BranchId) |
|
|
var groupBranchRoles = branchRoles.GroupBy(x => x.BranchId) |
|
|
.Select(y => new { xx = new { BranchId = y.Key }, items = y }); |
|
|
.Select(y => new { xx = new { BranchId = y.Key }, items = y }); |
|
|
foreach (var group in groupBranchRoles) |
|
|
foreach (var group in groupBranchRoles) |
|
@ -232,7 +232,7 @@ namespace BaseService.Systems.UserManagement |
|
|
var mybranchrole = new BranchRoleDto |
|
|
var mybranchrole = new BranchRoleDto |
|
|
{ |
|
|
{ |
|
|
BranchId = @group.xx.BranchId, |
|
|
BranchId = @group.xx.BranchId, |
|
|
BranchName = (await _branchRepository.GetListAsync()) |
|
|
BranchName = (await _branchRepository.GetListAsync().ConfigureAwait(false)) |
|
|
.FirstOrDefault(_ => _.Id == @group.xx.BranchId) |
|
|
.FirstOrDefault(_ => _.Id == @group.xx.BranchId) |
|
|
.Name |
|
|
.Name |
|
|
}; |
|
|
}; |
|
@ -252,12 +252,12 @@ namespace BaseService.Systems.UserManagement |
|
|
{ |
|
|
{ |
|
|
// var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList();
|
|
|
// var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList();
|
|
|
var listPermiss = new List<PermissionGrant>(); |
|
|
var listPermiss = new List<PermissionGrant>(); |
|
|
var listRolesName = await UserRepository.GetRoleNamesAsync(userId); |
|
|
var listRolesName = await UserRepository.GetRoleNamesAsync(userId).ConfigureAwait(false); |
|
|
if (listRolesName != null) |
|
|
if (listRolesName != null) |
|
|
{ |
|
|
{ |
|
|
foreach (var rolename in listRolesName) |
|
|
foreach (var rolename in listRolesName) |
|
|
{ |
|
|
{ |
|
|
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, rolename); |
|
|
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, rolename).ConfigureAwait(false); |
|
|
if (permissionGrantsInRole != null) |
|
|
if (permissionGrantsInRole != null) |
|
|
{ |
|
|
{ |
|
|
foreach (var permiss in permissionGrantsInRole) |
|
|
foreach (var permiss in permissionGrantsInRole) |
|
@ -279,7 +279,7 @@ namespace BaseService.Systems.UserManagement |
|
|
{ |
|
|
{ |
|
|
var branchList = new List<BranchRole>(); |
|
|
var branchList = new List<BranchRole>(); |
|
|
//获取当前用户的所有角色
|
|
|
//获取当前用户的所有角色
|
|
|
var userRoles = await UserRepository.GetRolesAsync(userId); |
|
|
var userRoles = await UserRepository.GetRolesAsync(userId).ConfigureAwait(false); |
|
|
if (userRoles == null) |
|
|
if (userRoles == null) |
|
|
{ |
|
|
{ |
|
|
throw new BusinessException("当前登录用户没有任何角色信息,请找管理员进行维护!"); |
|
|
throw new BusinessException("当前登录用户没有任何角色信息,请找管理员进行维护!"); |
|
@ -287,7 +287,7 @@ namespace BaseService.Systems.UserManagement |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
//获取所有分支-角色的信息
|
|
|
//获取所有分支-角色的信息
|
|
|
var allBranchRoles = await _branchRoleRepository.GetListAsync(); |
|
|
var allBranchRoles = await _branchRoleRepository.GetListAsync().ConfigureAwait(false); |
|
|
if (allBranchRoles != null) |
|
|
if (allBranchRoles != null) |
|
|
{ |
|
|
{ |
|
|
foreach (var role in userRoles) |
|
|
foreach (var role in userRoles) |
|
@ -296,7 +296,10 @@ namespace BaseService.Systems.UserManagement |
|
|
foreach (var branch in branchRoles) |
|
|
foreach (var branch in branchRoles) |
|
|
{ |
|
|
{ |
|
|
if (branch == null) |
|
|
if (branch == null) |
|
|
|
|
|
{ |
|
|
continue; //该用户没有角色-分支信息
|
|
|
continue; //该用户没有角色-分支信息
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var branchRole = new BranchRole(branch.BranchId, role.Id); |
|
|
var branchRole = new BranchRole(branch.BranchId, role.Id); |
|
|
branchList.Add(branchRole); |
|
|
branchList.Add(branchRole); |
|
|
} |
|
|
} |
|
@ -322,7 +325,7 @@ namespace BaseService.Systems.UserManagement |
|
|
public async Task<ApplicationAuthes> GetAuthConfigAsync(Guid branchId) |
|
|
public async Task<ApplicationAuthes> GetAuthConfigAsync(Guid branchId) |
|
|
{ |
|
|
{ |
|
|
var authConfig = new ApplicationAuthes(); |
|
|
var authConfig = new ApplicationAuthes(); |
|
|
var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync(); |
|
|
var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync().ConfigureAwait(false); |
|
|
foreach (var policyName in policyNames) |
|
|
foreach (var policyName in policyNames) |
|
|
{ |
|
|
{ |
|
|
authConfig.Policies[policyName] = true; |
|
|
authConfig.Policies[policyName] = true; |
|
@ -335,9 +338,9 @@ namespace BaseService.Systems.UserManagement |
|
|
var userId = CurrentUsers.GetId(); |
|
|
var userId = CurrentUsers.GetId(); |
|
|
|
|
|
|
|
|
//获取当前用户的所有权限信息
|
|
|
//获取当前用户的所有权限信息
|
|
|
var getUserPermissions = await GetUserGrantedPermissionsAsync(userId); |
|
|
var getUserPermissions = await GetUserGrantedPermissionsAsync(userId).ConfigureAwait(false); |
|
|
//获取当前用户的所有分支
|
|
|
//获取当前用户的所有分支
|
|
|
var gerUserBranches = await GetUserBranchRolesAsync(userId); |
|
|
var gerUserBranches = await GetUserBranchRolesAsync(userId).ConfigureAwait(false); |
|
|
if (gerUserBranches == null) |
|
|
if (gerUserBranches == null) |
|
|
{ |
|
|
{ |
|
|
throw new BusinessException("当前登录用户没有任何分支信息,请找管理员进行维护!"); |
|
|
throw new BusinessException("当前登录用户没有任何分支信息,请找管理员进行维护!"); |
|
@ -395,13 +398,13 @@ namespace BaseService.Systems.UserManagement |
|
|
[Authorize(IdentityPermissions.Users.Update)] |
|
|
[Authorize(IdentityPermissions.Users.Update)] |
|
|
public async Task<IdentityUserDto> ResetPasswordAsync(Guid userId) |
|
|
public async Task<IdentityUserDto> ResetPasswordAsync(Guid userId) |
|
|
{ |
|
|
{ |
|
|
var user = await UserManager.FindByIdAsync(userId.ToString()); |
|
|
var user = await UserManager.FindByIdAsync(userId.ToString()).ConfigureAwait(false); |
|
|
//string token = await UserManager.GeneratePasswordResetTokenAsync(user);//err:No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered.
|
|
|
//string token = await UserManager.GeneratePasswordResetTokenAsync(user);//err:No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered.
|
|
|
//await UserManager.ResetPasswordAsync(user, token, "1q2w3E*");
|
|
|
//await UserManager.ResetPasswordAsync(user, token, "1q2w3E*");
|
|
|
await UserManager.RemovePasswordAsync(user); |
|
|
await UserManager.RemovePasswordAsync(user).ConfigureAwait(false); |
|
|
if (user.PasswordHash == null) |
|
|
if (user.PasswordHash == null) |
|
|
{ |
|
|
{ |
|
|
(await UserManager.AddPasswordAsync(user, "123456")).CheckErrors(); |
|
|
(await UserManager.AddPasswordAsync(user, "123456").ConfigureAwait(false)).CheckErrors(); |
|
|
} |
|
|
} |
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); |
|
|
var dto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); |
|
|
|
|
|
|
|
|