Browse Source

Revise how to change the password for external logins

pull/4975/head
Yunus Emre Kalkan 6 years ago
parent
commit
09ba60f8f9
  1. 11
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml
  2. 3
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs
  3. 4
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js
  4. 8
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ChangePasswordInput.cs
  5. 2
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs
  6. 1
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs
  7. 14
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs

11
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml

@ -29,10 +29,15 @@
{ {
<abp-tab title="@L["ChangePassword"].Value"> <abp-tab title="@L["ChangePassword"].Value">
<h4>@L["ChangePassword"].Value</h4><hr/> <h4>@L["ChangePassword"].Value</h4><hr/>
<abp-dynamic-form abp-model="@Model.ChangePasswordInfoModel" id="ChangePasswordForm"> <form id="ChangePasswordForm">
<abp-form-content/> @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-button type="submit" button-type="Primary" text="@L["Submit"].Value"/>
</abp-dynamic-form> </form>
</abp-tab> </abp-tab>
} }
<abp-tab title="@L["PersonalSettings"].Value"> <abp-tab title="@L["PersonalSettings"].Value">

3
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 DisablePasswordChange { get; set; }
public bool HideOldPasswordInput { get; set; }
protected IProfileAppService ProfileAppService { get; } protected IProfileAppService ProfileAppService { get; }
public ManageModel(IProfileAppService profileAppService) public ManageModel(IProfileAppService profileAppService)
@ -28,6 +30,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
PersonalSettingsInfoModel = ObjectMapper.Map<ProfileDto, PersonalSettingsInfoModel>(user); PersonalSettingsInfoModel = ObjectMapper.Map<ProfileDto, PersonalSettingsInfoModel>(user);
DisablePasswordChange = user.IsExternalLoggedIn; DisablePasswordChange = user.IsExternalLoggedIn;
HideOldPasswordInput = !user.HasPassword;
return Page(); return Page();
} }

4
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js

@ -15,13 +15,13 @@
if ( if (
input.newPassword != input.newPasswordConfirm || input.newPassword != input.newPasswordConfirm ||
input.currentPassword == '' input.newPassword == ''
) { ) {
abp.message.error(l('NewPasswordConfirmFailed')); abp.message.error(l('NewPasswordConfirmFailed'));
return; return;
} }
if (input.currentPassword == '') { if (input.currentPassword && input.currentPassword == ''){
return; return;
} }

8
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 public class ChangePasswordInput
{ {
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))]
public string CurrentPassword { get; set; } public string CurrentPassword { get; set; }
[Required]
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))]
public string NewPassword { get; set; } public string NewPassword { get; set; }
} }
} }

2
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 string PhoneNumber { get; set; }
public bool IsExternalLoggedIn { get; set; } public bool IsExternalLoggedIn { get; set; }
public bool HasPassword { get; set; }
} }
} }

1
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs

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

14
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 currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());
var profile = ObjectMapper.Map<IdentityUser, ProfileDto>(currentUser); var profile = ObjectMapper.Map<IdentityUser, ProfileDto>(currentUser);
profile.IsExternalLoggedIn = currentUser.Logins.Any(); profile.IsExternalLoggedIn = currentUser.IsExternal;
profile.HasPassword = currentUser.PasswordHash != null;
return profile; return profile;
} }
@ -61,12 +62,19 @@ namespace Volo.Abp.Identity
{ {
var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());
var isExternalLoggedIn = currentUser.Logins.Any(); if (currentUser.IsExternal)
if (isExternalLoggedIn)
{ {
throw new BusinessException(code: IdentityErrorCodes.ExternalUserPasswordChange); 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(); (await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors();
} }
} }

Loading…
Cancel
Save