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 d133350921..444ccb34b1 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,9 +1,8 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; +using Volo.Abp.Identity.Settings; using Volo.Abp.Users; namespace Volo.Abp.Identity @@ -29,13 +28,30 @@ namespace Volo.Abp.Identity { var user = await _userManager.GetByIdAsync(CurrentUser.GetId()); - (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); - (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); + + var isUsernameUpdateEnabled = string.Equals(await (SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled)), + "true", StringComparison.OrdinalIgnoreCase); + + if (isUsernameUpdateEnabled) + { + (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); + } + + var isEmailUpdateEnabled = !string.Equals(await (SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsEmailUpdateEnabled)), + "true", StringComparison.OrdinalIgnoreCase); + + if (isEmailUpdateEnabled) + { + (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); + } + (await _userManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); + user.Name = input.Name; user.Surname = input.Surname; (await _userManager.UpdateAsync(user)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); return ObjectMapper.Map(user); diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml index 666d21f0e4..9da2cfe074 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml @@ -2,11 +2,19 @@ @using Microsoft.AspNetCore.Mvc.Localization @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @using Volo.Abp.Identity.Localization +@using Volo.Abp.Identity.Settings @using Volo.Abp.Identity.Web.Pages.Identity.Shared +@using Volo.Abp.Settings @model PersonalSettingsModal @inject IHtmlLocalizer L +@inject ISettingManager SettingManager @{ Layout = null; + var isUserNameUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled), "true", + StringComparison.OrdinalIgnoreCase); + + var isEmailUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsEmailUpdateEnabled), "true", + StringComparison.OrdinalIgnoreCase); }
@@ -14,7 +22,7 @@ - + @@ -25,7 +33,7 @@ - + diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs index 23606ba9e1..140abcacf6 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs @@ -1,10 +1,7 @@ -using System; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; -using Volo.Abp.Identity.Settings; -using Volo.Abp.Settings; namespace Volo.Abp.Identity.Web.Pages.Identity.Shared { @@ -12,19 +9,7 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Shared { [BindProperty] public PersonalSettingsInfoModel PersonalSettingsInfoModel { get; set; } - - [BindProperty] - public PersonalSettingsInfoModel PersonalSettingsInfoModel2 { get; set; } - - public bool IsUsernameUpdateDisabled => !string.Equals( - SettingManager.GetOrNull(IdentitySettingNames.User.IsUserNameUpdateEnabled), "true", - StringComparison.OrdinalIgnoreCase); - - public bool IsEmailUpdateDisabled => !string.Equals( - SettingManager.GetOrNull(IdentitySettingNames.User.IsEmailUpdateEnabled), "true", - StringComparison.OrdinalIgnoreCase); - - + private readonly IProfileAppService _profileAppService; public PersonalSettingsModal(IProfileAppService profileAppService) @@ -45,24 +30,6 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Shared var updateDto = ObjectMapper.Map(PersonalSettingsInfoModel); - ProfileDto user = null; - - if (IsUsernameUpdateDisabled ) - { - user = await _profileAppService.GetAsync(); - updateDto.UserName = user.UserName; - } - - if (IsEmailUpdateDisabled) - { - if (user == null) - { - user = await _profileAppService.GetAsync(); - } - - updateDto.Email = user.Email; - } - await _profileAppService.UpdateAsync(updateDto); return NoContent();