diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml index 92e9941d58..23350442b2 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml @@ -29,10 +29,15 @@ {

@L["ChangePassword"].Value


- - +
+ @if (!Model.HideOldPasswordInput) + { + + } + + - +
} diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs index 500393caac..a563ba346e 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs @@ -14,6 +14,8 @@ namespace Volo.Abp.Account.Web.Pages.Account public bool DisablePasswordChange { get; set; } + public bool HideOldPasswordInput { get; set; } + protected IProfileAppService ProfileAppService { get; } public ManageModel(IProfileAppService profileAppService) @@ -28,6 +30,7 @@ namespace Volo.Abp.Account.Web.Pages.Account PersonalSettingsInfoModel = ObjectMapper.Map(user); DisablePasswordChange = user.IsExternalLoggedIn; + HideOldPasswordInput = !user.HasPassword; return Page(); } diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js index 68109eb6da..3c7c4148e8 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js @@ -15,13 +15,13 @@ if ( input.newPassword != input.newPasswordConfirm || - input.currentPassword == '' + input.newPassword == '' ) { abp.message.error(l('NewPasswordConfirmFailed')); return; } - if (input.currentPassword == '') { + if (input.currentPassword && input.currentPassword == ''){ return; } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ChangePasswordInput.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ChangePasswordInput.cs index a5bd73908a..460e1407fd 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ChangePasswordInput.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ChangePasswordInput.cs @@ -1,9 +1,15 @@ -namespace Volo.Abp.Identity +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace Volo.Abp.Identity { public class ChangePasswordInput { + [DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))] public string CurrentPassword { get; set; } + [Required] + [DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))] public string NewPassword { get; set; } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs index f21f415f2d..4b97a518db 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs @@ -15,5 +15,7 @@ namespace Volo.Abp.Identity public string PhoneNumber { get; set; } public bool IsExternalLoggedIn { get; set; } + + public bool HasPassword { get; set; } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs index 4fe61aab88..d4f27f1972 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs @@ -15,6 +15,7 @@ namespace Volo.Abp.Identity CreateMap() .Ignore(x=>x.IsExternalLoggedIn) + .Ignore(x=>x.HasPassword) .MapExtraProperties(); } } 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 6379c7983f..73e438b640 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 @@ -24,7 +24,8 @@ namespace Volo.Abp.Identity var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); var profile = ObjectMapper.Map(currentUser); - profile.IsExternalLoggedIn = currentUser.Logins.Any(); + profile.IsExternalLoggedIn = currentUser.IsExternal; + profile.HasPassword = currentUser.PasswordHash != null; return profile; } @@ -61,12 +62,19 @@ namespace Volo.Abp.Identity { var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); - var isExternalLoggedIn = currentUser.Logins.Any(); - if (isExternalLoggedIn) + if (currentUser.IsExternal) { throw new BusinessException(code: IdentityErrorCodes.ExternalUserPasswordChange); } + if (currentUser.PasswordHash == null) + { + (await UserManager.RemovePasswordAsync(currentUser)).CheckErrors(); + (await UserManager.AddPasswordAsync(currentUser, input.NewPassword)).CheckErrors(); + + return; + } + (await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors(); } }