Revise how to change the password for external logins

pull/4975/head
Yunus Emre Kalkan 5 years ago
parent d737b93721
commit 09ba60f8f9

@ -29,10 +29,15 @@
{
<abp-tab title="@L["ChangePassword"].Value">
<h4>@L["ChangePassword"].Value</h4><hr/>
<abp-dynamic-form abp-model="@Model.ChangePasswordInfoModel" id="ChangePasswordForm">
<abp-form-content/>
<form id="ChangePasswordForm">
@if (!Model.HideOldPasswordInput)
{
<abp-input asp-for="ChangePasswordInfoModel.CurrentPassword"/>
}
<abp-input asp-for="ChangePasswordInfoModel.NewPassword"/>
<abp-input asp-for="ChangePasswordInfoModel.NewPasswordConfirm"/>
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value"/>
</abp-dynamic-form>
</form>
</abp-tab>
}
<abp-tab title="@L["PersonalSettings"].Value">

@ -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<ProfileDto, PersonalSettingsInfoModel>(user);
DisablePasswordChange = user.IsExternalLoggedIn;
HideOldPasswordInput = !user.HasPassword;
return Page();
}

@ -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;
}

@ -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; }
}
}

@ -15,5 +15,7 @@ namespace Volo.Abp.Identity
public string PhoneNumber { get; set; }
public bool IsExternalLoggedIn { get; set; }
public bool HasPassword { get; set; }
}
}

@ -15,6 +15,7 @@ namespace Volo.Abp.Identity
CreateMap<IdentityUser, ProfileDto>()
.Ignore(x=>x.IsExternalLoggedIn)
.Ignore(x=>x.HasPassword)
.MapExtraProperties();
}
}

@ -24,7 +24,8 @@ namespace Volo.Abp.Identity
var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());
var profile = ObjectMapper.Map<IdentityUser, ProfileDto>(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();
}
}

Loading…
Cancel
Save