Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom admin/pass implementation for new tenant #3107

Merged
merged 7 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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