diff --git a/src/Shentun.Peis.Application.Contracts/PeisApplicationContractsModule.cs b/src/Shentun.Peis.Application.Contracts/PeisApplicationContractsModule.cs
index d4846d0d..47974830 100644
--- a/src/Shentun.Peis.Application.Contracts/PeisApplicationContractsModule.cs
+++ b/src/Shentun.Peis.Application.Contracts/PeisApplicationContractsModule.cs
@@ -1,4 +1,6 @@
-using Volo.Abp.Account;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.Account;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
@@ -7,6 +9,7 @@ using Volo.Abp.PermissionManagement;
using Volo.Abp.SettingManagement;
using Volo.Abp.TenantManagement;
+
namespace Shentun.Peis;
[DependsOn(
diff --git a/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissionDefinitionProvider.cs b/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissionDefinitionProvider.cs
index 64433e37..e657ee3e 100644
--- a/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissionDefinitionProvider.cs
+++ b/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissionDefinitionProvider.cs
@@ -9,66 +9,32 @@ public class PeisPermissionDefinitionProvider : PermissionDefinitionProvider
{
public override void Define(IPermissionDefinitionContext context)
{
- var myGroup = context.AddGroup(PeisPermissions.GroupName);
- //Define your own permissions here. Example:
- //myGroup.AddPermission(PeisPermissions.MyPermission1, L("Permission:MyPermission1"));
-
- //var booksPermission = myGroup.AddPermission(PeisPermissions.Books.Default, L("Permission:Books"));
- //booksPermission.AddChild(PeisPermissions.Books.Create, L("Permission:Books.Create"));
- //booksPermission.AddChild(PeisPermissions.Books.Edit, L("Permission:Books.Edit"));
- //booksPermission.AddChild(PeisPermissions.Books.Delete, L("Permission:Books.Delete"));
-
-
- //配置权限选项
- var organizationUnitsPermission = myGroup.AddPermission(PeisPermissions.OrganizationUnits.Default, L("Permission:OrganizationUnits"));
- organizationUnitsPermission.AddChild(PeisPermissions.OrganizationUnits.Create, L("Permission:OrganizationUnits.Create"));
- organizationUnitsPermission.AddChild(PeisPermissions.OrganizationUnits.Edit, L("Permission:OrganizationUnits.Edit"));
- organizationUnitsPermission.AddChild(PeisPermissions.OrganizationUnits.Delete, L("Permission:OrganizationUnits.Delete"));
-
-
-
- #region 用户跟角色
-
- var myUserManagerGroupName = context.AddGroup(PeisPermissions.UserManagerGroupName);
-
- var userManagerPermission_User = myUserManagerGroupName.AddPermission(PeisPermissions.Users.Default, L("Permission:Users"));
- userManagerPermission_User.AddChild(PeisPermissions.Users.Create, L("Permission:Users.Create"));
- userManagerPermission_User.AddChild(PeisPermissions.Users.Edit, L("Permission:Users.Edit"));
- userManagerPermission_User.AddChild(PeisPermissions.Users.Delete, L("Permission:Users.Delete"));
-
- var userManagerPermission_Role = myUserManagerGroupName.AddPermission(PeisPermissions.Roles.Default, L("Permission:Roles"));
- userManagerPermission_Role.AddChild(PeisPermissions.Roles.Create, L("Permission:Roles.Create"));
- userManagerPermission_Role.AddChild(PeisPermissions.Roles.Edit, L("Permission:Roles.Edit"));
- userManagerPermission_Role.AddChild(PeisPermissions.Roles.Delete, L("Permission:Roles.Delete"));
-
- #endregion
-
+
#region 系统设置
- var mySystemSettingsGroupName = context.AddGroup(PeisPermissions.SystemSettingsGroupName);
+ var mySystemSettingsGroupName = context.AddGroup(PeisPermissions.SystemSettingsGroupName,L("Peis:SystemSettings"));
- var systemSettingsPermission_GuideType = mySystemSettingsGroupName.AddPermission(PeisPermissions.GuideTypes.Default, L("Permission:GuideTypes"));
- systemSettingsPermission_GuideType.AddChild(PeisPermissions.GuideTypes.Create, L("Permission:GuideTypes.Create"));
- systemSettingsPermission_GuideType.AddChild(PeisPermissions.GuideTypes.Edit, L("Permission:GuideTypes.Edit"));
- var s1 = systemSettingsPermission_GuideType.AddChild(PeisPermissions.GuideTypes.Delete, L("Permission:GuideTypes.Delete"));
+ mySystemSettingsGroupName.AddPermission(PeisPermissions.SystemSettings.Default, L("Peis:SystemSettings:Default"));
+ mySystemSettingsGroupName.AddPermission(PeisPermissions.SystemSettings.BaseData, L("Peis:SystemSettings:BaseData"));
- // s1.AddChild(PeisPermissions.GuideTypes.Delete + "333", L("Permission:GuideTypes.Delete"));
+ #endregion
- #endregion
#region 第三方接口
var myThirdGroupName = context.AddGroup(PeisPermissions.ThirdGroupName, L("Peis:Third"));
- myThirdGroupName.AddPermission(PeisPermissions.Third.Default, L("Permission:Third"));
+ myThirdGroupName.AddPermission(PeisPermissions.Third.Default, L("Peis:Third:Default"));
#endregion
+ #region 业务权限
+
+ var myBusinessGroupName = context.AddGroup(PeisPermissions.BusinessGroupName, L("Peis:Business"));
+ myBusinessGroupName.AddPermission(PeisPermissions.Business.Default, L("Peis:Business:Default"));
- #region 基础数据接口权限
- var myBaseDataGroupName = context.AddGroup(PeisPermissions.BaseDataGroupName, L("Peis:BaseData"));
- myBaseDataGroupName.AddPermission(PeisPermissions.BaseData.Default, L("Permission:BaseData"));
#endregion
+
}
private static LocalizableString L(string name)
diff --git a/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissions.cs b/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissions.cs
index f7486b65..e293e60d 100644
--- a/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissions.cs
+++ b/src/Shentun.Peis.Application.Contracts/Permissions/PeisPermissions.cs
@@ -3,71 +3,37 @@
public static class PeisPermissions
{
+
+ #region 系统设置
- public const string GroupName = "Peis";
-
- //Add your own permission names. Example:
- //public const string MyPermission1 = GroupName + ".MyPermission1";
-
- #region 用户管理
-
- public const string UserManagerGroupName = "Peis.UserManager";
-
-
- public static class Users
- {
- public const string Default = UserManagerGroupName + ".Users";
- public const string Create = Default + ".Create";
- public const string Edit = Default + ".Edit";
- public const string Delete = Default + ".Delete";
- }
+ public const string SystemSettingsGroupName = "Peis.SystemSettings";
- public static class Roles
- {
- public const string Default = UserManagerGroupName + ".Roles";
- public const string Create = Default + ".Create";
- public const string Edit = Default + ".Edit";
- public const string Delete = Default + ".Delete";
- }
+ ///
+ /// 系统设置
+ ///
+ public static class SystemSettings
+ {
- #endregion
+ ///
+ /// 用户等信息维护
+ ///
+ public const string Default = SystemSettingsGroupName + ".Default";
- #region 系统设置
+ ///
+ /// 基础数据维护
+ ///
+ public const string BaseData = SystemSettingsGroupName + ".BaseData";
- public const string SystemSettingsGroupName = "Peis.SystemSettings";
+
- public static class GuideTypes
- {
- public const string Default = SystemSettingsGroupName + ".GuideTypes";
- public const string Create = Default + ".Create";
- public const string Edit = Default + ".Edit";
- public const string Delete = Default + ".Delete";
}
#endregion
- ///
- /// 定义权限
- ///
- public static class Books
- {
- public const string Default = GroupName + ".Books";
- public const string Create = Default + ".Create";
- public const string Edit = Default + ".Edit";
- public const string Delete = Default + ".Delete";
- }
-
-
- public static class OrganizationUnits
- {
- public const string Default = GroupName + ".OrganizationUnits";
- public const string Create = Default + ".Create";
- public const string Edit = Default + ".Edit";
- public const string Delete = Default + ".Delete";
- }
+ #region 第三方接口
///
/// 第三方接口组
@@ -76,17 +42,33 @@ public static class PeisPermissions
public static class Third
{
- public const string Default = "Peis.Third.All";
+ ///
+ /// 第三方接口
+ ///
+ public const string Default = "Peis.Third.Default";
}
+ #endregion
+
+
+ #region 业务权限
+
///
- /// 基础数据接口统一权限
+ /// 业务权限
///
- public const string BaseDataGroupName = "Peis.BaseData";
+ public const string BusinessGroupName = "Peis.Business";
- public static class BaseData
+ public static class Business
{
- public const string Default = "Peis.BaseData.All";
+ ///
+ /// 业务权限
+ ///
+ public const string Default = "Peis.Business.Default";
}
+ #endregion
+
+
+
+
}
diff --git a/src/Shentun.Peis.Application.Contracts/Roles/RoleIdInputDto.cs b/src/Shentun.Peis.Application.Contracts/Roles/RoleIdInputDto.cs
new file mode 100644
index 00000000..ddcb828c
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/Roles/RoleIdInputDto.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.Peis.Roles
+{
+ public class RoleIdInputDto
+ {
+ public Guid Id { get; set; }
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/Roles/UpdateRoleInputDto.cs b/src/Shentun.Peis.Application.Contracts/Roles/UpdateRoleInputDto.cs
new file mode 100644
index 00000000..91c944cb
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/Roles/UpdateRoleInputDto.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Volo.Abp.Identity;
+
+namespace Shentun.Peis.Roles
+{
+ public class UpdateRoleInputDto: IdentityRoleUpdateDto
+ {
+ public Guid Id { get; set; }
+ }
+}
diff --git a/src/Shentun.Peis.Application/Books/BookAppService.cs b/src/Shentun.Peis.Application/Books/BookAppService.cs
deleted file mode 100644
index 8284520f..00000000
--- a/src/Shentun.Peis.Application/Books/BookAppService.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Shentun.Peis.Permissions;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Volo.Abp.Application.Dtos;
-using Volo.Abp.Application.Services;
-using Volo.Abp.Domain.Repositories;
-using Volo.Abp.Identity;
-
-namespace Shentun.Peis.Books
-{
- public class BookAppService : CrudAppService, IBookAppService
- {
-
-
- public BookAppService(IRepository repository) : base(repository)
- {
- GetPolicyName =PeisPermissions.Books.Default;
- GetListPolicyName = PeisPermissions.Books.Default;
- CreatePolicyName = PeisPermissions.Books.Create;
- UpdatePolicyName = PeisPermissions.Books.Edit;
- DeletePolicyName = PeisPermissions.Books.Delete;
- }
- }
-}
diff --git a/src/Shentun.Peis.Application/MyUser/MyUserAppService.cs b/src/Shentun.Peis.Application/MyUser/MyUserAppService.cs
index c102b52f..199750a0 100644
--- a/src/Shentun.Peis.Application/MyUser/MyUserAppService.cs
+++ b/src/Shentun.Peis.Application/MyUser/MyUserAppService.cs
@@ -35,11 +35,13 @@ using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectMapping;
+using Volo.Abp.PermissionManagement;
using Volo.Abp.Security.Encryption;
using Volo.Abp.Users;
namespace Shentun.Peis.MyUser
{
+
///
/// 重写IdentityUser服务
///
@@ -47,7 +49,7 @@ namespace Shentun.Peis.MyUser
////[RemoteService(isEnabled: false)]
[ExposeServices(typeof(IIdentityUserAppService))]
- public class MyUserAppService : IdentityUserAppService
+ public class MyUserAppService : ApplicationService, IIdentityUserAppService
{
private readonly IRepository _identityUserRepository;
private readonly IdentityUserManager _userManager;
@@ -62,6 +64,7 @@ namespace Shentun.Peis.MyUser
private readonly IRepository _identityUserOrganizationUnitRepository;
private readonly CurrentUser _currentUser;
private readonly IDistributedCache _userCache;
+ private readonly IIdentityRoleRepository _roleRepository;
public MyUserAppService(
IRepository identityUserRepository,
@@ -77,11 +80,7 @@ namespace Shentun.Peis.MyUser
IConfiguration configuration,
IRepository identityUserOrganizationUnitRepository,
CurrentUser currentUser,
- IDistributedCache userCache) :
- base(userManager,
- userRepository,
- roleRepository,
- identityOptions)
+ IDistributedCache userCache)
{
this._identityUserRepository = identityUserRepository;
this._userManager = userManager;
@@ -95,6 +94,7 @@ namespace Shentun.Peis.MyUser
this._organizationUnitRepository = organizationUnitRepository;
this._identityUserOrganizationUnitRepository = identityUserOrganizationUnitRepository;
this._currentUser = currentUser;
+ _roleRepository = roleRepository;
_userCache = userCache;
}
@@ -105,7 +105,7 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpGet("api/identity/users/userlistbyrolename")]
public async Task> GetUserListByRoleName(string RoleName)
{
@@ -118,7 +118,7 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/updatepassword")]
public async Task UpdatePassWordAsync(UpdatePasswordDto input)
{
@@ -144,7 +144,7 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/resetpassword")]
public async Task ResetPassWordAsync(ResetPassWordDto input)
{
@@ -164,24 +164,14 @@ namespace Shentun.Peis.MyUser
}
}
- /////
- ///// 创建
- /////
- /////
- /////
- //[Authorize(PeisPermissions.Users.Create)]
- //[HttpPost("api/identity/users/create")]
- //public override Task CreateAsync(IdentityUserCreateDto input)
- //{
- // return base.CreateAsync(input);
- //}
+
///
/// 创建 可以不带邮箱 自动以用户名生成
///
///
///
- [Authorize(PeisPermissions.Users.Create)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/create")]
public async Task CreateAsync(IdentityUserCreateNoEmailDto input)
{
@@ -206,7 +196,7 @@ namespace Shentun.Peis.MyUser
- await IdentityOptions.SetAsync();
+ await _identityOptions.SetAsync();
var user = new IdentityUser(
GuidGenerator.Create(),
@@ -221,9 +211,9 @@ namespace Shentun.Peis.MyUser
newinput.MapExtraPropertiesTo(user);
- (await UserManager.CreateAsync(user, input.Password)).CheckErrors();
+ (await _userManager.CreateAsync(user, input.Password)).CheckErrors();
await UpdateUserByInput(user, newinput);
- (await UserManager.UpdateAsync(user)).CheckErrors();
+ (await _userManager.UpdateAsync(user)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
@@ -242,11 +232,22 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Delete)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/delete")]
- public override Task DeleteAsync(Guid id)
+ public async Task DeleteAsync(Guid id)
{
- return base.DeleteAsync(id);
+ if (CurrentUser.Id == id)
+ {
+ throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
+ }
+
+ var user = await _userManager.FindByIdAsync(id.ToString());
+ if (user == null)
+ {
+ return;
+ }
+
+ (await _userManager.DeleteAsync(user)).CheckErrors();
}
///
@@ -254,18 +255,24 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpGet("api/identity/users/getlist")]
- public override Task> GetListAsync(GetIdentityUsersInput input)
+ public async Task> GetListAsync(GetIdentityUsersInput input)
{
- return base.GetListAsync(input);
+ var count = await _userRepository.GetCountAsync(input.Filter);
+ var list = await _userRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
+
+ return new PagedResultDto(
+ count,
+ ObjectMapper.Map, List>(list)
+ );
}
///
/// 获取列表 根据科室查询 不传科室查所有
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/getlistinorganizationunit")]
public async Task> GetListInOrganizationUnitAsync(OrganizationUnitIdIuputDto input)
{
@@ -323,7 +330,7 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/GetListByOperatorType")]
public async Task> GetListByOperatorTypeAsync(OperatorTypeIuputDto input)
{
@@ -339,24 +346,7 @@ namespace Shentun.Peis.MyUser
return entlistDto;
}
- ///
- /// 修改用户信息
- ///
- ///
- ///
- ///
- //[Authorize(PeisPermissions.Users.Edit)]
- //[HttpPost("api/identity/users/update")]
- [RemoteService(false)]
- public override async Task UpdateAsync(Guid id, IdentityUserUpdateDto input)
- {
- var entityDto = await base.UpdateAsync(id, input);
- var entity = await _identityUserRepository.GetAsync(id);
- _userCache.Set(id, entity);
- return entityDto;
-
- }
///
/// 修改
@@ -364,7 +354,7 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Edit)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/update")]
public async Task UpdateIdentityUserAsync(Guid id, IdentityUserUpdateInputDto input)
{
@@ -385,26 +375,26 @@ namespace Shentun.Peis.MyUser
input.Email = input.UserName + "@qq.com";
- await IdentityOptions.SetAsync();
+ await _identityOptions.SetAsync();
- var user = await UserManager.GetByIdAsync(id);
+ var user = await _userManager.GetByIdAsync(id);
user.SetProperty("user_sign", userSign);
user.SetProperty("user_photo", userPhoto);
user.SetProperty("operator_type", input.OperatorType);
user.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
- (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
+ (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
await UpdateUserByInput(user, input);
input.MapExtraPropertiesTo(user);
- (await UserManager.UpdateAsync(user)).CheckErrors();
+ (await _userManager.UpdateAsync(user)).CheckErrors();
if (!input.Password.IsNullOrEmpty())
{
- (await UserManager.RemovePasswordAsync(user)).CheckErrors();
- (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors();
+ (await _userManager.RemovePasswordAsync(user)).CheckErrors();
+ (await _userManager.AddPasswordAsync(user, input.Password)).CheckErrors();
}
await CurrentUnitOfWork.SaveChangesAsync();
@@ -417,18 +407,7 @@ namespace Shentun.Peis.MyUser
return entityDto;
}
- ///
- /// 获取用户信息 根据ID
- ///
- ///
- ///
- //[Authorize(PeisPermissions.Users.Default)]
- //[HttpGet("api/identity/users/getinfo")]
- [RemoteService(false)]
- public override Task GetAsync(Guid id)
- {
- return base.GetAsync(id);
- }
+
///
@@ -491,11 +470,11 @@ namespace Shentun.Peis.MyUser
///
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpGet("api/identity/users/getinfo")]
public async Task GetWithExtensionAsync(Guid id)
{
- var ent = await UserManager.GetByIdAsync(id);
+ var ent = await _userManager.GetByIdAsync(id);
var userSign = !string.IsNullOrWhiteSpace(ent.GetProperty("user_sign")) ? ImageHelper.GetImageBase64StringAsync(ent.GetProperty("user_sign")) : "";
var userPhoto = !string.IsNullOrWhiteSpace(ent.GetProperty("user_photo")) ? ImageHelper.GetImageBase64StringAsync(ent.GetProperty("user_photo")) : "";
var operatorType = ent.GetProperty("operator_type");
@@ -512,11 +491,13 @@ namespace Shentun.Peis.MyUser
/// 用户ID
/// 角色集合
///
- [Authorize(PeisPermissions.Users.Edit)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpPost("api/identity/users/updateroles")]
- public override Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input)
+ public async Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input)
{
- return base.UpdateRolesAsync(id, input);
+ var user = await _userManager.GetByIdAsync(id);
+ (await _userManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
+ await _userRepository.UpdateAsync(user);
}
@@ -525,49 +506,34 @@ namespace Shentun.Peis.MyUser
///
/// 用户ID
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpGet("api/identity/users/getroles")]
- public override Task> GetRolesAsync(Guid id)
+ public async Task> GetRolesAsync(Guid id)
{
- return base.GetRolesAsync(id);
+
+ var roles = await _userRepository.GetRolesAsync(id);
+
+ return new ListResultDto(
+ ObjectMapper.Map, List>(roles)
+ );
}
+
///
/// 获取当前登录用户的角色信息
///
///
- [Authorize(PeisPermissions.Users.Default)]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
[HttpGet("api/identity/users/getassignableroles")]
- public override Task> GetAssignableRolesAsync()
+ public async Task> GetAssignableRolesAsync()
{
- return base.GetAssignableRolesAsync();
+ var list = await _roleRepository.GetListAsync();
+ return new ListResultDto(
+ ObjectMapper.Map, List>(list));
}
- ///
- /// 暂未用到
- ///
- ///
- ///
- [Authorize(PeisPermissions.Users.Default)]
- [RemoteService(false)]
- public override Task FindByUsernameAsync(string userName)
- {
- return base.FindByUsernameAsync(userName);
- }
-
- ///
- /// 暂未用到
- ///
- ///
- ///
- [Authorize(PeisPermissions.Users.Default)]
- [RemoteService(false)]
- public override Task FindByEmailAsync(string email)
- {
- return base.FindByEmailAsync(email);
- }
///
/// 用户登录
@@ -684,5 +650,58 @@ namespace Shentun.Peis.MyUser
return await client.RequestTokenAsync(request);
}
+ [RemoteService(false)]
+ public Task FindByUsernameAsync(string userName)
+ {
+ throw new NotImplementedException();
+ }
+ [RemoteService(false)]
+ public Task FindByEmailAsync(string email)
+ {
+ throw new NotImplementedException();
+ }
+ [RemoteService(false)]
+ public Task CreateAsync(IdentityUserCreateDto input)
+ {
+ throw new NotImplementedException();
+ }
+
+
+ [RemoteService(false)]
+ public Task GetAsync(Guid id)
+ {
+ throw new NotImplementedException();
+ }
+
+ [RemoteService(false)]
+ public Task UpdateAsync(Guid id, IdentityUserUpdateDto input)
+ {
+ throw new NotImplementedException();
+ }
+
+
+ protected virtual async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input)
+ {
+ if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase))
+ {
+ (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors();
+ }
+
+ if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase))
+ {
+ (await _userManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors();
+ }
+
+ (await _userManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors();
+
+ user.Name = input.Name;
+ user.Surname = input.Surname;
+ (await _userManager.UpdateAsync(user)).CheckErrors();
+ user.SetIsActive(input.IsActive);
+ if (input.RoleNames != null)
+ {
+ (await _userManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
+ }
+ }
}
}
diff --git a/src/Shentun.Peis.Application/MyUser/MyUserAppServiceBak.cs b/src/Shentun.Peis.Application/MyUser/MyUserAppServiceBak.cs
new file mode 100644
index 00000000..d8ebf43a
--- /dev/null
+++ b/src/Shentun.Peis.Application/MyUser/MyUserAppServiceBak.cs
@@ -0,0 +1,721 @@
+using IdentityModel.Client;
+using log4net.ObjectRenderer;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Routing;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Options;
+using Newtonsoft.Json;
+using NPOI.SS.Formula.Functions;
+using NPOI.SS.UserModel;
+using Shentun.Peis.Models;
+using Shentun.Peis.MyUser;
+using Shentun.Peis.OrganizationUnits;
+using Shentun.Peis.Permissions;
+using Shentun.Peis.RegisterCheckPictures;
+using Shentun.Peis.Sexs;
+using Shentun.Utilities;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp;
+using Volo.Abp.Account;
+using Volo.Abp.Application.Dtos;
+using Volo.Abp.Application.Services;
+using Volo.Abp.Caching;
+using Volo.Abp.Data;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Domain.Repositories;
+using Volo.Abp.Identity;
+using Volo.Abp.ObjectExtending;
+using Volo.Abp.ObjectMapping;
+using Volo.Abp.PermissionManagement;
+using Volo.Abp.Security.Encryption;
+using Volo.Abp.Users;
+
+namespace Shentun.Peis.MyUser
+{
+
+ public class MyUserAppServiceBak
+ {
+
+ }
+ /////
+ ///// 重写IdentityUser服务
+ /////
+ //[Dependency(ReplaceServices = true)]
+ //////[RemoteService(isEnabled: false)]
+ //[ExposeServices(typeof(IIdentityUserAppService))]
+
+ //public class MyUserAppServiceBak : IdentityUserAppService
+ //{
+ // private readonly IRepository _identityUserRepository;
+ // private readonly IdentityUserManager _userManager;
+ // private readonly IIdentityUserRepository _userRepository;
+ // private readonly IOptions _identityOptions;
+ // private readonly IPasswordHasher _passwordHasher;
+ // private readonly IStringEncryptionService _stringEncryptionService;
+ // private readonly PeisOrganizationUnitManager _peisOrganizationUnitManager;
+ // private readonly IHttpClientFactory _httpClientFactory;
+ // private readonly IConfiguration _configuration;
+ // private readonly IRepository _organizationUnitRepository;
+ // private readonly IRepository _identityUserOrganizationUnitRepository;
+ // private readonly CurrentUser _currentUser;
+ // private readonly IDistributedCache _userCache;
+
+ // public MyUserAppServiceBak(
+ // IRepository identityUserRepository,
+ // IdentityUserManager userManager,
+ // IIdentityUserRepository userRepository,
+ // IIdentityRoleRepository roleRepository,
+ // IOptions identityOptions,
+ // IPasswordHasher passwordHasher,
+ // IStringEncryptionService stringEncryptionService,
+ // IRepository organizationUnitRepository,
+ // PeisOrganizationUnitManager peisOrganizationUnitManager,
+ // IHttpClientFactory httpClientFactory,
+ // IConfiguration configuration,
+ // IRepository identityUserOrganizationUnitRepository,
+ // CurrentUser currentUser,
+ // IDistributedCache userCache) :
+ // base(userManager,
+ // userRepository,
+ // roleRepository,
+ // identityOptions)
+ // {
+ // this._identityUserRepository = identityUserRepository;
+ // this._userManager = userManager;
+ // this._userRepository = userRepository;
+ // this._identityOptions = identityOptions;
+ // this._passwordHasher = passwordHasher;
+ // this._stringEncryptionService = stringEncryptionService;
+ // this._peisOrganizationUnitManager = peisOrganizationUnitManager;
+ // this._httpClientFactory = httpClientFactory;
+ // this._configuration = configuration;
+ // this._organizationUnitRepository = organizationUnitRepository;
+ // this._identityUserOrganizationUnitRepository = identityUserOrganizationUnitRepository;
+ // this._currentUser = currentUser;
+ // _userCache = userCache;
+ // }
+
+
+
+ // ///
+ // /// 根据角色查询用户列表
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpGet("api/identity/users/userlistbyrolename")]
+ // public async Task> GetUserListByRoleName(string RoleName)
+ // {
+ // var userlist = await _userRepository.GetListByNormalizedRoleNameAsync(RoleName);
+ // return ObjectMapper.Map, List>(userlist);
+ // }
+
+ // ///
+ // /// 修改用户密码 修改自身密码
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/updatepassword")]
+ // public async Task UpdatePassWordAsync(UpdatePasswordDto input)
+ // {
+ // var user = await _userManager.FindByIdAsync(_currentUser.Id.ToString());
+ // if (user != null)
+ // {
+ // var isPassWord = await _userManager.CheckPasswordAsync(user, input.OldPassWord);
+ // if (!isPassWord)
+ // {
+ // throw new UserFriendlyException("原密码不正确");
+ // }
+
+ // await _userManager.RemovePasswordAsync(user);
+
+ // await _userManager.AddPasswordAsync(user, input.NewPassWord);
+
+ // }
+ // }
+
+
+ // ///
+ // /// 管理员重置用户密码
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/resetpassword")]
+ // public async Task ResetPassWordAsync(ResetPassWordDto input)
+ // {
+ // var user = await _userManager.FindByIdAsync(input.UserId.ToString());
+ // if (user != null)
+ // {
+ // var RemoveMsg = await _userManager.RemovePasswordAsync(user);
+
+ // if (!RemoveMsg.Succeeded)
+ // throw new UserFriendlyException($"操作失败,{RemoveMsg.Errors.FirstOrDefault().Code}");
+
+ // var AddPasswordMsg = await _userManager.AddPasswordAsync(user, input.NewPassWord);
+
+ // if (!AddPasswordMsg.Succeeded)
+ // throw new UserFriendlyException($"操作失败,{AddPasswordMsg.Errors.FirstOrDefault().Code}");
+
+ // }
+ // }
+
+ // /////
+ // ///// 创建
+ // /////
+ // /////
+ // /////
+ // //[Authorize(PeisPermissions.Users.Create)]
+ // //[HttpPost("api/identity/users/create")]
+ // //public override Task CreateAsync(IdentityUserCreateDto input)
+ // //{
+ // // return base.CreateAsync(input);
+ // //}
+
+ // ///
+ // /// 创建 可以不带邮箱 自动以用户名生成
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/create")]
+ // public async Task CreateAsync(IdentityUserCreateNoEmailDto input)
+ // {
+ // #region 上传图片
+ // string userPhoto = UploadUserPhotoAsync(new UploadUserPhotoInputDto { PictureBaseStr = input.UserPhoto });
+ // string userSign = UploadUserSignAsync(new UploadUserPhotoInputDto { PictureBaseStr = input.UserSign });
+ // #endregion
+
+
+ // IdentityUserCreateDto newinput = new IdentityUserCreateDto
+ // {
+ // Email = string.IsNullOrWhiteSpace(input.Email) ? input.UserName + "@qq.com" : input.Email,
+ // IsActive = input.IsActive,
+ // LockoutEnabled = input.LockoutEnabled,
+ // Name = input.Name,
+ // Password = input.Password,
+ // PhoneNumber = input.PhoneNumber,
+ // RoleNames = input.RoleNames,
+ // Surname = input.Surname,
+ // UserName = input.UserName
+ // };
+
+
+
+ // await IdentityOptions.SetAsync();
+
+ // var user = new IdentityUser(
+ // GuidGenerator.Create(),
+ // newinput.UserName,
+ // newinput.Email,
+ // CurrentTenant.Id
+ // );
+
+ // user.SetProperty("user_photo", userPhoto);
+ // user.SetProperty("user_sign", userSign);
+ // user.SetProperty("operator_type", input.OperatorType);
+
+ // newinput.MapExtraPropertiesTo(user);
+
+ // (await UserManager.CreateAsync(user, input.Password)).CheckErrors();
+ // await UpdateUserByInput(user, newinput);
+ // (await UserManager.UpdateAsync(user)).CheckErrors();
+
+ // await CurrentUnitOfWork.SaveChangesAsync();
+
+ // var entityDto = ObjectMapper.Map(user);
+
+
+
+
+ // var entity = await _identityUserRepository.GetAsync(entityDto.Id);
+ // _userCache.Set(entityDto.Id, entity);
+ // return entityDto;
+ // }
+
+ // ///
+ // /// 删除用户
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/delete")]
+ // public override async Task DeleteAsync(Guid id)
+ // {
+ // if (CurrentUser.Id == id)
+ // {
+ // throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
+ // }
+
+ // var user = await UserManager.FindByIdAsync(id.ToString());
+ // if (user == null)
+ // {
+ // return;
+ // }
+
+ // (await UserManager.DeleteAsync(user)).CheckErrors();
+ // }
+
+ // ///
+ // /// 获取列表
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpGet("api/identity/users/getlist")]
+ // public override async Task> GetListAsync(GetIdentityUsersInput input)
+ // {
+ // var count = await UserRepository.GetCountAsync(input.Filter);
+ // var list = await UserRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
+
+ // return new PagedResultDto(
+ // count,
+ // ObjectMapper.Map, List>(list)
+ // );
+ // }
+ // ///
+ // /// 获取列表 根据科室查询 不传科室查所有
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/getlistinorganizationunit")]
+ // public async Task> GetListInOrganizationUnitAsync(OrganizationUnitIdIuputDto input)
+ // {
+
+ // List userList = new List();
+
+ // var identityUserOrganizationUnitList = await _identityUserOrganizationUnitRepository.GetListAsync();
+
+ // if (input.OrganizationUnitId != null && input.OrganizationUnitId != Guid.Empty)
+ // {
+ // List organizationUnitIds = await _peisOrganizationUnitManager.GetOrganizationUnitChildIds(input.OrganizationUnitId.Value);
+ // userList = await _userRepository.GetUsersInOrganizationsListAsync(organizationUnitIds);
+ // }
+ // else
+ // {
+ // userList = await _identityUserRepository.GetListAsync(m => m.IsDeleted == false);
+ // }
+ // var entlistdto = userList.Select(s => new IdentityUserWithExtensionDto
+ // {
+ // UserSign = s.GetProperty("user_sign"),
+ // UserPhoto = s.GetProperty("user_photo"),
+ // OperatorType = s.GetProperty("operator_type"),
+ // ConcurrencyStamp = s.ConcurrencyStamp,
+ // CreationTime = s.CreationTime,
+ // CreatorId = s.CreatorId,
+ // DeleterId = s.DeleterId,
+ // DeletionTime = s.DeletionTime,
+ // Email = s.Email,
+ // EmailConfirmed = s.EmailConfirmed,
+ // Id = s.Id,
+ // IsActive = s.IsActive,
+ // IsDeleted = s.IsDeleted,
+ // LastModificationTime = s.LastModificationTime,
+ // LastModifierId = s.LastModifierId,
+ // LockoutEnabled = s.LockoutEnabled,
+ // LockoutEnd = s.LockoutEnd,
+ // Name = s.Name,
+ // PhoneNumber = s.PhoneNumber,
+ // PhoneNumberConfirmed = s.PhoneNumberConfirmed,
+ // Surname = s.Surname,
+ // TenantId = s.TenantId,
+ // UserName = s.UserName,
+ // //OrganizationUnitId = identityUserOrganizationUnitList.FirstOrDefault(m => m.UserId == s.Id) != null? identityUserOrganizationUnitList.FirstOrDefault(m => m.UserId == s.Id).OrganizationUnitId:Guid.Empty,
+ // OrganizationUnitId = identityUserOrganizationUnitList.FirstOrDefault(m => m.UserId == s.Id)?.OrganizationUnitId,
+ // SimpleCode = LanguageConverter.GetPYSimpleCode(s.Surname)
+
+ // }).ToList();
+ // // var entlistdto = ObjectMapper.Map, List>(entlist);
+ // return entlistdto;
+ // }
+
+
+ // ///
+ // /// 获取列表 根据用户类别
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/GetListByOperatorType")]
+ // public async Task> GetListByOperatorTypeAsync(OperatorTypeIuputDto input)
+ // {
+ // var entlist = await _identityUserRepository.GetListAsync(m => m.IsDeleted == false);
+ // var entlistDto = entlist.Where(m => input.OperatorTypes.Contains(m.GetProperty("operator_type"))).Select(s => new ListByOperatorTypeDto
+ // {
+ // Id = s.Id,
+ // SimpleCode = LanguageConverter.GetPYSimpleCode(s.Surname),
+ // Surname = s.Surname,
+ // UserName = s.UserName
+ // }).ToList();
+
+ // return entlistDto;
+ // }
+
+ // ///
+ // /// 修改用户信息
+ // ///
+ // ///
+ // ///
+ // ///
+ // //[Authorize(PeisPermissions.Users.Edit)]
+ // //[HttpPost("api/identity/users/update")]
+ // [RemoteService(false)]
+ // public override async Task UpdateAsync(Guid id, IdentityUserUpdateDto input)
+ // {
+ // var entityDto = await base.UpdateAsync(id, input);
+
+ // var entity = await _identityUserRepository.GetAsync(id);
+ // _userCache.Set(id, entity);
+ // return entityDto;
+
+ // }
+
+ // ///
+ // /// 修改
+ // ///
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/update")]
+ // public async Task UpdateIdentityUserAsync(Guid id, IdentityUserUpdateInputDto input)
+ // {
+
+ // #region 上传图片
+ // string userPhoto = UploadUserPhotoAsync(new UploadUserPhotoInputDto
+ // {
+ // PictureBaseStr = input.UserPhoto,
+ // UserId = id
+ // });
+ // string userSign = UploadUserSignAsync(new UploadUserPhotoInputDto
+ // {
+ // PictureBaseStr = input.UserSign,
+ // UserId = id
+ // });
+ // #endregion
+
+ // input.Email = input.UserName + "@qq.com";
+
+
+ // await IdentityOptions.SetAsync();
+
+ // var user = await UserManager.GetByIdAsync(id);
+
+ // user.SetProperty("user_sign", userSign);
+ // user.SetProperty("user_photo", userPhoto);
+ // user.SetProperty("operator_type", input.OperatorType);
+ // user.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
+
+ // (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
+
+ // await UpdateUserByInput(user, input);
+ // input.MapExtraPropertiesTo(user);
+
+ // (await UserManager.UpdateAsync(user)).CheckErrors();
+
+ // if (!input.Password.IsNullOrEmpty())
+ // {
+ // (await UserManager.RemovePasswordAsync(user)).CheckErrors();
+ // (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors();
+ // }
+
+ // await CurrentUnitOfWork.SaveChangesAsync();
+
+ // var entityDto = ObjectMapper.Map(user);
+
+
+ // var entity = await _identityUserRepository.GetAsync(id);
+ // _userCache.Set(id, entity);
+ // return entityDto;
+ // }
+
+ // ///
+ // /// 获取用户信息 根据ID
+ // ///
+ // ///
+ // ///
+ // //[Authorize(PeisPermissions.Users.Default)]
+ // //[HttpGet("api/identity/users/getinfo")]
+ // [RemoteService(false)]
+ // public override Task GetAsync(Guid id)
+ // {
+ // return base.GetAsync(id);
+ // }
+
+
+ // ///
+ // ///上传用户照片 图片base64
+ // ///
+ // ///
+ // ///
+ // ///
+ // private string UploadUserPhotoAsync(UploadUserPhotoInputDto input)
+ // {
+ // string fileName = "";
+ // if (input.UserId != null)
+ // {
+ // fileName = input.UserId.ToString();
+ // }
+ // else
+ // {
+ // fileName = Guid.NewGuid().ToString();
+ // }
+
+ // string imgurl = $"UserPhoto/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{fileName}";
+ // var isupload = ImageHelper.Base64StrToImage(input.PictureBaseStr, imgurl);
+ // if (!string.IsNullOrEmpty(isupload))
+ // return isupload;
+ // else
+ // return "";
+ // }
+
+
+
+ // ///
+ // /// 上传用户签名 图片base64
+ // ///
+ // ///
+ // ///
+ // ///
+ // private string UploadUserSignAsync(UploadUserPhotoInputDto input)
+ // {
+ // string fileName = "";
+ // if (input.UserId != null)
+ // {
+ // fileName = input.UserId.ToString();
+ // }
+ // else
+ // {
+ // fileName = Guid.NewGuid().ToString();
+ // }
+
+ // string imgurl = $"UserSign/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{fileName}";
+ // var isupload = ImageHelper.Base64StrToImage(input.PictureBaseStr, imgurl);
+ // if (!string.IsNullOrEmpty(isupload))
+ // return isupload;
+ // else
+ // return "";
+ // }
+
+
+ // ///
+ // /// 获取用户信息 根据ID
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpGet("api/identity/users/getinfo")]
+ // public async Task GetWithExtensionAsync(Guid id)
+ // {
+ // var ent = await UserManager.GetByIdAsync(id);
+ // var userSign = !string.IsNullOrWhiteSpace(ent.GetProperty("user_sign")) ? ImageHelper.GetImageBase64StringAsync(ent.GetProperty("user_sign")) : "";
+ // var userPhoto = !string.IsNullOrWhiteSpace(ent.GetProperty("user_photo")) ? ImageHelper.GetImageBase64StringAsync(ent.GetProperty("user_photo")) : "";
+ // var operatorType = ent.GetProperty("operator_type");
+ // var entDto = ObjectMapper.Map(ent);
+ // entDto.UserPhoto = userPhoto;
+ // entDto.UserSign = userSign;
+ // entDto.OperatorType = operatorType;
+ // return entDto;
+ // }
+
+ // ///
+ // /// 给用户绑定角色
+ // ///
+ // /// 用户ID
+ // /// 角色集合
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpPost("api/identity/users/updateroles")]
+ // public override async Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input)
+ // {
+ // var user = await UserManager.GetByIdAsync(id);
+ // (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
+ // await UserRepository.UpdateAsync(user);
+ // }
+
+
+ // ///
+ // /// 获取用户的角色信息 根据用户ID
+ // ///
+ // /// 用户ID
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpGet("api/identity/users/getroles")]
+ // public async Task> GetRolesAsync(Guid id)
+ // {
+
+ // var roles = await UserRepository.GetRolesAsync(id);
+
+ // return new ListResultDto(
+ // ObjectMapper.Map, List>(roles)
+ // );
+ // }
+
+
+
+ // ///
+ // /// 获取当前登录用户的角色信息
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [HttpGet("api/identity/users/getassignableroles")]
+ // public override async Task> GetAssignableRolesAsync()
+ // {
+ // var list = await RoleRepository.GetListAsync();
+ // return new ListResultDto(
+ // ObjectMapper.Map, List>(list));
+ // }
+
+
+ // ///
+ // /// 暂未用到
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [RemoteService(false)]
+ // public override Task FindByUsernameAsync(string userName)
+ // {
+ // return base.FindByUsernameAsync(userName);
+ // }
+
+ // ///
+ // /// 暂未用到
+ // ///
+ // ///
+ // ///
+ // [Authorize(PeisPermissions.SystemSettings.Default)]
+ // [RemoteService(false)]
+ // public override Task FindByEmailAsync(string email)
+ // {
+ // return base.FindByEmailAsync(email);
+ // }
+
+ // ///
+ // /// 用户登录
+ // ///
+ // ///
+ // ///
+ // [HttpPost("api/identity/users/login")]
+ // public async Task UserLogin(UserLoginRequestDto input)
+ // {
+
+ // UserLoginDto msg;
+
+
+ // var user = await _userManager.FindByNameAsync(input.UserName);
+ // if (user != null)
+ // {
+
+ // var verifyResult = await _userManager.CheckPasswordAsync(user, input.PassWord);
+ // if (verifyResult)
+ // {
+
+ // var PeisId = await _peisOrganizationUnitManager.GetPeisIdAsync(user.Id);
+
+ // if (user.IsActive == false)
+ // {
+ // throw new UserFriendlyException("账号已被禁用");
+ // }
+
+ // if (user.LockoutEnabled == true)
+ // {
+ // throw new UserFriendlyException("账号已被锁定");
+ // }
+
+ // TokenResponse token = await RequestAuthServerLoginByPasswordAsync(input.UserName, input.PassWord);
+
+ // if (token.HttpResponse != null && token.HttpResponse.StatusCode == HttpStatusCode.OK)
+ // {
+ // msg = new UserLoginDto
+ // {
+ // //code = 1,
+ // //msg = "登录成功",
+ // peisid = PeisId,
+ // UserId = user.Id,
+ // OperatorType = user.GetProperty("operator_type"),
+ // access_token = token.AccessToken,
+ // expires_in = token.ExpiresIn,
+ // refresh_token = token.RefreshToken,
+ // token_type = token.TokenType
+ // };
+ // }
+ // else
+ // {
+ // //msg = new UserLoginDto { code = 1, msg = "登录成功", peisid = PeisId };
+ // throw new UserFriendlyException("获取token失败");
+ // }
+ // }
+ // else
+ // {
+ // //msg = new UserLoginDto { code = -1, msg = "密码不正确" };
+ // throw new UserFriendlyException("密码不正确");
+ // }
+
+
+
+ // #region MyRegion
+ // //var verifyResult = _passwordHasher.VerifyHashedPassword(user, user.PasswordHash, PassWord);
+
+ // //if (verifyResult == PasswordVerificationResult.Success)
+ // //{
+ // // return "1";
+ // //}
+ // //else
+ // //{
+ // // throw new UserFriendlyException("密码错误");
+ // //}
+ // #endregion
+
+ // }
+ // else
+ // {
+ // //msg = new UserLoginDto { code = -1, msg = "用户不存在" };
+ // throw new UserFriendlyException("用户不存在");
+ // }
+
+ // return msg;
+
+ // }
+
+
+ // protected virtual async Task RequestAuthServerLoginByPasswordAsync(string username, string password)
+ // {
+ // var client = _httpClientFactory.CreateClient();
+
+ // var request = new PasswordTokenRequest
+ // {
+ // Address = _configuration["AuthServer:Authority"] + "/connect/token",
+ // //GrantType = "password",
+ // //UserName = username,
+ // //Password = password,
+ // //Scope = "Peis offline_access",
+ // //ClientId = "Peis_App",
+ // Parameters =
+ // {
+ // {"username",username},
+ // {"password",password },
+ // {"scope","Peis offline_access" },
+ // {"client_id","Peis_App" },
+ // {"grant_type","password" }
+ // }
+ // };
+
+ // //request.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
+
+ // return await client.RequestTokenAsync(request);
+ // }
+
+ //}
+}
diff --git a/src/Shentun.Peis.Application/PermissionManagements/PermissionManagementAppService.cs b/src/Shentun.Peis.Application/PermissionManagements/PermissionManagementAppService.cs
index 38e2a497..b6e6a3e6 100644
--- a/src/Shentun.Peis.Application/PermissionManagements/PermissionManagementAppService.cs
+++ b/src/Shentun.Peis.Application/PermissionManagements/PermissionManagementAppService.cs
@@ -1,38 +1,84 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
+using Shentun.Peis.Permissions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Volo.Abp;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
+using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement;
using Volo.Abp.SimpleStateChecking;
namespace Shentun.Peis.PermissionManagements
{
+
///
/// 权限管理
///
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IPermissionAppService))]
- [Authorize]
+ [Authorize(PeisPermissions.SystemSettings.Default)]
public class PermissionManagementAppService : PermissionAppService
{
+
public PermissionManagementAppService(
IPermissionManager permissionManager,
IPermissionDefinitionManager permissionDefinitionManager,
IOptions options,
- ISimpleStateCheckerManager simpleStateCheckerManager)
+ ISimpleStateCheckerManager simpleStateCheckerManager)
: base(permissionManager, permissionDefinitionManager, options, simpleStateCheckerManager)
{
}
+
+ /////
+ ///// 获取角色的权限
+ /////
+ ///// 固定传 R
+ ///// 角色名称
+ /////
+ //[HttpGet("api/permissionmanagement/get")]
+ //public override Task GetAsync(string providerName, string providerKey)
+ //{
+ // return base.GetAsync(providerName, providerKey);
+ //}
+
+
+ /////
+ ///// 获取角色的权限
+ /////
+ ///// 固定传 R
+ ///// 角色名称
+ /////
+ //[HttpGet("api/permissionmanagement/get")]
+ //[AllowAnonymous]
+ //public override async Task GetAsync(string providerName, string providerKey)
+ //{
+ // var result = await base.GetAsync(providerName, providerKey);
+
+
+ // //过滤
+ // List filterGroupNames = new List { "AbpIdentity", "FeatureManagement", "SettingManagement", "AbpTenantManagement" };
+
+ // var newGroupData = result.Groups.Where(m => !filterGroupNames.Contains(m.Name)).ToList();
+
+ // result.Groups = newGroupData;
+
+ // return result;
+ //}
+
+
+
+
///
/// 获取角色的权限
///
@@ -40,9 +86,91 @@ namespace Shentun.Peis.PermissionManagements
/// 角色名称
///
[HttpGet("api/permissionmanagement/get")]
- public override Task GetAsync(string providerName, string providerKey)
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ public override async Task GetAsync(string providerName, string providerKey)
{
- return base.GetAsync(providerName, providerKey);
+
+ var result = new GetPermissionListResultDto
+ {
+ EntityDisplayName = providerKey,
+ Groups = new List()
+ };
+
+ var multiTenancySide = CurrentTenant.GetMultiTenancySide();
+
+ foreach (var group in PermissionDefinitionManager.GetGroups())
+ {
+ var groupDto = new PermissionGroupDto
+ {
+ Name = group.Name,
+ DisplayName = group.DisplayName.Localize(StringLocalizerFactory),
+ Permissions = new List()
+ };
+
+ var neededCheckPermissions = new List();
+
+ foreach (var permission in group.GetPermissionsWithChildren()
+ .Where(x => x.IsEnabled)
+ .Where(x => !x.Providers.Any() || x.Providers.Contains(providerName))
+ .Where(x => x.MultiTenancySide.HasFlag(multiTenancySide)))
+ {
+ if (await SimpleStateCheckerManager.IsEnabledAsync(permission))
+ {
+ neededCheckPermissions.Add(permission);
+ }
+ }
+
+ if (!neededCheckPermissions.Any())
+ {
+ continue;
+ }
+
+ var grantInfoDtos = neededCheckPermissions.Select(x => new PermissionGrantInfoDto
+ {
+ Name = x.Name,
+ DisplayName = x.DisplayName.Localize(StringLocalizerFactory),
+ ParentName = x.Parent?.Name,
+ AllowedProviders = x.Providers,
+ GrantedProviders = new List()
+ }).ToList();
+
+ var multipleGrantInfo = await PermissionManager.GetAsync(neededCheckPermissions.Select(x => x.Name).ToArray(), providerName, providerKey);
+
+ foreach (var grantInfo in multipleGrantInfo.Result)
+ {
+ var grantInfoDto = grantInfoDtos.First(x => x.Name == grantInfo.Name);
+
+ grantInfoDto.IsGranted = grantInfo.IsGranted;
+
+ foreach (var provider in grantInfo.Providers)
+ {
+ grantInfoDto.GrantedProviders.Add(new ProviderInfoDto
+ {
+ ProviderName = provider.Name,
+ ProviderKey = provider.Key,
+ });
+ }
+
+ groupDto.Permissions.Add(grantInfoDto);
+ }
+
+ if (groupDto.Permissions.Any())
+ {
+ result.Groups.Add(groupDto);
+ }
+ }
+
+
+
+
+ //过滤
+ List filterGroupNames = new List { "AbpIdentity", "FeatureManagement", "SettingManagement", "AbpTenantManagement" };
+
+ var newGroupData = result.Groups.Where(m => !filterGroupNames.Contains(m.Name)).ToList();
+
+ result.Groups = newGroupData;
+
+ return result;
}
@@ -54,9 +182,13 @@ namespace Shentun.Peis.PermissionManagements
///
///
[HttpPost("api/permissionmanagement/update")]
- public override Task UpdateAsync(string providerName, string providerKey, UpdatePermissionsDto input)
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ public override async Task UpdateAsync(string providerName, string providerKey, UpdatePermissionsDto input)
{
- return base.UpdateAsync(providerName, providerKey, input);
+ foreach (var permissionDto in input.Permissions)
+ {
+ await PermissionManager.SetAsync(permissionDto.Name, providerName, providerKey, permissionDto.IsGranted);
+ }
}
}
}
diff --git a/src/Shentun.Peis.Application/Roles/MyRoleAppService.cs b/src/Shentun.Peis.Application/Roles/MyRoleAppService.cs
new file mode 100644
index 00000000..783ea4f8
--- /dev/null
+++ b/src/Shentun.Peis.Application/Roles/MyRoleAppService.cs
@@ -0,0 +1,151 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using Shentun.Peis.Permissions;
+using Shentun.Peis.Rooms;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp;
+using Volo.Abp.Application.Dtos;
+using Volo.Abp.Application.Services;
+using Volo.Abp.Data;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Identity;
+using Volo.Abp.ObjectExtending;
+
+namespace Shentun.Peis.Roles
+{
+ ///
+ /// 角色管理
+ ///
+ [Authorize]
+ public class MyRoleAppService : ApplicationService
+ {
+
+ private readonly IdentityRoleManager _roleManager;
+ private readonly IIdentityRoleRepository _roleRepository;
+
+ public MyRoleAppService(
+ IdentityRoleManager roleManager,
+ IIdentityRoleRepository roleRepository)
+ {
+ _roleManager = roleManager;
+ _roleRepository = roleRepository;
+ }
+
+ ///
+ /// 查询
+ ///
+ ///
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ [HttpPost("api/app/MyRole/GetAllList")]
+ public async Task> GetAllListAsync()
+ {
+ var list = await _roleRepository.GetListAsync();
+ return new ListResultDto(
+ ObjectMapper.Map, List>(list)
+ );
+ }
+
+ ///
+ /// 创建
+ ///
+ ///
+ ///
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ [HttpPost("api/app/MyRole/Create")]
+ public async Task CreateAsync(IdentityRoleCreateDto input)
+ {
+ var role = new IdentityRole(
+ GuidGenerator.Create(),
+ input.Name,
+ CurrentTenant.Id
+ )
+ {
+ IsDefault = input.IsDefault,
+ IsPublic = input.IsPublic
+ };
+ input.MapExtraPropertiesTo(role);
+
+ (await _roleManager.CreateAsync(role)).CheckErrors();
+ await CurrentUnitOfWork.SaveChangesAsync();
+
+ return ObjectMapper.Map(role);
+ }
+
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ [HttpPost("api/app/MyRole/Update")]
+ public async Task UpdateAsync(UpdateRoleInputDto input)
+ {
+ var role = await _roleManager.GetByIdAsync(input.Id);
+
+ role.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
+
+ (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors();
+
+ role.IsDefault = input.IsDefault;
+ role.IsPublic = input.IsPublic;
+
+ input.MapExtraPropertiesTo(role);
+
+ (await _roleManager.UpdateAsync(role)).CheckErrors();
+ await CurrentUnitOfWork.SaveChangesAsync();
+
+ return ObjectMapper.Map(role);
+ }
+
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ [HttpPost("api/app/MyRole/Delete")]
+ public async Task DeleteAsync(RoleIdInputDto input)
+ {
+ var role = await _roleManager.FindByIdAsync(input.Id.ToString());
+ if (role == null)
+ {
+ return;
+ }
+
+ (await _roleManager.DeleteAsync(role)).CheckErrors();
+ }
+
+
+
+
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ [RemoteService(false)]
+ public async Task GetAsync(Guid id)
+ {
+ return ObjectMapper.Map(
+ await _roleManager.GetByIdAsync(id)
+ );
+ }
+ [Authorize(PeisPermissions.SystemSettings.Default)]
+ [RemoteService(false)]
+ public async Task> GetListAsync(GetIdentityRolesInput input)
+ {
+ var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
+ var totalCount = await _roleRepository.GetCountAsync(input.Filter);
+
+ return new PagedResultDto(
+ totalCount,
+ ObjectMapper.Map, List>(list)
+ );
+ }
+
+
+
+
+ }
+}
diff --git a/src/Shentun.Peis.Domain.Shared/Localization/Peis/en.json b/src/Shentun.Peis.Domain.Shared/Localization/Peis/en.json
index 5dc036ad..bad5a325 100644
--- a/src/Shentun.Peis.Domain.Shared/Localization/Peis/en.json
+++ b/src/Shentun.Peis.Domain.Shared/Localization/Peis/en.json
@@ -4,15 +4,13 @@
"Menu:Home": "Home",
"Welcome": "Welcome",
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io.",
- "Permission:BookStore": "Book Store",
- "Permission:Books": "Book Management",
- "Permission:Books.Create": "Creating new books",
- "Permission:Books.Edit": "Editing the books",
- "Permission:Books.Delete": "Deleting the books",
- "Permission:Third": "第三方接口基础权限",
+ "Peis:SystemSettings": "系统设置",
+ "Peis:SystemSettings:Default": "系统数据维护",
+ "Peis:SystemSettings:BaseData": "基础数据维护",
"Peis:Third": "第三方接口",
- "Permission:BaseData": "基础数据接口权限",
- "Peis:BaseData": "基础数据接口",
+ "Peis:Third:Default": "第三方接口",
+ "Peis:Business": "业务接口",
+ "Peis:Business:Default": "业务接口",
"EntityNotFoundErrorMessage": "There is no entity {0} with id = {1}!"
}
}
diff --git a/src/Shentun.Peis.Domain.Shared/Localization/Peis/zh-Hans.json b/src/Shentun.Peis.Domain.Shared/Localization/Peis/zh-Hans.json
index f8fac424..84015926 100644
--- a/src/Shentun.Peis.Domain.Shared/Localization/Peis/zh-Hans.json
+++ b/src/Shentun.Peis.Domain.Shared/Localization/Peis/zh-Hans.json
@@ -4,11 +4,13 @@
"Menu:Home": "首页",
"Welcome": "欢迎",
"LongWelcomeMessage": "欢迎来到该应用程序. 这是一个基于ABP框架的启动项目. 有关更多信息, 请访问 abp.io.",
- "Permission:BookStore": "Book Store",
- "Permission:Books": "Book Management",
- "Permission:Books.Create": "Creating new books",
- "Permission:Books.Edit": "Editing the books",
- "Permission:Books.Delete": "Deleting the books"
+ "Peis:SystemSettings": "系统设置",
+ "Peis:SystemSettings:Default": "系统数据维护",
+ "Peis:SystemSettings:BaseData": "基础数据维护",
+ "Peis:Third": "第三方接口",
+ "Peis:Third:Default": "第三方接口",
+ "Peis:Business": "业务接口",
+ "Peis:Business:Default": "业务接口"
},
"EntityNotFoundErrorMessage": "实体{0}不存在.id={1}!"
}
\ No newline at end of file
diff --git a/src/Shentun.Peis.HttpApi.Host/Filter/ApplicationDescription.cs b/src/Shentun.Peis.HttpApi.Host/Filter/ApplicationDescription.cs
index 4ae4cf7e..5bc0001e 100644
--- a/src/Shentun.Peis.HttpApi.Host/Filter/ApplicationDescription.cs
+++ b/src/Shentun.Peis.HttpApi.Host/Filter/ApplicationDescription.cs
@@ -32,6 +32,8 @@ namespace Shentun.Peis
application.Controllers.RemoveAll(x => x.ControllerType == typeof(TenantController));
application.Controllers.RemoveAll(x => x.ControllerType == typeof(IdentityUserLookupController));
application.Controllers.RemoveAll(x => x.ControllerType == typeof(PermissionsController));
+ application.Controllers.RemoveAll(x => x.ControllerType == typeof(IdentityRoleController));
+ //application.Controllers.RemoveAll(x => x.ControllerType == typeof(IdentityUserController));
//application.Controllers.RemoveAll(x => x.ControllerType == typeof(SettingManagementDbContextModelBuilderExtensions));