Skip to content

Commit 0c6924e

Browse files
author
support
committed
Allow to set captcha theme and captcha score
1 parent a8c9155 commit 0c6924e

File tree

7 files changed

+54
-3
lines changed

7 files changed

+54
-3
lines changed

src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/GeneralCommon.TabSecuritySettings.cshtml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
$('#ssReCaptchaPrivateKeypnl').show();
2525
$('#ssReCaptchaVersionpnl').show();
2626
$('#ssCaptchaShowOnVendorReviewPagepnl').show();
27+
$('#ssReCaptchaScorepnl').show();
28+
$('#ssReCaptchaThemepnl').show();
2729
}
2830
else {
2931
$('#ssCaptchaShowOnLoginPagepnl').hide();
@@ -42,6 +44,8 @@
4244
$('#ssReCaptchaPrivateKeypnl').hide();
4345
$('#ssReCaptchaVersionpnl').hide();
4446
$('#ssCaptchaShowOnVendorReviewPagepnl').hide();
47+
$('#ssReCaptchaScorepnl').hide();
48+
$('#ssReCaptchaThemepnl').hide();
4549
}
4650
}
4751
</script>
@@ -261,5 +265,23 @@
261265
<span asp-validation-for="SecuritySettings.ReCaptchaPrivateKey"></span>
262266
</div>
263267
</div>
268+
<div class="form-group" id="ssReCaptchaScorepnl">
269+
<div class="col-8 col-md-4 col-sm-4 text-right">
270+
<admin-label asp-for="SecuritySettings.ReCaptchaScore" class="control-label" />
271+
</div>
272+
<div class="col-4 col-md-8 col-sm-8">
273+
<admin-input asp-for="SecuritySettings.ReCaptchaScore" />
274+
<span asp-validation-for="SecuritySettings.ReCaptchaScore"></span>
275+
</div>
276+
</div>
277+
<div class="form-group" id="ssReCaptchaThemepnl">
278+
<div class="col-8 col-md-4 col-sm-4 text-right">
279+
<admin-label asp-for="SecuritySettings.ReCaptchaTheme" class="control-label" />
280+
</div>
281+
<div class="col-4 col-md-8 col-sm-8">
282+
<admin-input asp-for="SecuritySettings.ReCaptchaTheme" />
283+
<span asp-validation-for="SecuritySettings.ReCaptchaTheme"></span>
284+
</div>
285+
</div>
264286
</div>
265287
</div>

src/Web/Grand.Web.Admin/Mapper/CaptchaSettingsProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public CaptchaSettingsProfile()
2727
.ForMember(dest => dest.ReCaptchaVersion, mo => mo.MapFrom(p => p.ReCaptchaVersion))
2828
.ForMember(dest => dest.ReCaptchaPublicKey, mo => mo.MapFrom(p => p.ReCaptchaPublicKey))
2929
.ForMember(dest => dest.ReCaptchaPrivateKey, mo => mo.MapFrom(p => p.ReCaptchaPrivateKey))
30+
.ForMember(dest => dest.ReCaptchaScore, mo => mo.MapFrom(p => p.ReCaptchaScore))
31+
.ForMember(dest => dest.ReCaptchaTheme, mo => mo.MapFrom(p => p.ReCaptchaTheme))
3032
.ForMember(dest => dest.AvailableReCaptchaVersions, mo => mo.Ignore())
3133
.ForMember(dest => dest.UserFields, mo => mo.Ignore());
3234

src/Web/Grand.Web.Admin/Models/Settings/GeneralCommonSettingsModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,17 @@ public SecuritySettingsModel()
266266
public bool CaptchaShowOnVendorReviewPage { get; set; }
267267

268268
[GrandResourceDisplayName("Admin.Settings.GeneralCommon.reCaptchaPublicKey")]
269-
270269
public string ReCaptchaPublicKey { get; set; }
271270

272271
[GrandResourceDisplayName("Admin.Settings.GeneralCommon.reCaptchaPrivateKey")]
273-
274272
public string ReCaptchaPrivateKey { get; set; }
275273

274+
[GrandResourceDisplayName("Admin.Settings.GeneralCommon.ReCaptchaTheme")]
275+
public string ReCaptchaTheme { get; set; }
276+
277+
[GrandResourceDisplayName("Admin.Settings.GeneralCommon.ReCaptchaScore")]
278+
public decimal ReCaptchaScore { get; set; }
279+
276280
[GrandResourceDisplayName("Admin.Settings.GeneralCommon.reCaptchaVersion")]
277281
public GoogleReCaptchaVersion ReCaptchaVersion { get; set; }
278282
public IList<SelectListItem> AvailableReCaptchaVersions { get; set; }

src/Web/Grand.Web.Common/Security/Captcha/CaptchaSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public class CaptchaSettings : ISettings
7878
/// </summary>
7979
public string ReCaptchaTheme { get; set; }
8080
/// <summary>
81+
/// reCAPTCHA score
82+
/// </summary>
83+
public decimal ReCaptchaScore { get; set; }
84+
/// <summary>
8185
/// reCAPTCHA version
8286
/// </summary>
8387
public GoogleReCaptchaVersion ReCaptchaVersion { get; set; }

src/Web/Grand.Web.Common/Security/Captcha/GoogleReCaptchaValidator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ private GoogleReCaptchaResponse ParseResponseResult(string responseString)
4949
var result = new GoogleReCaptchaResponse();
5050

5151
var resultObject = JObject.Parse(responseString);
52-
result.IsValid = resultObject.Value<bool>("success");
52+
var success = resultObject.Value<bool>("success");
53+
if(_captchaSettings.ReCaptchaVersion == GoogleReCaptchaVersion.V3)
54+
{
55+
decimal score = resultObject.Value<decimal>("score");
56+
if (_captchaSettings.ReCaptchaScore > 0)
57+
success = success && score >= _captchaSettings.ReCaptchaScore;
58+
}
59+
result.IsValid = success;
5360

5461
if (resultObject.Value<JToken>("error-codes") != null &&
5562
resultObject.Value<JToken>("error-codes").Values<string>().Any())

src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11430,6 +11430,12 @@
1143011430
<Resource Name="Admin.Settings.GeneralCommon.reCaptchaPublicKey">
1143111431
<Value>reCAPTCHA public key</Value>
1143211432
</Resource>
11433+
<Resource Name="Admin.Settings.GeneralCommon.ReCaptchaTheme">
11434+
<Value>Theme for reCAPTCHA (e.g. blackglass, white) </Value>
11435+
</Resource>
11436+
<Resource Name="Admin.Settings.GeneralCommon.ReCaptchaScore">
11437+
<Value>reCAPTCHA v3 Score (1.0 is very likely a very good interaction, 0.0 is very likely a bot)</Value>
11438+
</Resource>
1143311439
<Resource Name="Admin.Settings.GeneralCommon.reCaptchaVersion">
1143411440
<Value>reCAPTCHA version</Value>
1143511441
</Resource>

src/Web/Grand.Web/App_Data/Resources/Upgrade/en_200.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@
4545
<Resource Name="Products.Mpn">
4646
<Value>Manufacturer part number</Value>
4747
</Resource>
48+
<Resource Name="Admin.Settings.GeneralCommon.ReCaptchaTheme">
49+
<Value>Theme for reCAPTCHA (e.g. blackglass, white) </Value>
50+
</Resource>
51+
<Resource Name="Admin.Settings.GeneralCommon.ReCaptchaScore">
52+
<Value>reCAPTCHA v3 Score (1.0 is very likely a very good interaction, 0.0 is very likely a bot)</Value>
53+
</Resource>
4854
</Language>

0 commit comments

Comments
 (0)