diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs index 8927121bf9..f3e342503c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs @@ -14,7 +14,5 @@ namespace Volo.Abp.Identity Task FindByUsernameAsync(string username); Task FindByEmailAsync(string email); - - Task ChangePasswordAsync(string currentPassword, string newPassword); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IProfileAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IProfileAppService.cs index cb61fc6a82..142b5ad16a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IProfileAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IProfileAppService.cs @@ -8,5 +8,7 @@ namespace Volo.Abp.Identity Task GetAsync(); Task UpdateAsync(UpdateProfileDto input); + + Task ChangePasswordAsync(string currentPassword, string newPassword); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index 251b429d33..ad87b0041f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -118,18 +118,6 @@ namespace Volo.Abp.Identity ); } - //TODO: Move this to the profile service! - public async Task ChangePasswordAsync(string currentPassword, string newPassword) - { - if (!CurrentUser.Id.HasValue) - { - throw new AbpException("Current user Id is null!"); - } - - var currentUser = await _userManager.GetByIdAsync(CurrentUser.Id.Value); - (await _userManager.ChangePasswordAsync(currentUser, currentPassword, newPassword)).CheckErrors(); - } - private async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input) { (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs index a47734cd0c..64a78b81ca 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs @@ -49,5 +49,11 @@ namespace Volo.Abp.Identity return ObjectMapper.Map(user); } + + public async Task ChangePasswordAsync(string currentPassword, string newPassword) + { + var currentUser = await _userManager.GetByIdAsync(CurrentUser.GetId()); + (await _userManager.ChangePasswordAsync(currentUser, currentPassword, newPassword)).CheckErrors(); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs index 2728e16fbd..acbc211b0f 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs @@ -64,10 +64,5 @@ namespace Volo.Abp.Identity { return _userAppService.FindByEmailAsync(email); } - - public Task ChangePasswordAsync(string currentPassword, string newPassword) - { - return _userAppService.ChangePasswordAsync(currentPassword, newPassword); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs index b1bb8a744c..4547bbdc1c 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; @@ -27,5 +24,10 @@ namespace Volo.Abp.Identity { return _profileAppService.UpdateAsync(input); } + + public Task ChangePasswordAsync(string currentPassword, string newPassword) + { + return _profileAppService.ChangePasswordAsync(currentPassword, newPassword); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs index 0e753edd6c..29dda11426 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs @@ -12,13 +12,14 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Shared [BindProperty] public ChangePasswordInfoModel ChangePasswordInfoModel { get; set; } - private readonly IIdentityUserAppService _userAppService; + private readonly IProfileAppService _profileAppService; private readonly IStringLocalizer _localizer; - public ChangePasswordModal(IIdentityUserAppService userAppService, + public ChangePasswordModal( + IProfileAppService profileAppService, IStringLocalizer localizer) { - _userAppService = userAppService; + _profileAppService = profileAppService; _localizer = localizer; } @@ -31,8 +32,10 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Shared throw new UserFriendlyException(_localizer.GetString("Identity.PasswordConfirmationFailed").Value); } - await _userAppService.ChangePasswordAsync(ChangePasswordInfoModel.CurrentPassword, - ChangePasswordInfoModel.NewPassword); + await _profileAppService.ChangePasswordAsync( + ChangePasswordInfoModel.CurrentPassword, + ChangePasswordInfoModel.NewPassword + ); return NoContent(); }