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 28aa876bba..92e9941d58 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 @@ -25,33 +25,36 @@ - -

@L["ChangePassword"].Value


- - - - -
+ @if (!Model.DisablePasswordChange) + { + +

@L["ChangePassword"].Value


+ + + + +
+ } -

@L["PersonalSettings"].Value


+

@L["PersonalSettings"].Value


- + - + - + - + - + - +
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 3c779dc870..500393caac 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 @@ -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(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] 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 4777c0ad23..f21f415f2d 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 @@ -13,5 +13,7 @@ namespace Volo.Abp.Identity public string Surname { get; set; } public string PhoneNumber { get; set; } + + public bool IsExternalLoggedIn { get; set; } } -} \ No newline at end of file +} 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 01a68dc677..4fe61aab88 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 @@ -1,4 +1,5 @@ using AutoMapper; +using Volo.Abp.AutoMapper; namespace Volo.Abp.Identity { @@ -11,9 +12,10 @@ namespace Volo.Abp.Identity CreateMap() .MapExtraProperties(); - + CreateMap() + .Ignore(x=>x.IsExternalLoggedIn) .MapExtraProperties(); } } -} \ No newline at end of file +} 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 45bcdf3e35..6379c7983f 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 @@ -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 GetAsync() { - return ObjectMapper.Map( - await UserManager.GetByIdAsync(CurrentUser.GetId()) - ); + var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); + + var profile = ObjectMapper.Map(currentUser); + profile.IsExternalLoggedIn = currentUser.Logins.Any(); + + return profile; } public virtual async Task 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(); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityErrorCodes.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityErrorCodes.cs index d77ee9f5a9..d5e57a6953 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityErrorCodes.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityErrorCodes.cs @@ -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"; } -} \ No newline at end of file +} diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json index 8305ca9589..41d152b06c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json @@ -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!" } }