From 1e0a7ce7048ec81912c9fda4348c76cca72e1dad Mon Sep 17 00:00:00 2001 From: Valeriy Baditsa Date: Mon, 1 Aug 2022 12:50:58 +0300 Subject: [PATCH 1/3] Plain text was added --- .../OutOfSchool.EmailSender/DevEmailSender.cs | 4 +-- .../OutOfSchool.EmailSender/EmailSender.cs | 6 ++--- .../OutOfSchool.EmailSender/IEmailSender.cs | 2 +- .../Controllers/AccountController.cs | 18 ++++++------- .../Services/MinistryAdminService.cs | 4 +-- .../Services/ProviderAdminService.cs | 4 +-- .../Services/IRazorViewToStringRenderer.cs | 24 ++++++------------ .../Services/RazorViewToStringRenderer.cs | 20 ++++++--------- .../wwwroot/images/Vector.png | Bin 468 -> 0 bytes 9 files changed, 35 insertions(+), 47 deletions(-) delete mode 100644 OutOfSchool/OutOfSchool.RazorTemplatesData/wwwroot/images/Vector.png diff --git a/OutOfSchool/OutOfSchool.EmailSender/DevEmailSender.cs b/OutOfSchool/OutOfSchool.EmailSender/DevEmailSender.cs index 204831a833..647168bfe4 100644 --- a/OutOfSchool/OutOfSchool.EmailSender/DevEmailSender.cs +++ b/OutOfSchool/OutOfSchool.EmailSender/DevEmailSender.cs @@ -12,9 +12,9 @@ public DevEmailSender(ILogger logger) this.logger = logger; } - public Task SendAsync(string email, string subject, string htmlMessage) + public Task SendAsync(string email, string subject, (string html, string plain) content) { - logger.LogDebug($"Sending mail to {email} with subject \"{subject}\" and content: {htmlMessage}"); + logger.LogDebug($"Sending mail to {email} with subject \"{subject}\" and content: {content.html}"); return Task.CompletedTask; } } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.EmailSender/EmailSender.cs b/OutOfSchool/OutOfSchool.EmailSender/EmailSender.cs index 3c6aeb68d8..7968132698 100644 --- a/OutOfSchool/OutOfSchool.EmailSender/EmailSender.cs +++ b/OutOfSchool/OutOfSchool.EmailSender/EmailSender.cs @@ -23,7 +23,7 @@ public EmailSender( this.logger = logger; } - public Task SendAsync(string email, string subject, string htmlMessage) + public Task SendAsync(string email, string subject, (string html, string plain) content) { var message = new SendGridMessage() { @@ -33,8 +33,8 @@ public Task SendAsync(string email, string subject, string htmlMessage) Name = emailOptions.Value.NameFrom, }, Subject = subject, - //TODO: Add plaintext message fallback - HtmlContent = htmlMessage + HtmlContent = content.html, + PlainTextContent = content.plain, }; message.AddTo(new EmailAddress(email)); diff --git a/OutOfSchool/OutOfSchool.EmailSender/IEmailSender.cs b/OutOfSchool/OutOfSchool.EmailSender/IEmailSender.cs index 865dad90bc..dfa0fa3d76 100644 --- a/OutOfSchool/OutOfSchool.EmailSender/IEmailSender.cs +++ b/OutOfSchool/OutOfSchool.EmailSender/IEmailSender.cs @@ -4,5 +4,5 @@ namespace OutOfSchool.EmailSender; public interface IEmailSender { - Task SendAsync(string email, string subject, string htmlMessage); + Task SendAsync(string email, string subject, (string html, string plain) content); } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs b/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs index a29a28b37f..fe9bbafece 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs @@ -123,9 +123,9 @@ public async Task ChangeEmail(ChangeEmailViewModel model) LastName = user.LastName, ActionUrl = HtmlEncoder.Default.Encode(callBackUrl), }; - var htmlMessage = await renderer.GetHtmlStringAsync(RazorTemplates.ChangeEmail, userActionViewModel); + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); - await emailSender.SendAsync(email, subject, htmlMessage); + await emailSender.SendAsync(email, subject, content); logger.LogInformation($"{path} Confirmation message was sent for User(id) + {userId}."); @@ -195,9 +195,9 @@ public async Task ConfirmEmail() LastName = user.LastName, ActionUrl = HtmlEncoder.Default.Encode(callBackUrl), }; - var htmlMessage = await renderer.GetHtmlStringAsync(RazorTemplates.ConfirmEmail, userActionViewModel); - - await emailSender.SendAsync(email, subject, htmlMessage); + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); + + await emailSender.SendAsync(email, subject, content); logger.LogInformation($"Confirmation message was sent. User(id): {userId}."); @@ -275,10 +275,10 @@ public async Task ForgotPassword(ForgotPasswordViewModel model) LastName = user.LastName, ActionUrl = callBackUrl, }; - - var htmlMessage = await renderer.GetHtmlStringAsync(RazorTemplates.ResetPassword, userActionViewModel); - - await emailSender.SendAsync(email, subject, htmlMessage); + + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); + + await emailSender.SendAsync(email, subject, content); logger.LogInformation($"{path} Message to change password was sent. User(id): {user.Id}."); diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs b/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs index cd8bf57b37..7ea26f5a28 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs @@ -145,9 +145,9 @@ await institutionAdminRepository.Create(ministryAdmin) Email = user.Email, Password = password, }; - var htmlMessage = await renderer.GetHtmlStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); - await emailSender.SendAsync(user.Email, subject, htmlMessage); + await emailSender.SendAsync(user.Email, subject, content); // No sense to commit if the email was not sent, as user will not be able to login // and needs to be re-created diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs b/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs index 5cad43c841..bc51c7764a 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs @@ -165,9 +165,9 @@ url is null Email = user.Email, Password = password, }; - var htmlMessage = await renderer.GetHtmlStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); - await emailSender.SendAsync(user.Email, subject, htmlMessage); + await emailSender.SendAsync(user.Email, subject, content); // No sense to commit if the email was not sent, as user will not be able to login // and needs to be re-created diff --git a/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/IRazorViewToStringRenderer.cs b/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/IRazorViewToStringRenderer.cs index 15e75384ec..710f20f6df 100644 --- a/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/IRazorViewToStringRenderer.cs +++ b/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/IRazorViewToStringRenderer.cs @@ -7,20 +7,12 @@ namespace OutOfSchool.RazorTemplatesData.Services; /// public interface IRazorViewToStringRenderer { - /// - /// Get rendered string from an html template. - /// - /// Email template name. - /// Data model. - /// A Rendered an html string. - Task GetHtmlStringAsync(string emailName, TModel model); - - /// - /// Get rendered string from an plain text template. - /// - /// Email template name. - /// Data model. - /// A Rendered an plain text string. - - Task GetPlainTextStringAsync(string emailName, TModel model); + /// + /// Get rendered string from an HTML and plain text template. + /// + /// + /// + /// + /// A rendered an HTML and plain text tuple strings. + Task<(string, string)> GetHtmlPlainStringAsync(string emailName, TModel model); } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/RazorViewToStringRenderer.cs b/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/RazorViewToStringRenderer.cs index c70879fb00..108de32b6e 100644 --- a/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/RazorViewToStringRenderer.cs +++ b/OutOfSchool/OutOfSchool.RazorTemplatesData/Services/RazorViewToStringRenderer.cs @@ -31,19 +31,15 @@ public RazorViewToStringRenderer( } /// - public async Task GetHtmlStringAsync(string emailName, TModel model) + public async Task<(string, string)> GetHtmlPlainStringAsync(string emailName, TModel model) { - var viewName = RazorTemplates.GetViewName(emailName); - - return await RenderViewToStringAsync(viewName, model); - } - - /// - public async Task GetPlainTextStringAsync(string emailName, TModel model) - { - var viewName = RazorTemplates.GetViewName(emailName, false); - - return await RenderViewToStringAsync(viewName, model); + var viewNameHtml = RazorTemplates.GetViewName(emailName); + var viewNamePlain = RazorTemplates.GetViewName(emailName, false); + var tuple = ( + html: await RenderViewToStringAsync(viewNameHtml, model), + plain: await RenderViewToStringAsync(viewNamePlain, model) + ); + return tuple; } private async Task RenderViewToStringAsync(string viewName, TModel model) diff --git a/OutOfSchool/OutOfSchool.RazorTemplatesData/wwwroot/images/Vector.png b/OutOfSchool/OutOfSchool.RazorTemplatesData/wwwroot/images/Vector.png deleted file mode 100644 index 35bc52d289f4cf44216d435a289367230aab6683..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 468 zcmV;_0W1EAP)pg;MRn>xwMbNuxD4i^Adj;13@8}3A)Vn5lqbp$2HA8BXnF*8=m91 zW?gKw-kBdT=U9_)t=HmsYVG2$qrlft6B9FcW}ahr$9oiyId-j_qk)9untOXeM5C$k zl%Z)(*YJIZMN=B{#=wm+w4m@2evUb7b;A>mW3FX177?4cLTE-McobZs`MS4gZotIw zo!!)NF)^@Fl9c23JMIxWlcKo_QLDxwbka5>VlFef={A0ci9X+R3g!qW_nhm!($iP? z9t)a_Sg#wNnYEm}0?oe^V|!HepgL3LhAsa3KRA%bQgAG|5Ud2(EPOz?GUtLP3T)y9 z%^~#jo(kRs_ks@|_D(ROzM44X;Z%1_?uz`S(S9XH+@sCc@%R%9)pb@tVX*c90000< KMNUMnLSTZS{mG#K From 0cdaf9a50637ffd6bbc49578a71c4d90f9285882 Mon Sep 17 00:00:00 2001 From: Valeriy Baditsa Date: Mon, 1 Aug 2022 13:07:27 +0300 Subject: [PATCH 2/3] Fix styles --- .../Controllers/AccountController.cs | 11 ++++------- .../Services/MinistryAdminService.cs | 2 +- .../Services/ProviderAdminService.cs | 2 +- .../Views/Shared/EmailButton.cshtml | 3 +-- .../Views/Shared/EmailLayout.cshtml | 5 +++-- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs b/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs index fe9bbafece..59ec14202a 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AccountController.cs @@ -123,8 +123,7 @@ public async Task ChangeEmail(ChangeEmailViewModel model) LastName = user.LastName, ActionUrl = HtmlEncoder.Default.Encode(callBackUrl), }; - var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); - + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); await emailSender.SendAsync(email, subject, content); logger.LogInformation($"{path} Confirmation message was sent for User(id) + {userId}."); @@ -195,8 +194,7 @@ public async Task ConfirmEmail() LastName = user.LastName, ActionUrl = HtmlEncoder.Default.Encode(callBackUrl), }; - var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); - + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); await emailSender.SendAsync(email, subject, content); logger.LogInformation($"Confirmation message was sent. User(id): {userId}."); @@ -275,9 +273,8 @@ public async Task ForgotPassword(ForgotPasswordViewModel model) LastName = user.LastName, ActionUrl = callBackUrl, }; - - var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); - + + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.ResetPassword, userActionViewModel); await emailSender.SendAsync(email, subject, content); logger.LogInformation($"{path} Message to change password was sent. User(id): {user.Id}."); diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs b/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs index 7ea26f5a28..25d59c52ff 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Services/MinistryAdminService.cs @@ -145,7 +145,7 @@ await institutionAdminRepository.Create(ministryAdmin) Email = user.Email, Password = password, }; - var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); await emailSender.SendAsync(user.Email, subject, content); diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs b/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs index bc51c7764a..6d1560078e 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Services/ProviderAdminService.cs @@ -165,7 +165,7 @@ url is null Email = user.Email, Password = password, }; - var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); + var content = await renderer.GetHtmlPlainStringAsync(RazorTemplates.NewAdminInvitation, adminInvitationViewModel); await emailSender.SendAsync(user.Email, subject, content); diff --git a/OutOfSchool/OutOfSchool.RazorTemplatesData/Views/Shared/EmailButton.cshtml b/OutOfSchool/OutOfSchool.RazorTemplatesData/Views/Shared/EmailButton.cshtml index df86acac0e..5d9313fe57 100644 --- a/OutOfSchool/OutOfSchool.RazorTemplatesData/Views/Shared/EmailButton.cshtml +++ b/OutOfSchool/OutOfSchool.RazorTemplatesData/Views/Shared/EmailButton.cshtml @@ -1,7 +1,6 @@ @using OutOfSchool.RazorTemplatesData.Models.Shared @model EmailButtonViewModel - +