From 28fc55ede9c1c656aad469a68e57be3dd82615f7 Mon Sep 17 00:00:00 2001 From: Jindrich Susen Date: Wed, 30 Mar 2022 10:15:13 +0200 Subject: [PATCH 1/2] INTERNAL: Redundant email parameter removed --- .../Origam.Security.Common/AccountMailSender.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/backend/Origam.Security.Common/AccountMailSender.cs b/backend/Origam.Security.Common/AccountMailSender.cs index a5aeccf6df..b5c6ba7cfb 100644 --- a/backend/Origam.Security.Common/AccountMailSender.cs +++ b/backend/Origam.Security.Common/AccountMailSender.cs @@ -141,7 +141,7 @@ public class AccountMailSender } public bool SendUserUnlockingNotification(string username, string email, - string languageId, string firstNameAndName, string userMail) + string languageId, string firstNameAndName) { string userLangIETF = ResolveIetfTagFromOrigamLanguageId(languageId); // build template replacements @@ -152,12 +152,6 @@ public class AccountMailSender new KeyValuePair("<%FirstNameAndName%>", firstNameAndName) }; - // resolve recipient email - string resultEmail = email; - if (resultEmail == null) - { - resultEmail = userMail; - } MailMessage userUnlockNotificationMail; using (LanguageSwitcher langSwitcher = new LanguageSwitcher( @@ -165,7 +159,7 @@ public class AccountMailSender { try { - userUnlockNotificationMail = GenerateMail(resultEmail, + userUnlockNotificationMail = GenerateMail(email, fromAddress, userUnlockNotificationBodyFilename, Resources.UserUnlockNotificationTemplate, userUnlockNotificationSubject, userLangIETF, replacements); @@ -176,7 +170,7 @@ public class AccountMailSender { log.ErrorFormat("Unlocking user: Failed to generate a mail" + " for a user `{0}' to `{1}': {2}" - , username, resultEmail, ex); + , username, email, ex); } throw ex; @@ -193,7 +187,7 @@ public class AccountMailSender { log.ErrorFormat("Unlocking user: Failed to send a mail" + " for a user `{0}' to `{1}': {2}" - , username, resultEmail, ex); + , username, email, ex); } throw new Exception( @@ -208,7 +202,7 @@ public class AccountMailSender { log.DebugFormat("User `{0}' has been unlocked and the" + " notification mail has been sent to `{1}'.", - username, resultEmail); + username, email); } return true; From 362a30b4e4a5ca34a900d6aca5c3526fadf79697 Mon Sep 17 00:00:00 2001 From: Jindrich Susen Date: Wed, 30 Mar 2022 10:22:00 +0200 Subject: [PATCH 2/2] FIX: Email was not sent after a user account was unlocked by the administrator --- .../Authorization/CoreManagerAdapter.cs | 10 ++++++++-- .../Origam.ServerCore/Authorization/IMailService.cs | 1 + backend/Origam.ServerCore/Authorization/MailService.cs | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/Origam.ServerCore/Authorization/CoreManagerAdapter.cs b/backend/Origam.ServerCore/Authorization/CoreManagerAdapter.cs index 759b78b19a..c573f0e7c0 100644 --- a/backend/Origam.ServerCore/Authorization/CoreManagerAdapter.cs +++ b/backend/Origam.ServerCore/Authorization/CoreManagerAdapter.cs @@ -100,8 +100,14 @@ public async Task UnlockUserAsync(string userName) { var user = await FindByNameAsync(userName); if (user == null) { return false; } - return (await coreUserManager.SetLockoutEndDateAsync( user, null)) - .Succeeded; + + Task unlockTask = coreUserManager.SetLockoutEndDateAsync( user, null); + bool success = (await unlockTask).Succeeded; + if (success) + { + mailService.SendUserUnlockedMessage(user); + } + return success; } public async Task ConfirmEmailAsync(string userId) diff --git a/backend/Origam.ServerCore/Authorization/IMailService.cs b/backend/Origam.ServerCore/Authorization/IMailService.cs index 4b7533f9ee..d7efa0e099 100644 --- a/backend/Origam.ServerCore/Authorization/IMailService.cs +++ b/backend/Origam.ServerCore/Authorization/IMailService.cs @@ -30,5 +30,6 @@ public interface IMailService void SendPasswordResetToken(IOrigamUser user, string token, int tokenValidityHours); void SendNewUserToken(IOrigamUser user, string token); void SendMultiFactorAuthCode(IOrigamUser user, string token); + void SendUserUnlockedMessage(IOrigamUser user); } } \ No newline at end of file diff --git a/backend/Origam.ServerCore/Authorization/MailService.cs b/backend/Origam.ServerCore/Authorization/MailService.cs index 12a14c5423..da9912aae2 100644 --- a/backend/Origam.ServerCore/Authorization/MailService.cs +++ b/backend/Origam.ServerCore/Authorization/MailService.cs @@ -110,5 +110,13 @@ public void SendMultiFactorAuthCode(IOrigamUser user, string token) email: user.Email, code: token); } + public void SendUserUnlockedMessage(IOrigamUser user) + { + mailSender.SendUserUnlockingNotification( + username: user.UserName, + email: user.Email, + firstNameAndName: user.FirstName + " " + user.Name, + languageId: user.LanguageId.ToString()); + } } } \ No newline at end of file