diff --git a/OliverBooth/Controllers/ContactController.cs b/OliverBooth/Controllers/ContactController.cs index 2aa73d7..5dc16e2 100644 --- a/OliverBooth/Controllers/ContactController.cs +++ b/OliverBooth/Controllers/ContactController.cs @@ -39,6 +39,13 @@ public class ContactController : Controller return RedirectToPage("/Contact/Index"); } + if (!ModelState.IsValid) + { + _logger.LogError("Captcha validation failed"); + TempData["Success"] = false; + return RedirectToPage("/Contact/Result"); + } + IFormCollection form = Request.Form; StringValues name = form["name"]; StringValues email = form["email"]; diff --git a/OliverBooth/OliverBooth.csproj b/OliverBooth/OliverBooth.csproj index 6e7d24e..4802bc0 100644 --- a/OliverBooth/OliverBooth.csproj +++ b/OliverBooth/OliverBooth.csproj @@ -9,6 +9,7 @@ + diff --git a/OliverBooth/Pages/Contact/Index.cshtml b/OliverBooth/Pages/Contact/Index.cshtml index 02706e1..14eefe9 100644 --- a/OliverBooth/Pages/Contact/Index.cshtml +++ b/OliverBooth/Pages/Contact/Index.cshtml @@ -33,5 +33,7 @@ + + \ No newline at end of file diff --git a/OliverBooth/Program.cs b/OliverBooth/Program.cs index 76aab4a..beb0140 100644 --- a/OliverBooth/Program.cs +++ b/OliverBooth/Program.cs @@ -1,3 +1,4 @@ +using AspNetCore.ReCaptcha; using Markdig; using OliverBooth.Data.Blog; using OliverBooth.Data.Web; @@ -38,6 +39,7 @@ builder.Services.AddSingleton(); builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); builder.Services.AddControllersWithViews(); builder.Services.AddRouting(options => options.LowercaseUrls = true); +builder.Services.AddReCaptcha(builder.Configuration.GetSection("ReCaptcha")); if (builder.Environment.IsProduction()) {