From 4ffbd5fe2b7dc148ffad03a14bacfce7525cdb2c Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 7 Aug 2020 08:03:50 +0800 Subject: [PATCH 1/2] add the organization structure API --- .../LINGYUN/Abp/Account/AccountAppService.cs | 29 ++++++----- .../Identity/IOrganizationUnitAppService.cs | 2 + .../Identity/OrganizationUnitAppService.cs | 8 ++++ .../Identity/OrganizationUnitController.cs | 7 +++ vueJs/src/api/organizationunit.ts | 9 ++++ .../components/EditOrganizationUint.vue | 48 ++++++++----------- 6 files changed, 62 insertions(+), 41 deletions(-) diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs index e1c531a04..be926b0c1 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs @@ -49,22 +49,25 @@ namespace LINGYUN.Abp.Account var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code); var user = await UserManager.FindByLoginAsync("WeChat", wehchatOpenId.OpenId); - if (user == null) + if (user != null) { - var userName = input.UserName ?? wehchatOpenId.OpenId; - var userEmail = input.EmailAddress ?? $"{userName}@{new Random().Next(1000, 99999)}.com";//如果邮件地址不验证,随意写入一个 - - user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id) - { - Name = input.Name ?? userName - }; - (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); + // 应该要抛出微信号已注册异常,而不是直接返回注册用户数据,否则造成用户信息泄露 + throw new UserFriendlyException(L["DuplicateWeChat"]); + } + var userName = input.UserName ?? wehchatOpenId.OpenId; + var userEmail = input.EmailAddress ?? $"{userName}@{new Random().Next(1000, 99999)}.com";//如果邮件地址不验证,随意写入一个 - (await UserManager.AddDefaultRolesAsync(user)).CheckErrors(); + user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id) + { + Name = input.Name ?? userName + }; + (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); + + (await UserManager.AddDefaultRolesAsync(user)).CheckErrors(); + + var userLogin = new UserLoginInfo("WeChat", wehchatOpenId.OpenId, "微信认证登录"); + (await UserManager.AddLoginAsync(user, userLogin)).CheckErrors(); - var userLogin = new UserLoginInfo("WeChat", wehchatOpenId.OpenId, "微信认证登录"); - (await UserManager.AddLoginAsync(user, userLogin)).CheckErrors(); - } return ObjectMapper.Map(user); } /// diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs index d03e2d337..631a1bdef 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs @@ -18,6 +18,8 @@ namespace LINGYUN.Abp.Identity Task MoveAsync(Guid id, OrganizationUnitMoveDto input); + Task> GetRootAsync(); + Task> FindChildrenAsync(OrganizationUnitGetChildrenDto input); Task> GetRolesAsync(OrganizationUnitGetRoleByPagedDto input); diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs index e23eaf86d..56aa0694a 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs @@ -58,6 +58,14 @@ namespace LINGYUN.Abp.Identity await OrganizationUnitManager.DeleteAsync(id); } + public virtual async Task> GetRootAsync() + { + var rootOriganizationUnits = await OrganizationUnitManager.FindChildrenAsync(null, recursive: false); + + return new ListResultDto( + ObjectMapper.Map, List>(rootOriganizationUnits)); + } + public virtual async Task> FindChildrenAsync(OrganizationUnitGetChildrenDto input) { var origanizationUnitChildren = await OrganizationUnitManager.FindChildrenAsync(input.Id, input.Recursive); diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs index 536223d6c..7aa254430 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs @@ -64,6 +64,13 @@ namespace LINGYUN.Abp.Identity return await OrganizationUnitAppService.GetAsync(id); } + [HttpGet] + [Route("root-node")] + public virtual async Task> GetRootAsync() + { + return await OrganizationUnitAppService.GetRootAsync(); + } + [HttpGet] [Route("last-children")] public virtual async Task GetLastChildOrNullAsync(Guid? parentId) diff --git a/vueJs/src/api/organizationunit.ts b/vueJs/src/api/organizationunit.ts index 1890f8538..74ad331c2 100644 --- a/vueJs/src/api/organizationunit.ts +++ b/vueJs/src/api/organizationunit.ts @@ -18,6 +18,15 @@ export default class OrganizationUnitService { return ApiService.Post(_url, payload, serviceUrl) } + /** + * 查询组织机构根节点 + * @returns 返回类型为 OrganizationUnit 的对象列表 + */ + public static getRootOrganizationUnits() { + const _url = '/api/identity/organization-units/root-node' + return ApiService.Get>(_url, serviceUrl) + } + /** * 查询组织机构列表 * @param payload 分页查询对象 diff --git a/vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue b/vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue index 11a0d9f8d..d16bcbc0e 100644 --- a/vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue +++ b/vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue @@ -48,7 +48,8 @@