- ABP Framework version: v4.4.4
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:"
- How can I implement functionality to require a** password reset** on first login?
- I would also want to automatically send an email to the user when a new user is created.
- How can I add the password expiry duration?
I general, I need to design/implement the following
- Password reset is required
- Password must reset every 90 days
- Password reset reminder 14 days prior to the reset date
- If user has not logged in but 90 days have passed, force user to reset password once logged in
I see it is encapsulated within TenantManagement and IdentityManagement module.
1 Answer(s)
-
0
As you know, ABP is customizable, so it will not be too difficult to do what you say.
IsActive
property has been added toUser
withABP 5.0.*
. If you do not want to upgrade your application to version5.0.*
, you can add a similar property and set this property to false when the user first registers. You update thePasswordExpireDate
(how you can addPasswordExpireDate
toUser
will be mentioned later) andIsActive
property when the password is reset. Thus, the user cannot login to the application without resetting the password.I wrote the following code as a small example for you to override a service.
I created a folder named
IdentityUser
in theMyProjectName.Application
project and I created a class calledMyIdentityUserAppService
in theIdentityUser
folder.MyIdentityUserAppService.cs
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(IIdentityUserAppService), typeof(IdentityUserAppService), typeof(MyIdentityUserAppService))] public class MyIdentityUserAppService : IdentityUserAppService, IIdentityUserAppService { public MyIdentityUserAppService( IdentityUserManager userManager, IIdentityUserRepository userRepository, IIdentityRoleRepository roleRepository, IOrganizationUnitRepository organizationUnitRepository, IIdentityClaimTypeRepository identityClaimTypeRepository, IdentityProTwoFactorManager identityProTwoFactorManager, IOptions<IdentityOptions> identityOptions, IDistributedEventBus distributedEventBus) : base( userManager, userRepository, roleRepository, organizationUnitRepository, identityClaimTypeRepository, identityProTwoFactorManager, identityOptions, distributedEventBus) { } public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input) { // Set isActive to false in ABP 5.0.* var identityUserDto = await base.CreateAsync(input); // send email // set password expiry duration - userSetProperty("PasswordExpireDate", DateTime.Now.AddMonths(3)); // something that you need return identityUserDto; } }
To trigger this code, you need to enter the application with the admin user and click Users from the Identity Management area and add a new user, I just wrote it as an example. You can do the necessary actions where I added it as a comment line.
You need to customize the
PasswordReset
method as I did in this code because you want to updateIsActive
andPasswordExpireDate
when the user resets their password. You can refer to this document for Overriding Services.Also, this article shows you how to customize
User
under "The AppUser Entity & Custom Properties". By following the relevant part of this article, you can add a property namedPasswordExpireDate
to theUser
and then query accordingly.Of course you need to create a background worker that runs daily and there you have to update the user towards your needs or or you can send them an email reminding them to reset their password.