public ActionResult Index(string name) { var captchaResponse = Request.Form["g-Recaptcha-Response"]; var result = ReCaptchaValidator.IsValid(captchaResponse); if (!result.Success) { if (result.ErrorCodes == null) { result.ErrorCodes = new List <string>() { "NOT_HUMAN" }; } foreach (string err in result.ErrorCodes) { ModelState.AddModelError("", err); } } result.Name = name; return(View(result)); }
protected ReCaptchaValidator ValidateCaptcha(String response, String userIPAddress) { ReCaptchaValidator validator = new ReCaptchaValidator(); validator.Validate(response, userIPAddress); return(validator); }
public async Task <ActionResult> Register(RegisterViewModel model) { string captchaResponse = Request.Form["g-Recaptcha-Response"]; string secretKey = @SettingHelper.Get("Recaptcha Secret Key"); try { var result = ReCaptchaValidator.IsValidAsync(captchaResponse, secretKey); if (result.Success && ModelState.IsValid && SettingHelper.Get("Recaptcha Site Key").HasValue()) { return(await ProcessRegistration("_RegistrationForm", model)); } if (!result.Success) { foreach (string err in result.ErrorCodes) { ModelState.AddModelError("", err); } } } catch (Exception ex) { var msg = ex.Message; } return(View("_RegistrationForm", model)); }
public HomeController(SignInManager <IdentityUser <Guid> > signInManager, PostsManager postsManager, EmailSender emailSender, ParametersManager parametersManager, ReCaptchaValidator reCaptchaValidator) { _signInManager = signInManager; _postsManager = postsManager; _emailSender = emailSender; _parametersManager = parametersManager; _reCaptchaValidator = reCaptchaValidator; }
public IActionResult Select(string normal, string hard, string workSequences, string inputOrganization, string power, string current, string speed, string cos, string problem, string email) { string captchaResponse = HttpContext.Request.Form["g-Recaptcha-Response"]; ReCaptchaValidationResult result = ReCaptchaValidator.IsValid(captchaResponse); if (!result.Success) { return(RedirectToAction("Index")); } _emailService.SendSelect(normal, hard, workSequences, inputOrganization, power, current, speed, cos, problem, email); return(RedirectToAction("SuccessSelect")); }
public PublicController( ISettingService settingService, INotificationService notificationServic, ReferenceData referenceData, ICountryNameCodeResolver countryNameCodeResolver, ReCaptchaValidator reCaptchaValidator) { _notificationService = notificationServic; _settingService = settingService; _referenceData = referenceData; _countryNameCodeResolver = countryNameCodeResolver; _reCaptchaValidator = reCaptchaValidator; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var reCaptchaPrivateKey = ConfigurationManager.AppSettings["reCaptcha_privateKey"]; var reCaptchaResponse = filterContext.HttpContext.Request.Form["g-recaptcha-response"]; var validator = new ReCaptchaValidator(reCaptchaPrivateKey); var validatorResponse = validator.Validate(reCaptchaResponse); if (!validatorResponse.Success) { filterContext.Controller.ViewData.ModelState.AddModelError("ErrorCodes", string.Join(",", validatorResponse.ErrorCodes)); } }
public async Task <IActionResult> Order(string name, string org, string post, string email, string phone, int lineId) { string captchaResponse = HttpContext.Request.Form["g-Recaptcha-Response"]; ReCaptchaValidationResult result = ReCaptchaValidator.IsValid(captchaResponse); if (!result.Success) { return(RedirectToAction("Index")); } ModelLine line = await _modelLineService.GetAsync(p => p.Id == lineId); _emailService.SendOrder(name, org, post, email, phone, line); return(RedirectToAction("SuccessOrder", new { name = line.Name })); }
public async Task <IActionResult> SendConfigurationRefs(string email, string phone, string teSys1FullRef, string teSys1CircuitBreakersRef, string teSys1CoilRef, string teSys1ContactorRef, string teSys2FullRef, string teSys2CircuitBreakersRef, string teSys2CoilRef, string teSys2ContactorRef) { string captchaResponse = HttpContext.Request.Form["g-Recaptcha-Response"]; ReCaptchaValidationResult result = ReCaptchaValidator.IsValid(captchaResponse); if (!result.Success) { return(RedirectToAction("Index")); } _emailService.SendConfigurationRefs(email, phone, teSys1FullRef, teSys1CircuitBreakersRef, teSys1CoilRef, teSys1ContactorRef, teSys2FullRef, teSys2CircuitBreakersRef, teSys2CoilRef, teSys2ContactorRef); return(RedirectToAction("Success")); }
public IActionResult Login(IFormCollection collection, string captcha) { var formUserName = collection["UserName"].ToString(); var formPin = collection["Pin"].ToString(); if (!int.TryParse(formPin, out _)) { return(RedirectToAction("Login", "Login")); } var model = new LoginViewModel { UserName = formUserName, Pin = int.Parse(formPin) }; var validateModel = _bankService.ValidateUserNameAndPin(model); if (validateModel != true) { return(RedirectToAction("Login", "Login")); } HttpContext.Session.SetString("CurrentUserName", model.UserName); HttpContext.Session.SetInt32("CurrentUserPin", model.Pin); // this is response by div id var captchaResponse = Request.Form["g-Recaptcha-Response"]; // here we validate response var result = ReCaptchaValidator.IsValid(captchaResponse); // if captcha failed -- return to login form again if (!result.Success) { return(RedirectToAction("Login", "Login")); } return(RedirectToAction("SuccessLoginScreen", "Login")); }
private bool ValidateGoogleSecret() { var gSecret = _options.Value.GoogleCaptchaSecret; return(ReCaptchaValidator.ValidateCaptcha(Request, gSecret)); }
public async void Validate_IPArgumentNull_ShouldThrowArgumentNullException() { IReCaptchaValidator validator = new ReCaptchaValidator("site_key", "secret_key"); await Assert.ThrowsAsync <ArgumentNullException>(() => validator.Validate("code", null)); }
public async void Validate_CodeArgumentNullOrEmpty_ShouldThrowArgumentException(string code) { IReCaptchaValidator validator = new ReCaptchaValidator("site_key", "secret_key"); await Assert.ThrowsAsync <ArgumentException>(() => validator.Validate(code, IPAddress.Any)); }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> public void ProcessRequest(HttpContext context) { error_p = false; body = ""; redirect = ""; requiredFields = ""; splitFields = ""; foreach (string key in context.Request.Form.AllKeys) { switch (key) { case "submit.x": break; // ignore case "submit.y": break; // ignore case "__from": from = context.Request.Params[key]; if (!EmailSyntaxValidator.Valid(from, true)) { errorList.Add("Error: from email '" + from + "' is invalid. Please go back and enter a valid email address."); error_p = true; } break; case "__subject": subject = context.Request.Params[key]; break; case "__recipient": to = ConfigurationManager.AppSettings[context.Request.Params[key]]; if ((to == null) || (to == "")) { errorList.Add("Error: recipient '" + context.Request.Params[key] + "' is not configured."); error_p = true; } break; case "__redirectto": redirect = context.Request.Params[key]; break; case "__requiredfields": requiredFields = context.Request.Params[key].Trim().Replace(" ", ""); break; case "__splitFields": splitFields = "," + context.Request.Params[key].Replace(" ", "") + ","; break; // Recaptcha fields case "g-recaptcha-response": recaptchaResponseField = context.Request.Form[key]; break; default: if (key.StartsWith("__linebreak")) { body += "\n"; } else { if (!key.StartsWith("__")) { // only send "real" fields if (splitFields.IndexOf(key) == -1) { body += key.Replace("_", " ") + ": " + context.Request.Params[key] + "\n"; } else { // split the field into multiple lines body += key.Replace("_", " ") + ": \n\t\t" + context.Server.UrlDecode(context.Request.Params[key].Replace(",", "\n\t\t")) + "\n"; } } } break; } } if (requiredFields != "") { foreach (string field in requiredFields.Split(',')) { if ((context.Request.Params[field] == null) || (context.Request.Params[field].Trim() == "")) { errorList.Add("Required field missing: " + field); error_p = true; } } } // Verify captcha was submitted, and is valid ReCaptchaValidator captcha = ValidateCaptcha(recaptchaResponseField, context.Request.UserHostAddress); if (!captcha.Success) { if (captcha.ErrorCodes == null) { errorList.Add("reCAPTCHA check not completed!"); } else { errorList.AddRange(captcha.ErrorCodes); } error_p = true; } if (!error_p) { try { SendEmail(); } catch (Exception exception) { errorList.Add("Error: " + exception.Message); error_p = true; } if (!error_p && redirect != null) { context.Response.Redirect(redirect); } } if (error_p) { Content = string.Empty; errorList.ForEach(entry => { Content += HtmlEncoder.HtmlEncode(entry) + "<br>\n"; }); context.Response.Write(Content); } }