From 9a3bf18a31d9516b1d58fd58c37d12b996394940 Mon Sep 17 00:00:00 2001 From: nick Date: Fri, 31 Jul 2026 21:36:05 +0100 Subject: [PATCH] Polish facelift forms and clean package warnings --- CatherineLynwood/CatherineLynwood.csproj | 3 +- .../Controllers/HomeController.cs | 32 ++- .../Views/Home/AboutCatherineLynwood.cshtml | 2 +- .../Views/Home/ContactCatherine.cshtml | 10 +- .../Views/Home/SamanthaLynwood.cshtml | 6 +- .../BlogCommentComponent/Default.cshtml | 4 +- CatherineLynwood/wwwroot/css/site.css | 202 ++++++++++++++++++ CatherineLynwood/wwwroot/css/site.min.css | 2 +- 8 files changed, 249 insertions(+), 12 deletions(-) diff --git a/CatherineLynwood/CatherineLynwood.csproj b/CatherineLynwood/CatherineLynwood.csproj index 1805ea7..8acd696 100644 --- a/CatherineLynwood/CatherineLynwood.csproj +++ b/CatherineLynwood/CatherineLynwood.csproj @@ -154,7 +154,7 @@ - + @@ -164,7 +164,6 @@ - diff --git a/CatherineLynwood/Controllers/HomeController.cs b/CatherineLynwood/Controllers/HomeController.cs index 3effcf1..4edd838 100644 --- a/CatherineLynwood/Controllers/HomeController.cs +++ b/CatherineLynwood/Controllers/HomeController.cs @@ -95,8 +95,15 @@ namespace CatherineLynwood.Controllers [Route("contact-catherine")] [HttpPost] + [ValidateAntiForgeryToken] public async Task ContactCatherine(Contact contact) { + if (IsLikelySpamContact(contact)) + { + _logger.LogInformation("Discarded likely spam contact submission."); + return RedirectToAction("ThankYou"); + } + if (ModelState.IsValid) { await _dataAccess.SaveContact(contact, false); @@ -113,6 +120,29 @@ namespace CatherineLynwood.Controllers return View(contact); } + private bool IsLikelySpamContact(Contact contact) + { + var form = Request.HasFormContentType ? Request.Form : null; + var website = form?["Website"].ToString(); + if (!string.IsNullOrWhiteSpace(website)) + { + return true; + } + + if (long.TryParse(form?["ContactStartedAt"].ToString(), out var startedAt)) + { + var elapsedSeconds = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - startedAt; + if (elapsedSeconds >= 0 && elapsedSeconds < 4) + { + return true; + } + } + + var message = contact.Message ?? string.Empty; + var linkCount = System.Text.RegularExpressions.Regex.Matches(message, @"https?://|www\.", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Count; + return linkCount > 2; + } + [Route("feed.xml")] [Route("rss.xml")] [Route("rss")] @@ -338,4 +368,4 @@ namespace CatherineLynwood.Controllers #endregion Private Methods } -} \ No newline at end of file +} diff --git a/CatherineLynwood/Views/Home/AboutCatherineLynwood.cshtml b/CatherineLynwood/Views/Home/AboutCatherineLynwood.cshtml index c76ee7e..9ec30a7 100644 --- a/CatherineLynwood/Views/Home/AboutCatherineLynwood.cshtml +++ b/CatherineLynwood/Views/Home/AboutCatherineLynwood.cshtml @@ -21,7 +21,7 @@ Birmingham-born author of gritty, emotionally truthful fiction about women, survival, family secrets, and the fire people carry after everything else has been stripped away.

-
+
Catherine Lynwood
diff --git a/CatherineLynwood/Views/Home/ContactCatherine.cshtml b/CatherineLynwood/Views/Home/ContactCatherine.cshtml index 7a323cb..7301dfd 100644 --- a/CatherineLynwood/Views/Home/ContactCatherine.cshtml +++ b/CatherineLynwood/Views/Home/ContactCatherine.cshtml @@ -17,7 +17,13 @@
-
+ + @Html.AntiForgeryToken() + +

Contact Catherine

I would love to hear your thoughts regarding my work. Please feel free to contact me and I will try my best to reply as soon as I can.

@@ -75,4 +81,4 @@ } -} \ No newline at end of file +} diff --git a/CatherineLynwood/Views/Home/SamanthaLynwood.cshtml b/CatherineLynwood/Views/Home/SamanthaLynwood.cshtml index bdb9014..e949888 100644 --- a/CatherineLynwood/Views/Home/SamanthaLynwood.cshtml +++ b/CatherineLynwood/Views/Home/SamanthaLynwood.cshtml @@ -31,8 +31,8 @@
-
-