From 8888c55d2ef9da8aaa15b92e40b39725579537f7 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 1 Sep 2021 09:02:41 +0100 Subject: [PATCH] Update to use constants for emailtype strings --- src/Umbraco.Core/Constants-Web.cs | 9 +++++++++ .../NotificationMethods/EmailNotificationMethod.cs | 2 +- .../Services/Implement/NotificationService.cs | 2 +- .../Controllers/AuthenticationController.cs | 4 ++-- .../Controllers/UsersController.cs | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Constants-Web.cs b/src/Umbraco.Core/Constants-Web.cs index 13cd7d7ad3..f6a8c00970 100644 --- a/src/Umbraco.Core/Constants-Web.cs +++ b/src/Umbraco.Core/Constants-Web.cs @@ -59,6 +59,15 @@ namespace Umbraco.Cms.Core public const string ActionToken = "action"; public const string AreaToken = "area"; } + + public static class EmailTypes + { + public const string HealthCheck = "HealthCheck"; + public const string Notification = "Notification"; + public const string PasswordReset = "PasswordReset"; + public const string TwoFactorAuth = "2FA"; + public const string UserInvite = "UserInvite"; + } } } } diff --git a/src/Umbraco.Core/HealthChecks/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Core/HealthChecks/NotificationMethods/EmailNotificationMethod.cs index 9842cff576..8de4cd8cc3 100644 --- a/src/Umbraco.Core/HealthChecks/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Core/HealthChecks/NotificationMethods/EmailNotificationMethod.cs @@ -74,7 +74,7 @@ namespace Umbraco.Cms.Core.HealthChecks.NotificationMethods var mailMessage = CreateMailMessage(subject, message); - await _emailSender.SendAsync(mailMessage, "HealthCheck"); + await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.HealthCheck); } private EmailMessage CreateMailMessage(string subject, string message) diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 0299f3c23f..dc45319d12 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -519,7 +519,7 @@ namespace Umbraco.Cms.Core.Services.Implement { try { - _emailSender.SendAsync(request.Mail, "Notification").GetAwaiter().GetResult(); + _emailSender.SendAsync(request.Mail, Constants.Web.EmailTypes.Notification).GetAwaiter().GetResult(); _logger.LogDebug("Notification '{Action}' sent to {Username} ({Email})", request.Action, request.UserName, request.Email); } catch (Exception ex) diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs index a33df694e8..54bfbeeb5f 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs @@ -394,7 +394,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers var mailMessage = new EmailMessage(from, user.Email, subject, message, true); - await _emailSender.SendAsync(mailMessage, "PasswordReset"); + await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.PasswordReset); _userManager.NotifyForgotPasswordRequested(User, user.Id.ToString()); } @@ -458,7 +458,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers { var mailMessage = new EmailMessage(from, user.Email, subject, message, true); - await _emailSender.SendAsync(mailMessage, "2FA"); + await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.TwoFactorAuth); } else if (provider == "Phone") { diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs index 2f1fbfa78a..821719c796 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs @@ -559,7 +559,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers var mailMessage = new EmailMessage(fromEmail, toMailBoxAddress.ToString(), emailSubject, emailBody, true); - await _emailSender.SendAsync(mailMessage, "UserInvite", true); + await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.UserInvite, true); } ///