From 3076f584854e8065b6d285faa77ec3f5c17a099a Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 24 Sep 2023 00:04:44 +0100 Subject: [PATCH] feat: add working privacy policy contact form --- OliverBooth/Controllers/ContactController.cs | 27 ++++++++++++++++++++ OliverBooth/Pages/Contact/Privacy.cshtml | 20 +++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/OliverBooth/Controllers/ContactController.cs b/OliverBooth/Controllers/ContactController.cs index 0f11dc5..4d50ec7 100644 --- a/OliverBooth/Controllers/ContactController.cs +++ b/OliverBooth/Controllers/ContactController.cs @@ -31,6 +31,33 @@ public class ContactController : Controller return RedirectToPage("/Contact/Index"); } + [HttpPost("privacy-policy")] + public async Task HandlePrivacyPolicy() + { + if (!Request.HasFormContentType) + { + return RedirectToPage("/Contact/Privacy"); + } + + IFormCollection form = Request.Form; + StringValues name = form["name"]; + StringValues email = form["email"]; + StringValues subject = form["subject"]; + StringValues message = form["message"]; + StringValues privacyPolicy = form["privacy-policy"]; + + await using SmtpSender sender = CreateSender(); + await sender.WriteEmail + .To("Oliver Booth", _destination.GetValue("PrivacyPolicy")) + .From(name, email) + .Subject($"[{privacyPolicy}] {subject}") + .BodyHtml(message) + .SendAsync(); + + TempData["Success"] = true; + return RedirectToPage("/Contact/Result"); + } + [HttpPost("other")] public async Task HandleMiscellaneous() { diff --git a/OliverBooth/Pages/Contact/Privacy.cshtml b/OliverBooth/Pages/Contact/Privacy.cshtml index 0e05fd7..baf5fc1 100644 --- a/OliverBooth/Pages/Contact/Privacy.cshtml +++ b/OliverBooth/Pages/Contact/Privacy.cshtml @@ -18,21 +18,21 @@ Please outline your concerns in the form below, and I will get back to you as soon as possible.

-
+
- - + +
- - + +
- + + +
- - + +