mirror of https://github.com/abpframework/abp.git
23 changed files with 484 additions and 3 deletions
@ -0,0 +1,25 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Account.Application.Contracts</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Account.Application.Contracts</PackageId> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<EmbeddedResource Include="Volo\Abp\Account\Localization\Resources\*.json" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Remove="Volo\Abp\Account\Localization\Resources\en.json" /> |
||||
|
<None Remove="Volo\Abp\Account\Localization\Resources\zh-Hans.json" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\identity\src\Volo.Abp.Identity.Application.Contracts\Volo.Abp.Identity.Application.Contracts.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -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<VirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpAccountApplicationContractsModule>(); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Resources |
||||
|
.Add<AccountResource>("en") |
||||
|
.AddBaseTypes(typeof(AbpValidationResource)) |
||||
|
.AddVirtualJson("/Volo/Abp/Account/Localization/Resources"); |
||||
|
}); |
||||
|
|
||||
|
Configure<ExceptionLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.MapCodeNamespace("Volo.Account", typeof(AccountResource)); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<IdentityUserDto> RegisterAsync(RegisterDto input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Localization |
||||
|
{ |
||||
|
[LocalizationResourceName("AbpAccount")] |
||||
|
public class AccountResource |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -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}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hans", |
||||
|
"texts": { |
||||
|
"PasswordReset": "重设密码", |
||||
|
"PasswordResetInfoInEmail": "我们收到了帐户恢复请求!如果您发起了此请求,请单击以下链接以重置密码.", |
||||
|
"ResetMyPassword": "重置我的密码", |
||||
|
"NotAMemberYet": "还不是会员?", |
||||
|
"OrSignInWith": "或者登录", |
||||
|
"EmailConfirmation": "邮件确认", |
||||
|
"EmailConfirmationInfoInEmail": "请点击以下链接确认您的电子邮件地址.", |
||||
|
"ConfirmMyEmail": "确认我的电子邮件地址", |
||||
|
"Volo.Account:InvalidEmailAddress": "找不到给定的电子邮件地址:{Email}" |
||||
|
} |
||||
|
} |
||||
@ -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; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Account.Application</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Account.Application</PackageId> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="System.Text.Encodings.Web" Version="4.5.0" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.Account.Application.Contracts\Volo.Abp.Account.Application.Contracts.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\identity\src\Volo.Abp.Identity.Application\Volo.Abp.Identity.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Emailing\Volo.Abp.Emailing.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.UI.Navigation\Volo.Abp.UI.Navigation.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -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<VirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpAccountApplicationModule>(); |
||||
|
}); |
||||
|
|
||||
|
Configure<AppUrlOptions>(options => |
||||
|
{ |
||||
|
options.Applications["MVC"].Urls[AccountUrlNames.PasswordReset] = "Account/ResetPassword"; |
||||
|
options.Applications["MVC"].Urls[AccountUrlNames.EmailConfirmation] = "Account/EmailConfirmation"; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<IdentityUserDto> 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<IdentityUser, IdentityUserDto>(user); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Account.HttpApi.Client</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Account.HttpApi.Client</PackageId> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.Account.Application.Contracts\Volo.Abp.Account.Application.Contracts.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Account.HttpApi</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Account.HttpApi</PackageId> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.Account.Application.Contracts\Volo.Abp.Account.Application.Contracts.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -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 |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -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<IdentityUserDto> RegisterAsync(RegisterDto input) |
||||
|
{ |
||||
|
return _accountAppService.RegisterAsync(input); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.2</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\identity\test\Volo.Abp.Identity.Domain.Tests\Volo.Abp.Identity.Domain.Tests.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.Account.Application\Volo.Abp.Account.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\identity\src\Volo.Abp.Identity.AspNetCore\Volo.Abp.Identity.AspNetCore.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,10 @@ |
|||||
|
namespace Volo.Abp.Account |
||||
|
{ |
||||
|
public class AbpAccountApplicationTestBase : AbpIntegratedTest<AbpAccountApplicationTestModule> |
||||
|
{ |
||||
|
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<AbpDbContextOptions>(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<IdentityDbContext>().UseSqlite(connection).Options |
||||
|
).GetService<IRelationalDatabaseCreator>().CreateTables(); |
||||
|
|
||||
|
new PermissionManagementDbContext( |
||||
|
new DbContextOptionsBuilder<PermissionManagementDbContext>().UseSqlite(connection).Options |
||||
|
).GetService<IRelationalDatabaseCreator>().CreateTables(); |
||||
|
|
||||
|
|
||||
|
return connection; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<IAccountAppService>(); |
||||
|
_identityUserRepository = GetRequiredService<IIdentityUserRepository>(); |
||||
|
_lookupNormalizer = GetRequiredService<ILookupNormalizer>(); |
||||
|
_userManager = GetRequiredService<IdentityUserManager>(); |
||||
|
} |
||||
|
|
||||
|
[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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue