From dea09e45b7d25d5af8054f2632971eb07bd4f691 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 7 Nov 2022 17:30:49 +0300 Subject: [PATCH] Added SetPasswordEventHandler --- .../Volo/Abp/Identity/IdentityUserManager.cs | 13 ++++++++++ .../Abp/Identity/SetPasswordEventHandler.cs | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/SetPasswordEventHandler.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index b1db0e01e5..90f2d3ecd7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -253,4 +253,17 @@ public class IdentityUserManager : UserManager, IDomainService return await UpdateUserAsync(user); } + + public virtual async Task SetPasswordAsync(Guid? userId, string userName, string password) + { + if (!password.IsNullOrEmpty()) + { + var user = await UserRepository.GetAsync(userId.GetValueOrDefault(), cancellationToken: CancellationToken); + if (user != null) + { + (await RemovePasswordAsync(user)).CheckErrors(); + (await AddPasswordAsync(user, password)).CheckErrors(); + } + } + } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/SetPasswordEventHandler.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/SetPasswordEventHandler.cs new file mode 100644 index 0000000000..ec56dfe059 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/SetPasswordEventHandler.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.Users; + +namespace Volo.Abp.Identity; +public class SetPasswordEventHandler : + IDistributedEventHandler, + ITransientDependency +{ + protected IdentityUserManager UserManager { get; } + + public SetPasswordEventHandler( + IdentityUserManager permissionManager) + { + UserManager = permissionManager; + } + + public async Task HandleEventAsync(UserPasswordChangeRequestedEto eventData) + { + await UserManager.SetPasswordAsync( + eventData.TenantId, + eventData.UserName, + eventData.Password); + } +} \ No newline at end of file