From d3ad33ab5ea9fa6c3eabe6572fef339a242b1d88 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 5 Jul 2019 13:09:06 +0300 Subject: [PATCH] register api for account module --- modules/account/Volo.Abp.Account.sln | 43 ++++++++++++++-- ...o.Abp.Account.Application.Contracts.csproj | 25 +++++++++ .../AbpAccountApplicationContractsModule.cs | 37 ++++++++++++++ .../Volo/Abp/Account/IAccountAppService.cs | 11 ++++ .../Account/Localization/AccountResource.cs | 10 ++++ .../Account/Localization/Resources/en.json | 14 +++++ .../Localization/Resources/zh-Hans.json | 14 +++++ .../Volo/Abp/Account/RegisterDto.cs | 25 +++++++++ .../Volo.Abp.Account.Application.csproj | 20 ++++++++ .../Account/AbpAccountApplicationModule.cs | 32 ++++++++++++ .../Volo/Abp/Account/AccountAppService.cs | 27 ++++++++++ .../Volo/Abp/Account/AccountUrlNames.cs | 8 +++ .../Volo.Abp.Account.HttpApi.Client.csproj | 17 +++++++ .../Account/AbpAccountHttpApiClientModule.cs | 19 +++++++ .../Volo.Abp.Account.HttpApi.csproj | 17 +++++++ .../Abp/Account/AbpAccountHttpApiModule.cs | 13 +++++ .../Volo/Abp/Account/AccountController.cs | 27 ++++++++++ .../AbpAccountWebModule.cs | 1 + .../Volo.Abp.Account.Web.csproj | 1 + .../Volo.Abp.Account.Application.Tests.csproj | 17 +++++++ .../Account/AbpAccountApplicationTestBase.cs | 10 ++++ .../AbpAccountApplicationTestModule.cs | 51 +++++++++++++++++++ .../Abp/Account/AccountAppService_Tests.cs | 48 +++++++++++++++++ 23 files changed, 484 insertions(+), 3 deletions(-) create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo.Abp.Account.Application.Contracts.csproj create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/AbpAccountApplicationContractsModule.cs create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/IAccountAppService.cs create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/AccountResource.cs create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json create mode 100644 modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/RegisterDto.cs create mode 100644 modules/account/src/Volo.Abp.Account.Application/Volo.Abp.Account.Application.csproj create mode 100644 modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AbpAccountApplicationModule.cs create mode 100644 modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs create mode 100644 modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountUrlNames.cs create mode 100644 modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj create mode 100644 modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo/Abp/Account/AbpAccountHttpApiClientModule.cs create mode 100644 modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj create mode 100644 modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs create mode 100644 modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs create mode 100644 modules/account/test/Volo.Abp.Account.Application.Tests/Volo.Abp.Account.Application.Tests.csproj create mode 100644 modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestBase.cs create mode 100644 modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs create mode 100644 modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs diff --git a/modules/account/Volo.Abp.Account.sln b/modules/account/Volo.Abp.Account.sln index efee5404cd..c2b195f05b 100644 --- a/modules/account/Volo.Abp.Account.sln +++ b/modules/account/Volo.Abp.Account.sln @@ -1,13 +1,25 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29001.49 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B5881429-EFF7-4F30-8C0B-0AC41E36B74E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Account.Web", "src\Volo.Abp.Account.Web\Volo.Abp.Account.Web.csproj", "{FCAC4354-7B13-4A91-A2F4-04D00F253C91}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Account.Web.IdentityServer", "src\Volo.Abp.Account.Web.IdentityServer\Volo.Abp.Account.Web.IdentityServer.csproj", "{841C216F-B0E9-472C-BC19-2C31ADF0664F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Account.Web.IdentityServer", "src\Volo.Abp.Account.Web.IdentityServer\Volo.Abp.Account.Web.IdentityServer.csproj", "{841C216F-B0E9-472C-BC19-2C31ADF0664F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Account.Application", "src\Volo.Abp.Account.Application\Volo.Abp.Account.Application.csproj", "{17251488-053D-42BA-B430-2428082E3D9E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Account.Application.Contracts", "src\Volo.Abp.Account.Application.Contracts\Volo.Abp.Account.Application.Contracts.csproj", "{715B4DE5-47B4-4C99-A53A-D10FBBE7F48B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Account.HttpApi", "src\Volo.Abp.Account.HttpApi\Volo.Abp.Account.HttpApi.csproj", "{EBF0C2B3-14CB-4DFC-9753-ECBF959CBA2E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Account.HttpApi.Client", "src\Volo.Abp.Account.HttpApi.Client\Volo.Abp.Account.HttpApi.Client.csproj", "{7BCA5955-B3F6-41E8-9D5D-D115195C6098}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{12FAE513-7575-4235-89DF-277BA1A3B098}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Account.Application.Tests", "test\Volo.Abp.Account.Application.Tests\Volo.Abp.Account.Application.Tests.csproj", "{356EAC51-5D55-4852-A8A5-2F90EAC8DAE3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -23,6 +35,26 @@ Global {841C216F-B0E9-472C-BC19-2C31ADF0664F}.Debug|Any CPU.Build.0 = Debug|Any CPU {841C216F-B0E9-472C-BC19-2C31ADF0664F}.Release|Any CPU.ActiveCfg = Release|Any CPU {841C216F-B0E9-472C-BC19-2C31ADF0664F}.Release|Any CPU.Build.0 = Release|Any CPU + {17251488-053D-42BA-B430-2428082E3D9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17251488-053D-42BA-B430-2428082E3D9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17251488-053D-42BA-B430-2428082E3D9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17251488-053D-42BA-B430-2428082E3D9E}.Release|Any CPU.Build.0 = Release|Any CPU + {715B4DE5-47B4-4C99-A53A-D10FBBE7F48B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {715B4DE5-47B4-4C99-A53A-D10FBBE7F48B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {715B4DE5-47B4-4C99-A53A-D10FBBE7F48B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {715B4DE5-47B4-4C99-A53A-D10FBBE7F48B}.Release|Any CPU.Build.0 = Release|Any CPU + {EBF0C2B3-14CB-4DFC-9753-ECBF959CBA2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBF0C2B3-14CB-4DFC-9753-ECBF959CBA2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBF0C2B3-14CB-4DFC-9753-ECBF959CBA2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBF0C2B3-14CB-4DFC-9753-ECBF959CBA2E}.Release|Any CPU.Build.0 = Release|Any CPU + {7BCA5955-B3F6-41E8-9D5D-D115195C6098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BCA5955-B3F6-41E8-9D5D-D115195C6098}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BCA5955-B3F6-41E8-9D5D-D115195C6098}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BCA5955-B3F6-41E8-9D5D-D115195C6098}.Release|Any CPU.Build.0 = Release|Any CPU + {356EAC51-5D55-4852-A8A5-2F90EAC8DAE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {356EAC51-5D55-4852-A8A5-2F90EAC8DAE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {356EAC51-5D55-4852-A8A5-2F90EAC8DAE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {356EAC51-5D55-4852-A8A5-2F90EAC8DAE3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -30,6 +62,11 @@ Global GlobalSection(NestedProjects) = preSolution {FCAC4354-7B13-4A91-A2F4-04D00F253C91} = {B5881429-EFF7-4F30-8C0B-0AC41E36B74E} {841C216F-B0E9-472C-BC19-2C31ADF0664F} = {B5881429-EFF7-4F30-8C0B-0AC41E36B74E} + {17251488-053D-42BA-B430-2428082E3D9E} = {B5881429-EFF7-4F30-8C0B-0AC41E36B74E} + {715B4DE5-47B4-4C99-A53A-D10FBBE7F48B} = {B5881429-EFF7-4F30-8C0B-0AC41E36B74E} + {EBF0C2B3-14CB-4DFC-9753-ECBF959CBA2E} = {B5881429-EFF7-4F30-8C0B-0AC41E36B74E} + {7BCA5955-B3F6-41E8-9D5D-D115195C6098} = {B5881429-EFF7-4F30-8C0B-0AC41E36B74E} + {356EAC51-5D55-4852-A8A5-2F90EAC8DAE3} = {12FAE513-7575-4235-89DF-277BA1A3B098} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2B054393-D2B2-4EA8-8A15-D60CBCF3E7A9} diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo.Abp.Account.Application.Contracts.csproj b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo.Abp.Account.Application.Contracts.csproj new file mode 100644 index 0000000000..0f1621b6b2 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo.Abp.Account.Application.Contracts.csproj @@ -0,0 +1,25 @@ + + + + + + netstandard2.0 + Volo.Abp.Account.Application.Contracts + Volo.Abp.Account.Application.Contracts + + + + + + + + + + + + + + + + + diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/AbpAccountApplicationContractsModule.cs b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/AbpAccountApplicationContractsModule.cs new file mode 100644 index 0000000000..ad5cb15296 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/AbpAccountApplicationContractsModule.cs @@ -0,0 +1,37 @@ +using Volo.Abp.Account.Localization; +using Volo.Abp.Identity; +using Volo.Abp.Localization; +using Volo.Abp.Localization.ExceptionHandling; +using Volo.Abp.Localization.Resources.AbpValidation; +using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; + +namespace Volo.Abp.Account +{ + [DependsOn( + typeof(AbpIdentityApplicationContractsModule) + )] + public class AbpAccountApplicationContractsModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Resources + .Add("en") + .AddBaseTypes(typeof(AbpValidationResource)) + .AddVirtualJson("/Volo/Abp/Account/Localization/Resources"); + }); + + Configure(options => + { + options.MapCodeNamespace("Volo.Account", typeof(AccountResource)); + }); + } + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/IAccountAppService.cs b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/IAccountAppService.cs new file mode 100644 index 0000000000..74d6bb3f7a --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/IAccountAppService.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Identity; + +namespace Volo.Abp.Account +{ + public interface IAccountAppService : IApplicationService + { + Task RegisterAsync(RegisterDto input); + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/AccountResource.cs b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/AccountResource.cs new file mode 100644 index 0000000000..fe79f8c0f4 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/AccountResource.cs @@ -0,0 +1,10 @@ +using Volo.Abp.Localization; + +namespace Volo.Abp.Account.Localization +{ + [LocalizationResourceName("AbpAccount")] + public class AccountResource + { + + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json new file mode 100644 index 0000000000..02583b106b --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json @@ -0,0 +1,14 @@ +{ + "culture": "en", + "texts": { + "PasswordReset": "Password Reset", + "PasswordResetInfoInEmail": "We received an account recovery request! If you initiated this request, click the following link to reset your password.", + "ResetMyPassword": "Reset my password", + "NotAMemberYet": "Not a member yet?", + "OrSignInWith": "Or sign in with", + "EmailConfirmation": "Email Confirmation", + "EmailConfirmationInfoInEmail": "Please confirm your email address by clicking the following link.", + "ConfirmMyEmail": "Confirm my email address", + "Volo.Account:InvalidEmailAddress": "Can not find the given email address: {Email}" + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json new file mode 100644 index 0000000000..1c5373b625 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json @@ -0,0 +1,14 @@ +{ + "culture": "zh-Hans", + "texts": { + "PasswordReset": "重设密码", + "PasswordResetInfoInEmail": "我们收到了帐户恢复请求!如果您发起了此请求,请单击以下链接以重置密码.", + "ResetMyPassword": "重置我的密码", + "NotAMemberYet": "还不是会员?", + "OrSignInWith": "或者登录", + "EmailConfirmation": "邮件确认", + "EmailConfirmationInfoInEmail": "请点击以下链接确认您的电子邮件地址.", + "ConfirmMyEmail": "确认我的电子邮件地址", + "Volo.Account:InvalidEmailAddress": "找不到给定的电子邮件地址:{Email}" + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/RegisterDto.cs b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/RegisterDto.cs new file mode 100644 index 0000000000..5355d7e332 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/RegisterDto.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Identity; + +namespace Volo.Abp.Account +{ + public class RegisterDto + { + [Required] + [StringLength(IdentityUserConsts.MaxUserNameLength)] + public string UserName { get; set; } + + [Required] + [EmailAddress] + [StringLength(IdentityUserConsts.MaxEmailLength)] + public string EmailAddress { get; set; } + + [Required] + [StringLength(IdentityUserConsts.MaxPasswordLength)] + [DataType(DataType.Password)] + public string Password { get; set; } + + [Required] + public string AppName { get; set; } + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo.Abp.Account.Application.csproj b/modules/account/src/Volo.Abp.Account.Application/Volo.Abp.Account.Application.csproj new file mode 100644 index 0000000000..097e1f6c55 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application/Volo.Abp.Account.Application.csproj @@ -0,0 +1,20 @@ + + + + + + netstandard2.0 + Volo.Abp.Account.Application + Volo.Abp.Account.Application + + + + + + + + + + + + diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AbpAccountApplicationModule.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AbpAccountApplicationModule.cs new file mode 100644 index 0000000000..44ca2681f6 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AbpAccountApplicationModule.cs @@ -0,0 +1,32 @@ +using Volo.Abp.Emailing; +using Volo.Abp.Identity; +using Volo.Abp.Modularity; +using Volo.Abp.Ui.Navigation.Urls; +using Volo.Abp.UI.Navigation; +using Volo.Abp.VirtualFileSystem; + +namespace Volo.Abp.Account +{ + [DependsOn( + typeof(AbpAccountApplicationContractsModule), + typeof(AbpEmailingModule), + typeof(AbpIdentityApplicationModule), + typeof(AbpUiNavigationModule) + )] + public class AbpAccountApplicationModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Applications["MVC"].Urls[AccountUrlNames.PasswordReset] = "Account/ResetPassword"; + options.Applications["MVC"].Urls[AccountUrlNames.EmailConfirmation] = "Account/EmailConfirmation"; + }); + } + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs new file mode 100644 index 0000000000..def2b83757 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Volo.Abp.Application.Services; +using Volo.Abp.Identity; + +namespace Volo.Abp.Account +{ + public class AccountAppService : ApplicationService, IAccountAppService + { + protected IdentityUserManager UserManager { get; } + + public AccountAppService( + IdentityUserManager userManager) + { + UserManager = userManager; + } + + public async Task RegisterAsync(RegisterDto input) + { + var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.EmailAddress, CurrentTenant.Id); + + (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); + + return ObjectMapper.Map(user); + } + } +} diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountUrlNames.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountUrlNames.cs new file mode 100644 index 0000000000..4c54649bd2 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountUrlNames.cs @@ -0,0 +1,8 @@ +namespace Volo.Abp.Account +{ + public static class AccountUrlNames + { + public const string PasswordReset = "Abp.Account.PasswordReset"; + public const string EmailConfirmation = "Abp.Account.EmailConfirmation"; + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj new file mode 100644 index 0000000000..c5d14ebcc4 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj @@ -0,0 +1,17 @@ + + + + + + netstandard2.0 + Volo.Abp.Account.HttpApi.Client + Volo.Abp.Account.HttpApi.Client + + + + + + + + + diff --git a/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo/Abp/Account/AbpAccountHttpApiClientModule.cs b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo/Abp/Account/AbpAccountHttpApiClientModule.cs new file mode 100644 index 0000000000..2cfba522cb --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo/Abp/Account/AbpAccountHttpApiClientModule.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Http.Client; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Account +{ + [DependsOn( + typeof(AbpAccountApplicationContractsModule), + typeof(AbpHttpClientModule))] + public class AbpAccountHttpApiClientModule : AbpModule + { + public const string RemoteServiceName = "Account"; + + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddHttpClientProxies(typeof(AbpAccountApplicationContractsModule).Assembly, RemoteServiceName); + } + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj b/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj new file mode 100644 index 0000000000..8c028185c7 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj @@ -0,0 +1,17 @@ + + + + + + netstandard2.0 + Volo.Abp.Account.HttpApi + Volo.Abp.Account.HttpApi + + + + + + + + + diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs new file mode 100644 index 0000000000..42e47c31c5 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs @@ -0,0 +1,13 @@ +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Account +{ + [DependsOn( + typeof(AbpAccountApplicationContractsModule), + typeof(AbpAspNetCoreMvcModule))] + public class AbpAccountHttpApiModule : AbpModule + { + + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs new file mode 100644 index 0000000000..c750ede454 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Identity; + +namespace Volo.Abp.Account +{ + [RemoteService] + [Area("account")] + [Route("api/account")] + public class AccountController : AbpController, IAccountAppService + { + private readonly IAccountAppService _accountAppService; + + public AccountController(IAccountAppService accountAppService) + { + _accountAppService = accountAppService; + } + + [HttpPost] + [Route("register")] + public Task RegisterAsync(RegisterDto input) + { + return _accountAppService.RegisterAsync(input); + } + } +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index 846c31763c..e4e446dc8d 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -14,6 +14,7 @@ using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.Account.Web { [DependsOn( + typeof(AbpAccountHttpApiModule), typeof(AbpIdentityAspNetCoreModule), typeof(AbpAspNetCoreMvcUiThemeSharedModule) )] diff --git a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj index 50be3cbf0d..223b83610d 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj +++ b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj @@ -32,6 +32,7 @@ + diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo.Abp.Account.Application.Tests.csproj b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo.Abp.Account.Application.Tests.csproj new file mode 100644 index 0000000000..5fa709490c --- /dev/null +++ b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo.Abp.Account.Application.Tests.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp2.2 + + + + + + + + + + + + + diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestBase.cs b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestBase.cs new file mode 100644 index 0000000000..38f1506a76 --- /dev/null +++ b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestBase.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.Account +{ + public class AbpAccountApplicationTestBase : AbpIntegratedTest + { + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + } +} \ No newline at end of file diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs new file mode 100644 index 0000000000..6be56c3a87 --- /dev/null +++ b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs @@ -0,0 +1,51 @@ +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Identity; +using Volo.Abp.Identity.AspNetCore; +using Volo.Abp.Identity.EntityFrameworkCore; +using Volo.Abp.Modularity; +using Volo.Abp.PermissionManagement.EntityFrameworkCore; + +namespace Volo.Abp.Account +{ + [DependsOn( + typeof(AbpIdentityAspNetCoreModule), + typeof(AbpAccountApplicationModule), + typeof(AbpIdentityDomainTestModule) + )] + public class AbpAccountApplicationTestModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var sqliteConnection = CreateDatabaseAndGetConnection(); + + Configure(options => + { + options.Configure(abpDbContextConfigurationContext => + { + abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); + }); + }); + } + + private static SqliteConnection CreateDatabaseAndGetConnection() + { + var connection = new SqliteConnection("Data Source=:memory:"); + connection.Open(); + + new IdentityDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); + + new PermissionManagementDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); + + + return connection; + } + } +} diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs new file mode 100644 index 0000000000..a2dec7ddff --- /dev/null +++ b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs @@ -0,0 +1,48 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Shouldly; +using Volo.Abp.Identity; +using Xunit; + +namespace Volo.Abp.Account.Pro.Application.Tests.Volo.Abp.Account +{ + public class AccountAppService_Tests : AbpAccountApplicationTestBase + { + private readonly IAccountAppService _accountAppService; + private readonly IIdentityUserRepository _identityUserRepository; + private readonly ILookupNormalizer _lookupNormalizer; + private readonly IdentityUserManager _userManager; + + + public AccountAppService_Tests() + { + _accountAppService = GetRequiredService(); + _identityUserRepository = GetRequiredService(); + _lookupNormalizer = GetRequiredService(); + _userManager = GetRequiredService(); + } + + [Fact] + public async Task RegisterAsync() + { + var registerDto = new RegisterDto() + { + UserName = "bob.lee", + EmailAddress = "bob.lee@abp.io", + Password = "P@ssW0rd", + AppName = "MVC" + }; + + await _accountAppService.RegisterAsync(registerDto); + + var user = await _identityUserRepository.FindByNormalizedUserNameAsync( + _lookupNormalizer.Normalize("bob.lee")); + + user.ShouldNotBeNull(); + user.UserName.ShouldBe("bob.lee"); + user.Email.ShouldBe("bob.lee@abp.io"); + + (await _userManager.CheckPasswordAsync(user, "P@ssW0rd")).ShouldBeTrue(); + } + } +}