Do not show "password change" if the user has registered via social login

resolves https://github.com/abpframework/abp/issues/4928
pull/4975/head
Yunus Emre Kalkan 5 years ago
parent 279faf95b3
commit 33f3916716

@ -25,33 +25,36 @@
<abp-card>
<abp-card-body>
<abp-tabs tab-style="PillVertical">
<abp-tab title="@L["ChangePassword"].Value">
<h4>@L["ChangePassword"].Value</h4><hr />
<abp-dynamic-form abp-model="@Model.ChangePasswordInfoModel" id="ChangePasswordForm">
<abp-form-content />
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value" />
</abp-dynamic-form>
</abp-tab>
@if (!Model.DisablePasswordChange)
{
<abp-tab title="@L["ChangePassword"].Value">
<h4>@L["ChangePassword"].Value</h4><hr/>
<abp-dynamic-form abp-model="@Model.ChangePasswordInfoModel" id="ChangePasswordForm">
<abp-form-content/>
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value"/>
</abp-dynamic-form>
</abp-tab>
}
<abp-tab title="@L["PersonalSettings"].Value">
<h4>@L["PersonalSettings"].Value</h4><hr />
<h4>@L["PersonalSettings"].Value</h4><hr/>
<form method="post" id="PersonalSettingsForm">
<abp-input asp-for="PersonalSettingsInfoModel.UserName" readonly="!isUserNameUpdateEnabled" />
<abp-input asp-for="PersonalSettingsInfoModel.UserName" readonly="!isUserNameUpdateEnabled"/>
<abp-row>
<abp-column size-md="_6">
<abp-input asp-for="PersonalSettingsInfoModel.Name" />
<abp-input asp-for="PersonalSettingsInfoModel.Name"/>
</abp-column>
<abp-column size-md="_6">
<abp-input asp-for="PersonalSettingsInfoModel.Surname" />
<abp-input asp-for="PersonalSettingsInfoModel.Surname"/>
</abp-column>
</abp-row>
<abp-input asp-for="PersonalSettingsInfoModel.Email" readonly="!isEmailUpdateEnabled" />
<abp-input asp-for="PersonalSettingsInfoModel.Email" readonly="!isEmailUpdateEnabled"/>
<abp-input asp-for="PersonalSettingsInfoModel.PhoneNumber" />
<abp-input asp-for="PersonalSettingsInfoModel.PhoneNumber"/>
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value" />
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value"/>
</form>
</abp-tab>
</abp-tabs>

@ -12,6 +12,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
public PersonalSettingsInfoModel PersonalSettingsInfoModel { get; set; }
public bool DisablePasswordChange { get; set; }
protected IProfileAppService ProfileAppService { get; }
public ManageModel(IProfileAppService profileAppService)
@ -25,6 +27,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
PersonalSettingsInfoModel = ObjectMapper.Map<ProfileDto, PersonalSettingsInfoModel>(user);
DisablePasswordChange = user.IsExternalLoggedIn;
return Page();
}
@ -54,7 +58,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
[DataType(DataType.Password)]
public string NewPasswordConfirm { get; set; }
}
public class PersonalSettingsInfoModel
{
[Required]

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

@ -1,4 +1,5 @@
using AutoMapper;
using Volo.Abp.AutoMapper;
namespace Volo.Abp.Identity
{
@ -11,9 +12,10 @@ namespace Volo.Abp.Identity
CreateMap<IdentityRole, IdentityRoleDto>()
.MapExtraProperties();
CreateMap<IdentityUser, ProfileDto>()
.Ignore(x=>x.IsExternalLoggedIn)
.MapExtraProperties();
}
}
}
}

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Volo.Abp.Identity.Settings;
@ -20,9 +21,12 @@ namespace Volo.Abp.Identity
public virtual async Task<ProfileDto> GetAsync()
{
return ObjectMapper.Map<IdentityUser, ProfileDto>(
await UserManager.GetByIdAsync(CurrentUser.GetId())
);
var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());
var profile = ObjectMapper.Map<IdentityUser, ProfileDto>(currentUser);
profile.IsExternalLoggedIn = currentUser.Logins.Any();
return profile;
}
public virtual async Task<ProfileDto> UpdateAsync(UpdateProfileDto input)
@ -56,6 +60,13 @@ namespace Volo.Abp.Identity
public virtual async Task ChangePasswordAsync(ChangePasswordInput input)
{
var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());
var isExternalLoggedIn = currentUser.Logins.Any();
if (isExternalLoggedIn)
{
throw new BusinessException(code: IdentityErrorCodes.ExternalUserPasswordChange);
}
(await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors();
}
}

@ -4,5 +4,6 @@
{
public const string UserSelfDeletion = "Volo.Abp.Identity:010001";
public const string MaxAllowedOuMembership = "Volo.Abp.Identity:010002";
public const string ExternalUserPasswordChange = "Volo.Abp.Identity:010003";
}
}
}

@ -102,6 +102,7 @@
"Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "Whether a confirmed telephone number is required to sign in.",
"Description:Abp.Identity.User.IsUserNameUpdateEnabled": "Whether the username can be updated by the user.",
"Description:Abp.Identity.User.IsEmailUpdateEnabled": "Whether the email can be updated by the user.",
"Volo.Abp.Identity:010002": "Can not set more than {MaxUserMembershipCount} organization unit for a user!"
"Volo.Abp.Identity:010002": "Can not set more than {MaxUserMembershipCount} organization unit for a user!",
"Volo.Abp.Identity:010003": "Can not change password of an externally logged in user!"
}
}

Loading…
Cancel
Save