mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Cleanup changes as requested by Jetski5822 and sebastienros
This commit is contained in:
@@ -12,17 +12,21 @@ using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.AntiSpam.Drivers {
|
||||
public class ReCaptchaPartDriver : ContentPartDriver<ReCaptchaPart> {
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IJsonConverter _jsonConverter;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private const string ReCaptchaSecureUrl = "https://www.google.com/recaptcha/api/siteverify";
|
||||
|
||||
public ReCaptchaPartDriver(
|
||||
INotifier notifier,
|
||||
IJsonConverter jsonConverter,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_notifier = notifier;
|
||||
_jsonConverter = jsonConverter;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -75,16 +79,16 @@ namespace Orchard.AntiSpam.Drivers {
|
||||
context.Request.Form["g-recaptcha-response"]
|
||||
);
|
||||
|
||||
ReCaptchaPartResponseModel responseModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ReCaptchaPartResponseModel>(result);
|
||||
ReCaptchaPartResponseModel responseModel = _jsonConverter.Deserialize<ReCaptchaPartResponseModel>(result);
|
||||
|
||||
if (!responseModel.success) {
|
||||
for (int i = 0; i < responseModel.errorMessage.Length; i++) {
|
||||
if (responseModel.errorMessage[i] == "missing-input-response") {
|
||||
if (!responseModel.Success) {
|
||||
for (int i = 0; i < responseModel.ErrorCodes.Length; i++) {
|
||||
if (responseModel.ErrorCodes[i] == "missing-input-response") {
|
||||
_notifier.Error(T("The Captcha field is required"));
|
||||
}
|
||||
else {
|
||||
_notifier.Error(T("There was an error with the Captcha please try again"));
|
||||
Logger.Information("Error occurred while submitting a reCaptcha: " + responseModel.errorMessage[i]);
|
||||
Logger.Information("Error occurred while submitting a reCaptcha: " + responseModel.ErrorCodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,9 +6,10 @@ namespace Orchard.AntiSpam.ViewModels {
|
||||
}
|
||||
|
||||
public class ReCaptchaPartResponseModel {
|
||||
public bool success { get; set; }
|
||||
[JsonProperty("success")]
|
||||
public string Success { get; set; }
|
||||
|
||||
[JsonProperty("error-codes")]
|
||||
public string[] errorMessage { get; set; }
|
||||
public string[] ErrorCodes { get; set; }
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
@{
|
||||
var publicKey = (string)Model.PublicKey;
|
||||
}
|
||||
@if (!String.IsNullOrWhiteSpace(publicKey)) {
|
||||
@if (!HasText(publicKey)) {
|
||||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||
|
||||
<fieldset>
|
||||
|
@@ -43,9 +43,9 @@ namespace Orchard.DynamicForms.Validators {
|
||||
|
||||
ReCaptchaElementResponseModel responseModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ReCaptchaElementResponseModel>(result);
|
||||
|
||||
if (!responseModel.success) {
|
||||
for (int i = 0; i < responseModel.errorMessage.Length; i++) {
|
||||
if (responseModel.errorMessage[i] == "missing-input-response") {
|
||||
if (!responseModel.Success) {
|
||||
for (int i = 0; i < responseModel.ErrorCodes.Length; i++) {
|
||||
if (responseModel.ErrorCodes[i] == "missing-input-response") {
|
||||
var validationSettings = element.ValidationSettings;
|
||||
var validationMessage = validationSettings.CustomValidationMessage.WithDefault("The Captcha field is required");
|
||||
context.ModelState.AddModelError("g-recaptcha-response", T(validationMessage).Text);
|
||||
@@ -54,7 +54,7 @@ namespace Orchard.DynamicForms.Validators {
|
||||
var validationSettings = element.ValidationSettings;
|
||||
var validationMessage = validationSettings.CustomValidationMessage.WithDefault("There was an error with the Captcha please try again");
|
||||
context.ModelState.AddModelError("g-recaptcha-response", T(validationMessage).Text);
|
||||
Logger.Information("Error occurred while submitting a reCaptcha: " + responseModel.errorMessage[i]);
|
||||
Logger.Information("Error occurred while submitting a reCaptcha: " + responseModel.ErrorCodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Orchard.DynamicForms.ViewModels
|
||||
{
|
||||
namespace Orchard.DynamicForms.ViewModels {
|
||||
public class ReCaptchaElementResponseModel {
|
||||
public bool success { get; set; }
|
||||
[JsonProperty("success")]
|
||||
public bool Success { get; set; }
|
||||
|
||||
[JsonProperty("error-codes")]
|
||||
public string[] errorMessage { get; set; }
|
||||
public string[] ErrorCodes { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user