Skip to content

Commit

Permalink
Update user properties when it's changed.
Browse files Browse the repository at this point in the history
Resolve #7430
  • Loading branch information
maliming committed Jan 26, 2021
1 parent d8830a5 commit 78d0523
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
Expand Down Expand Up @@ -37,17 +38,26 @@ public virtual async Task<ProfileDto> UpdateAsync(UpdateProfileDto input)

var user = await UserManager.GetByIdAsync(CurrentUser.GetId());

if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled))
if (!string.Equals(user.UserName, input.UserName, StringComparison.InvariantCultureIgnoreCase))
{
(await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled))
{
(await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
}
}

if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsEmailUpdateEnabled))
if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase))
{
(await UserManager.SetEmailAsync(user, input.Email)).CheckErrors();
if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsEmailUpdateEnabled))
{
(await UserManager.SetEmailAsync(user, input.Email)).CheckErrors();
}
}

(await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors();
if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase))
{
(await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors();
}

user.Name = input.Name;
user.Surname = input.Surname;
Expand Down

0 comments on commit 78d0523

Please sign in to comment.