From b8d41b47f11de57fff4f160fb71b8fd98207ac8b Mon Sep 17 00:00:00 2001 From: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Date: Thu, 23 Jun 2022 10:44:41 -0500 Subject: [PATCH] [PS-794] Fix password reset email templates email format (#2068) * Fix password reset email templates email format --- .../Services/Implementations/HandlebarsMailService.cs | 9 +++++++-- src/Core/Services/Implementations/UserService.cs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Core/Services/Implementations/HandlebarsMailService.cs b/src/Core/Services/Implementations/HandlebarsMailService.cs index 03f975b0a..905148ff3 100644 --- a/src/Core/Services/Implementations/HandlebarsMailService.cs +++ b/src/Core/Services/Implementations/HandlebarsMailService.cs @@ -418,7 +418,7 @@ namespace Bit.Core.Services var message = CreateDefaultMessage("Master Password Has Been Changed", email); var model = new AdminResetPasswordViewModel() { - UserName = CoreHelpers.SanitizeForEmail(userName), + UserName = GetUserIdentifier(email, userName), OrgName = CoreHelpers.SanitizeForEmail(orgName), }; await AddMessageContentAsync(message, "AdminResetPassword", model); @@ -766,7 +766,7 @@ namespace Bit.Core.Services var message = CreateDefaultMessage("Master Password Has Been Changed", email); var model = new UpdateTempPasswordViewModel() { - UserName = CoreHelpers.SanitizeForEmail(userName) + UserName = GetUserIdentifier(email, userName) }; await AddMessageContentAsync(message, "UpdatedTempPassword", model); message.Category = "UpdatedTempPassword"; @@ -886,5 +886,10 @@ namespace Bit.Core.Services message.Category = "FailedTwoFactorAttempts"; await _mailDeliveryService.SendEmailAsync(message); } + + private static string GetUserIdentifier(string email, string userName) + { + return string.IsNullOrEmpty(userName) ? email : CoreHelpers.SanitizeForEmail(userName, false); + } } } diff --git a/src/Core/Services/Implementations/UserService.cs b/src/Core/Services/Implementations/UserService.cs index ced91ce6b..73077665e 100644 --- a/src/Core/Services/Implementations/UserService.cs +++ b/src/Core/Services/Implementations/UserService.cs @@ -794,7 +794,7 @@ namespace Bit.Core.Services user.ForcePasswordReset = true; await _userRepository.ReplaceAsync(user); - await _mailService.SendAdminResetPasswordEmailAsync(user.Email, user.Name ?? user.Email, org.Name); + await _mailService.SendAdminResetPasswordEmailAsync(user.Email, user.Name, org.Name); await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_AdminResetPassword); await _pushService.PushLogOutAsync(user.Id); @@ -820,7 +820,7 @@ namespace Bit.Core.Services user.MasterPasswordHint = hint; await _userRepository.ReplaceAsync(user); - await _mailService.SendUpdatedTempPasswordEmailAsync(user.Email, user.Name ?? user.Email); + await _mailService.SendUpdatedTempPasswordEmailAsync(user.Email, user.Name); await _eventService.LogUserEventAsync(user.Id, EventType.User_UpdatedTempPassword); await _pushService.PushLogOutAsync(user.Id);