#20528: Handling reCaptcha timeouts

Work Item: 20528
This commit is contained in:
Sebastien Ros
2014-03-13 18:36:34 -07:00
parent b2be9705c6
commit 5b14195445

View File

@@ -9,6 +9,7 @@ using Orchard.AntiSpam.ViewModels;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.UI.Admin;
namespace Orchard.AntiSpam.Drivers {
@@ -20,10 +21,11 @@ namespace Orchard.AntiSpam.Drivers {
public ReCaptchaPartDriver(IWorkContextAccessor workContextAccessor) {
_workContextAccessor = workContextAccessor;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
protected override DriverResult Editor(ReCaptchaPart part, dynamic shapeHelper) {
var workContext = _workContextAccessor.GetContext();
@@ -65,15 +67,21 @@ namespace Orchard.AntiSpam.Drivers {
if(updater.TryUpdateModel(submitViewModel, String.Empty, null, null)) {
var context = workContext.HttpContext;
var result = ExecuteValidateRequest(
settings.PrivateKey,
context.Request.ServerVariables["REMOTE_ADDR"],
submitViewModel.recaptcha_challenge_field,
submitViewModel.recaptcha_response_field
);
try {
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("The text you entered in the Captcha field does not match the image"));
if (!HandleValidateResponse(context, result)) {
updater.AddModelError("Parts_ReCaptcha_Fields", 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"));
}
}