Recaptcha for contact and registration page implemented

This commit is contained in:
2022-10-21 14:43:33 -04:00
parent 0160c1d7b5
commit 8fd0796019
10 changed files with 155 additions and 42 deletions
@@ -0,0 +1,30 @@
using System.Linq;
using System.Web;
using System.Web.Http.Results;
using System.Web.Mvc;
using hbehr.recaptcha;
using log4net;
using Umbraco.Web.Mvc;
namespace LeafWeb.WebCms.Controllers
{
public class ValidateRecaptchaAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
if (context != null)
{
//https://github.com/henriqb/ReCaptcha-Asp-Net
//https://stackoverflow.com/questions/58328542/trying-the-samesite-attribute-fix-for-the-google-recaptcha-v2-warning-on-chrome
var userResponse = context.RequestContext.HttpContext.Request.Params["g-recaptcha-response"];
var validCaptcha = userResponse != null && ReCaptcha.ValidateCaptcha(userResponse);
if (!validCaptcha)
{
context.Result = new System.Web.Mvc.RedirectResult("/error");
}
}
base.OnActionExecuting(context);
}
}
}