From b3867fdcae010d545ca55a4c4694c4d38b904c83 Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Wed, 13 Mar 2024 16:35:37 +0100 Subject: [PATCH] Improved Account related Mails --- Wave/Program.cs | 2 +- .../Services/IdentityEmailSender.de-DE.resx | 125 ++++++++++++++++++ .../Services/IdentityEmailSender.en-GB.resx | 101 ++++++++++++++ .../Services/IdentityEmailSender.resx | 125 ++++++++++++++++++ ...pEmailSender.cs => IdentityEmailSender.cs} | 18 ++- 5 files changed, 363 insertions(+), 8 deletions(-) create mode 100644 Wave/Resources/Services/IdentityEmailSender.de-DE.resx create mode 100644 Wave/Resources/Services/IdentityEmailSender.en-GB.resx create mode 100644 Wave/Resources/Services/IdentityEmailSender.resx rename Wave/Services/{SmtpEmailSender.cs => IdentityEmailSender.cs} (56%) diff --git a/Wave/Program.cs b/Wave/Program.cs index 8f50722..e56a886 100644 --- a/Wave/Program.cs +++ b/Wave/Program.cs @@ -195,7 +195,7 @@ if (emailConfig.Smtp.Keys.Any(k => k.Equals("live", StringComparison.CurrentCultureIgnoreCase))) { builder.Services.AddScoped(sp => sp.GetKeyedService("live")!); - builder.Services.AddScoped, SmtpEmailSender>(); + builder.Services.AddScoped, IdentityEmailSender>(); } else { builder.Services.AddSingleton, IdentityNoOpEmailSender>(); logMessages.Add("No 'live' email provider configured."); diff --git a/Wave/Resources/Services/IdentityEmailSender.de-DE.resx b/Wave/Resources/Services/IdentityEmailSender.de-DE.resx new file mode 100644 index 0000000..590aef1 --- /dev/null +++ b/Wave/Resources/Services/IdentityEmailSender.de-DE.resx @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Bestätigen Sie ihre Mailadresse + + + Bitte bestätigen Sie ihre Mailadresse, indem Sie den folgenden Link öffnen. + + + E-Mail Adresse Bestätigen + + + E-Mail Bestätigen + + + Passwort Ändern + + + Passwort zurücksetzen + + + Bitte öffnen Sie den folgenden link um Ihr Passwort zu ändern. + + + Passwort Ändern + + \ No newline at end of file diff --git a/Wave/Resources/Services/IdentityEmailSender.en-GB.resx b/Wave/Resources/Services/IdentityEmailSender.en-GB.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Wave/Resources/Services/IdentityEmailSender.en-GB.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Wave/Resources/Services/IdentityEmailSender.resx b/Wave/Resources/Services/IdentityEmailSender.resx new file mode 100644 index 0000000..3f91c73 --- /dev/null +++ b/Wave/Resources/Services/IdentityEmailSender.resx @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Confirm E-Mail Address + + + Please confirm your account by opening the following link. + + + Confirm Your Email + + + Confirm email + + + Please open the following link to change your password. + + + Reset your password + + + Change Password + + + Change Password + + \ No newline at end of file diff --git a/Wave/Services/SmtpEmailSender.cs b/Wave/Services/IdentityEmailSender.cs similarity index 56% rename from Wave/Services/SmtpEmailSender.cs rename to Wave/Services/IdentityEmailSender.cs index a1a6f63..2b33076 100644 --- a/Wave/Services/SmtpEmailSender.cs +++ b/Wave/Services/IdentityEmailSender.cs @@ -1,23 +1,27 @@ using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Localization; using Wave.Data; namespace Wave.Services; -public class SmtpEmailSender(EmailFactory email, [FromKeyedServices("live")]IEmailService emailService) : IEmailSender, IAsyncDisposable { +public class IdentityEmailSender(EmailFactory email, [FromKeyedServices("live")]IEmailService emailService, IStringLocalizer localizer) : IEmailSender, IAsyncDisposable { private EmailFactory Email { get; } = email; private IEmailService EmailService { get; } = emailService; + private IStringLocalizer Localizer { get; } = localizer; #region IEmailSenderAsync public Task SendConfirmationLinkAsync(ApplicationUser user, string email, string confirmationLink) => - SendDefaultMailAsync(email, user.FullName, "Confirm your email", "Confirm your email", - $"

Please confirm your account by clicking here.

", - $"Please confirm your account by clicking here: {confirmationLink}"); + SendDefaultMailAsync(email, user.FullName, Localizer["ConfirmationMail_Subject"], Localizer["ConfirmationMail_Title"], + $"

{Localizer["ConfirmationMail_Body"]}

" + + $"

{Localizer["ConfirmName_LinkLabel"]}

", + $"{Localizer["ConfirmationMail_Body"]} {confirmationLink}"); public Task SendPasswordResetLinkAsync(ApplicationUser user, string email, string resetLink) => - SendDefaultMailAsync(email, user.FullName, "Reset your password", "Reset your password", - $"

Please reset your password by clicking here.

", - $"Please reset your password by clicking here: {resetLink}"); + SendDefaultMailAsync(email, user.FullName, Localizer["PasswordResetMail_Subject"], Localizer["PasswordResetMail_Title"], + $"

{Localizer["PasswordResetMail_Body"]}

" + + $"

{Localizer["PasswordResetMail_LinkLabel"]}.

", + $"{Localizer["PasswordResetMail_Body"]} {resetLink}"); public Task SendPasswordResetCodeAsync(ApplicationUser user, string email, string resetCode) => SendDefaultMailAsync(email, user.FullName, "Reset your password", "Reset your password",