-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @cotur
The password will be checked by Identity. Will the web prompt when the password does not meet the requirements?
abp/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs
Lines 42 to 47 in 1a622bc
options.Password.RequiredLength = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredLength, options.Password.RequiredLength); | |
options.Password.RequiredUniqueChars = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredUniqueChars, options.Password.RequiredUniqueChars); | |
options.Password.RequireNonAlphanumeric = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireNonAlphanumeric, options.Password.RequireNonAlphanumeric); | |
options.Password.RequireLowercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireLowercase, options.Password.RequireLowercase); | |
options.Password.RequireUppercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireUppercase, options.Password.RequireUppercase); | |
options.Password.RequireDigit = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireDigit, options.Password.RequireDigit); |
var isValidEmail = | ||
Regex.IsMatch(AdminEmailAddress, TenantConsts.EmailRegex, RegexOptions.IgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use ValidationHelper.IsValidEmailAddress()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use [EmailAddress] and [Required] attributes for the AdminEmailAddress. Also, add [Required] attribute for AdminPassword
.
Completely remove custom Validate method.
@@ -51,8 +51,7 @@ 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(tenant.Id, input.AdminEmailAddress, input.AdminPassword); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use:
await DataSeeder.SeedAsync(new DataSeedContext()
.WithProperty("AdminEmail", input.AdminEmailAddress)
.WithProperty("AdminPassword", input.AdminPassword));
|
||
public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId, string adminEmailAddress, string adminPassword) | ||
{ | ||
var context = new DataSeedContext(tenantId) | ||
.WithProperty("AdminEmail", adminEmailAddress) | ||
.WithProperty("AdminPassword", adminPassword); | ||
|
||
return seeder.SeedAsync(context); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can remove it, because this code is not related to the Volo.Abp.Data
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please remove this. adminEmailAddress and adminPassword is a concept of the Identity module.
However, you can add WithAdminEmail(string emailAddress)
and WithAdminPassword(string password)
extension methods to the DataSeedContext
, but inside the Identity module!
var isValidEmail = | ||
Regex.IsMatch(AdminEmailAddress, TenantConsts.EmailRegex, RegexOptions.IgnoreCase); | ||
|
||
if (string.IsNullOrWhiteSpace(AdminEmailAddress) || !isValidEmail) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use if (!isValidEmail)
|
||
public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId, string adminEmailAddress, string adminPassword) | ||
{ | ||
var context = new DataSeedContext(tenantId) | ||
.WithProperty("AdminEmail", adminEmailAddress) | ||
.WithProperty("AdminPassword", adminPassword); | ||
|
||
return seeder.SeedAsync(context); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please remove this. adminEmailAddress and adminPassword is a concept of the Identity module.
However, you can add WithAdminEmail(string emailAddress)
and WithAdminPassword(string password)
extension methods to the DataSeedContext
, but inside the Identity module!
var isValidEmail = | ||
Regex.IsMatch(AdminEmailAddress, TenantConsts.EmailRegex, RegexOptions.IgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use [EmailAddress] and [Required] attributes for the AdminEmailAddress. Also, add [Required] attribute for AdminPassword
.
Completely remove custom Validate method.
....Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/en.json
Outdated
Show resolved
Hide resolved
...gement/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/TenantConsts.cs
Outdated
Show resolved
Hide resolved
...ement/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml.cs
Outdated
Show resolved
Hide resolved
...nagement/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml
Outdated
Show resolved
Hide resolved
Yes, UI should validate if possible (check how it was implemented for the user registeration). |
Closes: #3088