public virtual JsonResult Index(RecaptchaValidationModel model) { //System.Threading.Thread.Sleep(2000); if (!ModelState.IsValid) return Json(ModelState.First(s => s.Value.Errors.Any()).Value.Errors.First().ErrorMessage); Session.RecaptchaValidated(model, Request.AnonymousID); return Json(true); }
public static void RecaptchaValidated(this HttpSessionStateBase session, RecaptchaValidationModel model, string anonymousId) { if (session == null) throw new ArgumentNullException("session"); if (model == null) throw new ArgumentNullException("model"); if (string.IsNullOrWhiteSpace(anonymousId)) throw new ArgumentException("AnonymousID cannot be null or whitespace. Make sure anonymous identification is enabled."); var data = new RecaptchaModelValidated { Challenge = model.recaptcha_challenge_field, Response = model.recaptcha_response_field, AnonymousId = anonymousId, }; var raw = JsonConvert.SerializeObject(data); if (session[Key] != null) session.Remove(Key); session.Add(Key, raw); }