Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlock mail not sent 2022 1 #412

Merged
merged 2 commits into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 5 additions & 11 deletions backend/Origam.Security.Common/AccountMailSender.cs
Expand Up @@ -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
Expand All @@ -152,20 +152,14 @@ public class AccountMailSender
new KeyValuePair<string, string>("<%FirstNameAndName%>",
firstNameAndName)
};
// resolve recipient email
string resultEmail = email;
if (resultEmail == null)
{
resultEmail = userMail;
}

MailMessage userUnlockNotificationMail;
using (LanguageSwitcher langSwitcher = new LanguageSwitcher(
userLangIETF))
{
try
{
userUnlockNotificationMail = GenerateMail(resultEmail,
userUnlockNotificationMail = GenerateMail(email,
fromAddress, userUnlockNotificationBodyFilename,
Resources.UserUnlockNotificationTemplate,
userUnlockNotificationSubject, userLangIETF, replacements);
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions backend/Origam.ServerCore/Authorization/CoreManagerAdapter.cs
Expand Up @@ -100,8 +100,14 @@ public async Task<bool> UnlockUserAsync(string userName)
{
var user = await FindByNameAsync(userName);
if (user == null) { return false; }
return (await coreUserManager.SetLockoutEndDateAsync( user, null))
.Succeeded;

Task<IdentityResult> unlockTask = coreUserManager.SetLockoutEndDateAsync( user, null);
bool success = (await unlockTask).Succeeded;
if (success)
{
mailService.SendUserUnlockedMessage(user);
}
return success;
}

public async Task<InternalIdentityResult> ConfirmEmailAsync(string userId)
Expand Down
1 change: 1 addition & 0 deletions backend/Origam.ServerCore/Authorization/IMailService.cs
Expand Up @@ -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);
}
}
8 changes: 8 additions & 0 deletions backend/Origam.ServerCore/Authorization/MailService.cs
Expand Up @@ -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());
}
}
}