protected override DriverResult Editor(ReCaptchaPart part, IUpdateModel updater, dynamic shapeHelper) { var submitViewModel = new ReCaptchaPartSubmitViewModel(); if (updater.TryUpdateModel(submitViewModel, String.Empty, null, null)) { var settings = part.TypePartDefinition.Settings.GetModel <ReCaptchaPartSettings>(); var context = _workContextAccessor.GetContext().HttpContext; var result = ExecuteValidateRequest( settings.PrivateKey, context.Request.ServerVariables["REMOTE_ADDR"], submitViewModel.recaptcha_challenge_field, submitViewModel.recaptcha_response_field ); if (!HandleValidateResponse(context, result)) { updater.AddModelError("Parts_ReCaptcha_Fields", T("Incorrect word")); } } return(Editor(part, shapeHelper)); }
protected override DriverResult Editor(ReCaptchaPart part, IUpdateModel updater, dynamic shapeHelper) { var workContext = _workContextAccessor.GetContext(); var settings = workContext.CurrentSite.As <ReCaptchaSettingsPart>(); // don't display the part in the admin if (AdminFilter.IsApplied(workContext.HttpContext.Request.RequestContext)) { return(null); } if (settings.TrustAuthenticatedUsers && workContext.CurrentUser != null) { return(null); } var submitViewModel = new ReCaptchaPartSubmitViewModel(); if (updater.TryUpdateModel(submitViewModel, String.Empty, null, null)) { var context = workContext.HttpContext; try { var result = ExecuteValidateRequest( settings.PrivateKey, context.Request.ServerVariables["REMOTE_ADDR"], submitViewModel.recaptcha_challenge_field, submitViewModel.recaptcha_response_field ); if (!HandleValidateResponse(context, result)) { _notifier.Error(T("The text you entered in the Captcha field does not match the image")); updater.AddModelError("", T("The text you entered in the Captcha field does not match the image")); } } catch (Exception e) { Logger.Error(e, "An unexcepted error occured while submitting a reCaptcha"); updater.AddModelError("Parts_ReCaptcha_Fields", T("There was an error while validating the Captcha image")); } } return(Editor(part, shapeHelper)); }