Skip to content

Commit

Permalink
Merge pull request #3107 from abpframework/Cotur-TenantManagement
Browse files Browse the repository at this point in the history
Custom admin/pass implementation for new tenant
  • Loading branch information
hikalkan authored Mar 16, 2020
2 parents 1254179 + 1bfe661 commit 7b26309
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
namespace Volo.Abp.TenantManagement
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.Abp.TenantManagement.Localization;

namespace Volo.Abp.TenantManagement
{
public class TenantCreateDto : TenantCreateOrUpdateDtoBase
{
[Required]
[EmailAddress]
[MaxLength(256)]
public string AdminEmailAddress { get; set; }


[Required]
[MaxLength(128)]
public string AdminPassword { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace Volo.Abp.TenantManagement
using System.ComponentModel.DataAnnotations;

namespace Volo.Abp.TenantManagement
{
public abstract class TenantCreateOrUpdateDtoBase
{
[Required]
[StringLength(TenantConsts.MaxNameLength)]
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TenantAppService : TenantManagementAppServiceBase, ITenantAppServic
protected ITenantManager TenantManager { get; }

public TenantAppService(
ITenantRepository tenantRepository,
ITenantRepository tenantRepository,
ITenantManager tenantManager,
IDataSeeder dataSeeder)
{
Expand Down Expand Up @@ -51,10 +51,13 @@ public virtual async Task<TenantDto> CreateAsync(TenantCreateDto input)
{
//TODO: Handle database creation?

//TODO: Set admin email & password..?
await DataSeeder.SeedAsync(tenant.Id);
await DataSeeder.SeedAsync(
new DataSeedContext(tenant.Id)
.WithProperty("AdminEmail", input.AdminEmailAddress)
.WithProperty("AdminPassword", input.AdminPassword)
);
}

return ObjectMapper.Map<Tenant, TenantDto>(tenant);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public virtual Task<PagedResultDto<TenantDto>> GetListAsync(GetTenantsInput inpu
[HttpPost]
public virtual Task<TenantDto> CreateAsync(TenantCreateDto input)
{
ValidateModel();
return _service.CreateAsync(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<abp-modal>
<abp-modal-header title="@L["NewTenant"]"></abp-modal-header>
<abp-modal-body>
<abp-input asp-for="Tenant.Name" label="@L["TenantName"].Value" />
<abp-input asp-for="Tenant.Name" />

<abp-input asp-for="Tenant.AdminEmailAddress" />

<abp-input asp-for="Tenant.AdminPassword" />
</abp-modal-body>
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
</abp-modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ public class TenantInfoModel
{
[Required]
[StringLength(TenantConsts.MaxNameLength)]
[Display(Name = "DisplayName:TenantName")]
public string Name { get; set; }

[Required]
[EmailAddress]
[MaxLength(256)]
public string AdminEmailAddress { get; set; }

[Required]
[MaxLength(128)]
public string AdminPassword { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task GetListAsync_Sorted_Descending_By_Name()
public async Task CreateAsync()
{
var tenancyName = Guid.NewGuid().ToString("N").ToLowerInvariant();
var tenant = await _tenantAppService.CreateAsync(new TenantCreateDto { Name = tenancyName });
var tenant = await _tenantAppService.CreateAsync(new TenantCreateDto { Name = tenancyName , AdminEmailAddress = "[email protected]", AdminPassword = "123456"});
tenant.Name.ShouldBe(tenancyName);
tenant.Id.ShouldNotBe(default(Guid));
}
Expand All @@ -69,7 +69,7 @@ public async Task CreateAsync_Should_Not_Allow_Duplicate_Names()
{
await Assert.ThrowsAsync<UserFriendlyException>(async () =>
{
await _tenantAppService.CreateAsync(new TenantCreateDto { Name = "acme" });
await _tenantAppService.CreateAsync(new TenantCreateDto { Name = "acme", AdminEmailAddress = "[email protected]", AdminPassword = "123456" });
});
}

Expand Down

0 comments on commit 7b26309

Please sign in to comment.