diff --git a/UT4MasterServer.Services/Interfaces/IEmailService.cs b/UT4MasterServer.Services/Interfaces/IEmailService.cs new file mode 100644 index 00000000..46357f5a --- /dev/null +++ b/UT4MasterServer.Services/Interfaces/IEmailService.cs @@ -0,0 +1,7 @@ +namespace UT4MasterServer.Services.Interfaces; + +public interface IEmailService +{ + Task SendTextEmailAsync(string fromAddress, List toAddresses, string subject, string body); + Task SendHTMLEmailAsync(string fromAddress, List toAddresses, string subject, string body); +} diff --git a/UT4MasterServer.Services/Scoped/AccountService.cs b/UT4MasterServer.Services/Scoped/AccountService.cs index 534aab90..af3c9abe 100644 --- a/UT4MasterServer.Services/Scoped/AccountService.cs +++ b/UT4MasterServer.Services/Scoped/AccountService.cs @@ -7,6 +7,7 @@ using UT4MasterServer.Models.Database; using UT4MasterServer.Models.DTO.Responses; using UT4MasterServer.Models.Settings; +using UT4MasterServer.Services.Interfaces; namespace UT4MasterServer.Services.Scoped; @@ -14,16 +15,16 @@ public sealed class AccountService { private readonly IMongoCollection accountCollection; private readonly ApplicationSettings applicationSettings; - private readonly AwsSesClient awsSesClient; + private readonly IEmailService emailService; public AccountService( DatabaseContext dbContext, IOptions applicationSettings, - AwsSesClient awsSesClient) + IEmailService emailService) { this.applicationSettings = applicationSettings.Value; accountCollection = dbContext.Database.GetCollection("accounts"); - this.awsSesClient = awsSesClient; + this.emailService = emailService; } public async Task CreateIndexesAsync() @@ -296,7 +297,7 @@ private async Task SendVerificationLinkAsync(string email, EpicID accountID, str

Click here to verify your email.

"; - await awsSesClient.SendHTMLEmailAsync(applicationSettings.NoReplyEmail, new List() { email }, "Email Verification", html); + await emailService.SendHTMLEmailAsync(applicationSettings.NoReplyEmail, new List() { email }, "Email Verification", html); } private async Task SendResetPasswordLinkAsync(string email, EpicID accountID, string guid) @@ -315,6 +316,6 @@ private async Task SendResetPasswordLinkAsync(string email, EpicID accountID, st

If you didn't initiate password reset, ignore this message.

"; - await awsSesClient.SendHTMLEmailAsync(applicationSettings.NoReplyEmail, new List() { email }, "Reset Password", html); + await emailService.SendHTMLEmailAsync(applicationSettings.NoReplyEmail, new List() { email }, "Reset Password", html); } } diff --git a/UT4MasterServer.Services/Scoped/AwsSesClient.cs b/UT4MasterServer.Services/Scoped/AwsSesClient.cs index b8df2d45..b8d1fa8b 100644 --- a/UT4MasterServer.Services/Scoped/AwsSesClient.cs +++ b/UT4MasterServer.Services/Scoped/AwsSesClient.cs @@ -5,10 +5,11 @@ using System.Text.Json; using UT4MasterServer.Common.Exceptions; using UT4MasterServer.Models.Settings; +using UT4MasterServer.Services.Interfaces; namespace UT4MasterServer.Services.Scoped; -public sealed class AwsSesClient +public sealed class AwsSesClient : IEmailService { private readonly ILogger _logger; private readonly IAmazonSimpleEmailService _amazonSimpleEmailService; diff --git a/UT4MasterServer/Controllers/AdminPanelController.cs b/UT4MasterServer/Controllers/AdminPanelController.cs index 47da042c..78e028d2 100644 --- a/UT4MasterServer/Controllers/AdminPanelController.cs +++ b/UT4MasterServer/Controllers/AdminPanelController.cs @@ -10,6 +10,7 @@ using UT4MasterServer.Models.DTO.Requests; using UT4MasterServer.Models.DTO.Responses; using UT4MasterServer.Models.Responses; +using UT4MasterServer.Services.Interfaces; using UT4MasterServer.Services.Scoped; namespace UT4MasterServer.Controllers; @@ -27,7 +28,7 @@ public sealed class AdminPanelController : ControllerBase private readonly TrustedGameServerService trustedGameServerService; private readonly MatchmakingService matchmakingService; private readonly CleanupService cleanupService; - private readonly AwsSesClient awsSesClient; + private readonly IEmailService emailService; public AdminPanelController( ILogger logger, @@ -38,7 +39,7 @@ public AdminPanelController( TrustedGameServerService trustedGameServerService, MatchmakingService matchmakingService, CleanupService cleanupService, - AwsSesClient awsSesClient) + IEmailService emailService) { this.logger = logger; this.accountService = accountService; @@ -48,7 +49,7 @@ public AdminPanelController( this.trustedGameServerService = trustedGameServerService; this.matchmakingService = matchmakingService; this.cleanupService = cleanupService; - this.awsSesClient = awsSesClient; + this.emailService = emailService; } #region Accounts @@ -571,14 +572,14 @@ public async Task DeleteMCPFile(string filename) [HttpPost("send-text-email")] public async Task SendTextEmail([FromBody] SendEmailRequest sendEmailRequest) { - await awsSesClient.SendTextEmailAsync(sendEmailRequest.From, sendEmailRequest.To, sendEmailRequest.Subject, sendEmailRequest.Body); + await emailService.SendTextEmailAsync(sendEmailRequest.From, sendEmailRequest.To, sendEmailRequest.Subject, sendEmailRequest.Body); return Ok(); } [HttpPost("send-html-email")] public async Task SendHtmlEmail([FromBody] SendEmailRequest sendEmailRequest) { - await awsSesClient.SendHTMLEmailAsync(sendEmailRequest.From, sendEmailRequest.To, sendEmailRequest.Subject, sendEmailRequest.Body); + await emailService.SendHTMLEmailAsync(sendEmailRequest.From, sendEmailRequest.To, sendEmailRequest.Subject, sendEmailRequest.Body); return Ok(); } diff --git a/UT4MasterServer/Program.cs b/UT4MasterServer/Program.cs index 616c6f6e..695eada4 100644 --- a/UT4MasterServer/Program.cs +++ b/UT4MasterServer/Program.cs @@ -15,6 +15,7 @@ using UT4MasterServer.Services.Scoped; using UT4MasterServer.Services.Singleton; using UT4MasterServer.Services.Hosted; +using UT4MasterServer.Services.Interfaces; namespace UT4MasterServer; @@ -115,7 +116,7 @@ public static void Main(string[] args) .AddScoped() .AddScoped() .AddScoped() - .AddScoped() + .AddScoped() .AddScoped(); // services whose instance is created once and are persistent