From c53594185d5a2ac22e73ededdb369c89ccc2b60f Mon Sep 17 00:00:00 2001 From: Stephan van Leeuwen Date: Sat, 20 Jul 2024 16:10:15 +0200 Subject: [PATCH 1/2] Add expired-callback and error-callback to the V2 invisible widget --- .../ReCaptchaGeneratorTests.cs | 11 ++++++++++- AspNetCore.ReCaptcha/ReCaptchaGenerator.cs | 14 +++++++++++--- AspNetCore.ReCaptcha/ReCaptchaHelper.cs | 2 +- AspNetCore.ReCaptcha/ReCaptchaTagHelper.cs | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/AspNetCore.ReCaptcha.Tests/ReCaptchaGeneratorTests.cs b/AspNetCore.ReCaptcha.Tests/ReCaptchaGeneratorTests.cs index b138d02..41be18e 100644 --- a/AspNetCore.ReCaptcha.Tests/ReCaptchaGeneratorTests.cs +++ b/AspNetCore.ReCaptcha.Tests/ReCaptchaGeneratorTests.cs @@ -12,14 +12,19 @@ public void ReCaptchaGeneratorReturnsReCaptchaForV2() var result = ReCaptchaGenerator.ReCaptchaV2(new Uri("https://www.google.com/recaptcha/"), "test", "test", "test", "test", "test", "test", "test", false, "nonce"); Assert.NotNull(result); + Assert.Equal(@"
+", + result.ToHtmlString()); } [Fact] public void ReCaptchaGeneratorReturnsReCaptchaForV2Invisible() { - var result = ReCaptchaGenerator.ReCaptchaV2Invisible(new Uri("https://www.google.com/recaptcha/"), "test", "test", "test", "test", "test", "test"); + var result = ReCaptchaGenerator.ReCaptchaV2Invisible(new Uri("https://www.google.com/recaptcha/"), "test", "test", "test", "test", "test", "test", "test", "test"); Assert.NotNull(result); + Assert.Equal(@" +", result.ToHtmlString()); } [Fact] @@ -28,6 +33,10 @@ public void ReCaptchaGeneratorReturnsReCaptchaForV3() var result = ReCaptchaGenerator.ReCaptchaV3(new Uri("https://www.google.com/recaptcha/"), "test", "test", "test", "test", 1, "nonce"); Assert.NotNull(result); + Assert.Equal( + @" +", + result.ToHtmlString()); } [Theory] diff --git a/AspNetCore.ReCaptcha/ReCaptchaGenerator.cs b/AspNetCore.ReCaptcha/ReCaptchaGenerator.cs index bb9f5f3..2e25e6c 100644 --- a/AspNetCore.ReCaptcha/ReCaptchaGenerator.cs +++ b/AspNetCore.ReCaptcha/ReCaptchaGenerator.cs @@ -67,13 +67,21 @@ public static IHtmlContent ReCaptchaV2(Uri baseUrl, string siteKey, string size, return content; } - public static IHtmlContent ReCaptchaV2Invisible(Uri baseUrl, string siteKey, string text, string className, string language, string callback, string badge) + public static IHtmlContent ReCaptchaV2Invisible(Uri baseUrl, string siteKey, string text, string className, string language, string callback, string errorCallback, string expiredCallback, string badge) { var content = new HtmlContentBuilder(); content.AppendFormat(@"", text); content.AppendLine(); diff --git a/AspNetCore.ReCaptcha/ReCaptchaHelper.cs b/AspNetCore.ReCaptcha/ReCaptchaHelper.cs index 7bab06d..293cf32 100644 --- a/AspNetCore.ReCaptcha/ReCaptchaHelper.cs +++ b/AspNetCore.ReCaptcha/ReCaptchaHelper.cs @@ -136,7 +136,7 @@ public static IHtmlContent ReCaptcha( case ReCaptchaVersion.V2: return ReCaptchaGenerator.ReCaptchaV2(staticSettings.RecaptchaBaseUrl, settings.SiteKey, size, theme, language, callback, errorCallback, expiredCallback, autoTheme, nonce); case ReCaptchaVersion.V2Invisible: - return ReCaptchaGenerator.ReCaptchaV2Invisible(staticSettings.RecaptchaBaseUrl, settings.SiteKey, text, className, language, callback, badge); + return ReCaptchaGenerator.ReCaptchaV2Invisible(staticSettings.RecaptchaBaseUrl, settings.SiteKey, text, className, language, callback, errorCallback, expiredCallback, badge); case ReCaptchaVersion.V3: return ReCaptchaGenerator.ReCaptchaV3(staticSettings.RecaptchaBaseUrl, settings.SiteKey, action, language, callback, ReCaptchaGenerator.GenerateId(helper.ViewContext), nonce); } diff --git a/AspNetCore.ReCaptcha/ReCaptchaTagHelper.cs b/AspNetCore.ReCaptcha/ReCaptchaTagHelper.cs index 939f871..b1a46ac 100644 --- a/AspNetCore.ReCaptcha/ReCaptchaTagHelper.cs +++ b/AspNetCore.ReCaptcha/ReCaptchaTagHelper.cs @@ -57,7 +57,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output) var content = settings.Version switch { - ReCaptchaVersion.V2Invisible => ReCaptchaGenerator.ReCaptchaV2Invisible(settings.RecaptchaBaseUrl, settings.SiteKey, Text, ClassName, Language, Callback, Badge), + ReCaptchaVersion.V2Invisible => ReCaptchaGenerator.ReCaptchaV2Invisible(settings.RecaptchaBaseUrl, settings.SiteKey, Text, ClassName, Language, Callback, ErrorCallback, ExpiredCallback, Badge), ReCaptchaVersion.V3 => ReCaptchaGenerator.ReCaptchaV3(settings.RecaptchaBaseUrl, settings.SiteKey, Action, Language, Callback, ReCaptchaGenerator.GenerateId(ViewContext), Nonce), _ => ReCaptchaGenerator.ReCaptchaV2(settings.RecaptchaBaseUrl, settings.SiteKey, Size, Theme, Language, Callback, ErrorCallback, ExpiredCallback, AutoTheme, Nonce), }; From f8dd5df7d5589c49d1ce8af969f5f7027ddd73b2 Mon Sep 17 00:00:00 2001 From: Stephan van Leeuwen Date: Sat, 20 Jul 2024 16:10:57 +0200 Subject: [PATCH 2/2] Update version to 1.8.2 --- AspNetCore.ReCaptcha/AspNetCore.ReCaptcha.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AspNetCore.ReCaptcha/AspNetCore.ReCaptcha.csproj b/AspNetCore.ReCaptcha/AspNetCore.ReCaptcha.csproj index ba99d88..a0c2877 100644 --- a/AspNetCore.ReCaptcha/AspNetCore.ReCaptcha.csproj +++ b/AspNetCore.ReCaptcha/AspNetCore.ReCaptcha.csproj @@ -3,7 +3,7 @@ net6.0 AspNetCore.ReCaptcha - 1.8.1 + 1.8.2 Michaelvs97,sleeuwen Google ReCAPTCHA v2/v3 Library for .NET 6 and above Google ReCAPTCHA v2/v3 Library for .NET 6 and above