From 2420700b703b8f7e1e8d79769ac6e0cf8eb5d570 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 12 Apr 2024 14:57:21 +0800 Subject: [PATCH 1/2] Update to net8 and support hide the badge. --- README.md | 27 ++++++++++++++++++- demo/reCAPTCHA.Demo/Pages/V2_Invisible.cshtml | 3 +-- demo/reCAPTCHA.Demo/Pages/V3.cshtml | 4 +-- demo/reCAPTCHA.Demo/reCAPTCHA.Demo.csproj | 2 +- src/Owl.reCAPTCHA/Owl.reCAPTCHA.csproj | 6 ++--- .../TagHelpers/reCAPTCHAV2ScriptTagHelper.cs | 22 +++++++-------- .../TagHelpers/reCAPTCHAV3ScriptTagHelper.cs | 13 ++++++--- 7 files changed, 53 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 500a09f..e646dcf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Owl.reCAPTCHA -Google reCAPTCHA for ASP NET Core 7.0 (v3 and v2) +Google reCAPTCHA for ASP NET Core (v3 and v2) # Install-Package @@ -30,6 +30,12 @@ services.AddreCAPTCHAV3(x => +@* + Hide-the-recaptcha-badge + https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed + +*@ + + +@* + Hide-the-recaptcha-badge + https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed + +*@ + ``` @@ -146,6 +159,12 @@ services.AddreCAPTCHAV2(x => +@* + Hide-the-recaptcha-badge + https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed + +*@ +
@@ -168,6 +187,12 @@ services.AddreCAPTCHAV2(x => +@* + Hide-the-recaptcha-badge + https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed + +*@ + diff --git a/demo/reCAPTCHA.Demo/Pages/V2_Invisible.cshtml b/demo/reCAPTCHA.Demo/Pages/V2_Invisible.cshtml index 2d71bca..5e0696b 100644 --- a/demo/reCAPTCHA.Demo/Pages/V2_Invisible.cshtml +++ b/demo/reCAPTCHA.Demo/Pages/V2_Invisible.cshtml @@ -13,10 +13,9 @@ } - + - diff --git a/demo/reCAPTCHA.Demo/Pages/V3.cshtml b/demo/reCAPTCHA.Demo/Pages/V3.cshtml index ef1150d..b3f464d 100644 --- a/demo/reCAPTCHA.Demo/Pages/V3.cshtml +++ b/demo/reCAPTCHA.Demo/Pages/V3.cshtml @@ -22,5 +22,5 @@ } - - \ No newline at end of file + + diff --git a/demo/reCAPTCHA.Demo/reCAPTCHA.Demo.csproj b/demo/reCAPTCHA.Demo/reCAPTCHA.Demo.csproj index 1d044be..ba0b783 100644 --- a/demo/reCAPTCHA.Demo/reCAPTCHA.Demo.csproj +++ b/demo/reCAPTCHA.Demo/reCAPTCHA.Demo.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 diff --git a/src/Owl.reCAPTCHA/Owl.reCAPTCHA.csproj b/src/Owl.reCAPTCHA/Owl.reCAPTCHA.csproj index ca5bbea..d6c2529 100644 --- a/src/Owl.reCAPTCHA/Owl.reCAPTCHA.csproj +++ b/src/Owl.reCAPTCHA/Owl.reCAPTCHA.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 Owl.reCAPTCHA Owl.reCAPTCHA maliming @@ -9,12 +9,12 @@ https://github.com/maliming/reCAPTCHA https://github.com/maliming/reCAPTCHA git - 7.0.0 + 8.0.0 true Library true true - 7.0.0 + 8.0.0 diff --git a/src/Owl.reCAPTCHA/v2/TagHelpers/reCAPTCHAV2ScriptTagHelper.cs b/src/Owl.reCAPTCHA/v2/TagHelpers/reCAPTCHAV2ScriptTagHelper.cs index b5860b5..8d49e9f 100644 --- a/src/Owl.reCAPTCHA/v2/TagHelpers/reCAPTCHAV2ScriptTagHelper.cs +++ b/src/Owl.reCAPTCHA/v2/TagHelpers/reCAPTCHAV2ScriptTagHelper.cs @@ -16,11 +16,13 @@ public class reCAPTCHAV2ScriptTagHelper : TagHelper public string Render { get; set; } + public bool HideBadge { get; set; } + private readonly reCAPTCHAOptions _options; private readonly IreCAPTCHALanguageCodeProvider _reCAPTCHALanguageCodeProvider; - public reCAPTCHAV2ScriptTagHelper(IOptionsSnapshot optionsAccessor, + public reCAPTCHAV2ScriptTagHelper(IOptionsSnapshot optionsAccessor, IreCAPTCHALanguageCodeProvider reCaptchaLanguageCodeProvider) { _options = optionsAccessor.Get(reCAPTCHAConsts.V2); @@ -33,8 +35,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output) */ - output.TagName = "script"; - output.TagMode = TagMode.StartTagAndEndTag; + output.TagName = ""; var src = $"{_options.VerifyBaseUrl.RemovePostFix(StringComparison.OrdinalIgnoreCase, "/")}/recaptcha/api.js?" + $"hl={_reCAPTCHALanguageCodeProvider.GetLanguageCode()}"; @@ -47,15 +48,14 @@ public override void Process(TagHelperContext context, TagHelperOutput output) src += $"&render={Render}"; } - output.Attributes.Add(new TagHelperAttribute("src", new HtmlString(src))); + var scriptAsync = ScriptAsync ? "async" : string.Empty; + var scriptDefer = ScriptDefer ? "defer" : string.Empty; - if (ScriptAsync) - { - output.Attributes.Add(new TagHelperAttribute("async")); - } - if (ScriptDefer) + output.Content.SetHtmlContent($""); + + if (HideBadge) { - output.Attributes.Add(new TagHelperAttribute("defer")); + output.PostElement.SetHtmlContent(""); } } -} \ No newline at end of file +} diff --git a/src/Owl.reCAPTCHA/v3/TagHelpers/reCAPTCHAV3ScriptTagHelper.cs b/src/Owl.reCAPTCHA/v3/TagHelpers/reCAPTCHAV3ScriptTagHelper.cs index 96cfa05..3bfcac6 100644 --- a/src/Owl.reCAPTCHA/v3/TagHelpers/reCAPTCHAV3ScriptTagHelper.cs +++ b/src/Owl.reCAPTCHA/v3/TagHelpers/reCAPTCHAV3ScriptTagHelper.cs @@ -8,6 +8,8 @@ namespace Owl.reCAPTCHA.v3.TagHelpers; [HtmlTargetElement("recaptcha-script-v3", TagStructure = TagStructure.WithoutEndTag)] public class reCAPTCHAV3ScriptTagHelper : TagHelper { + public bool HideBadge { get; set; } + private readonly reCAPTCHAOptions _options; private readonly IreCAPTCHALanguageCodeProvider _reCAPTCHALanguageCodeProvider; @@ -24,12 +26,15 @@ public override void Process(TagHelperContext context, TagHelperOutput output) /* */ - - output.TagName = "script"; - output.TagMode = TagMode.StartTagAndEndTag; + output.TagName = ""; var src = $"{_options.VerifyBaseUrl.RemovePostFix(StringComparison.OrdinalIgnoreCase, "/")}/recaptcha/api.js?hl={_reCAPTCHALanguageCodeProvider.GetLanguageCode()}&render={_options.SiteKey}"; - output.Attributes.Add(new TagHelperAttribute("src", new HtmlString(src))); + output.Content.SetHtmlContent($""); + + if (HideBadge) + { + output.PostElement.SetHtmlContent(""); + } } } From 52a01f40dc34324d5fceddf61c06cce62ebb75a1 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 12 Apr 2024 15:01:24 +0800 Subject: [PATCH 2/2] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 4a8d351..8537275 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,12 +8,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 7.0.100 - - name: Build with dotnet - run: dotnet build -c Release - - name: Test with dotnet - run: dotnet test --no-restore + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Build with dotnet + run: dotnet build -c Release + - name: Test with dotnet + run: dotnet test --no-restore