Skip to content

Commit

Permalink
Merge pull request #15 from BenjaminAbt/feature/updates
Browse files Browse the repository at this point in the history
add updates
  • Loading branch information
BenjaminAbt authored Nov 13, 2024
2 parents abfc287 + 91d7a5f commit f6cea48
Show file tree
Hide file tree
Showing 30 changed files with 228 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trim_trailing_whitespace = true

# C# files
[*.cs]
file_header_template = Copyright © Benjamin Abt 2020-2021, all rights reserved
file_header_template = Copyright © Benjamin Abt 2020-2024, all rights reserved

#### .NET Coding Conventions ####

Expand Down
34 changes: 18 additions & 16 deletions .github/workflows/ci.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
name: NETCore
name: NET

on:
push:
branches:
- main
pull_request:
types: [labeled]
branches:
- main


env:
BuildConfig: Release
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_VERSION: '6.0.101' # https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/6.0/releases.json

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Cancel previous builds in PR
uses: styfle/cancel-workflow-action@0.9.1
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- name: 'Install .NET SDK'
uses: actions/setup-dotnet@v1
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: ./global.json

- name: Restore dependencies
run: dotnet restore

- name: Versioning
- name: Setup Git Versioning
uses: dotnet/nbgv@master
id: nbgv

- name: Version Info
- name: Show Version Info
run: |
echo 'SemVer2: ${{ steps.nbgv.outputs.SemVer2 }}'
- name: Build with dotnet
run: dotnet build
--configuration ${{ env.BuildConfig }}
--no-restore --configuration ${{ env.BuildConfig }}
/p:Version=${{ steps.nbgv.outputs.AssemblyVersion }}

- name: Test with dotnet
run: dotnet test

- name: Pack NuGet
run: dotnet pack
--configuration ${{ env.BuildConfig }}
/p:ContinuousIntegrationBuild=true
/p:Version=${{ steps.nbgv.outputs.NuGetPackageVersion }}

- name: Push to NuGet
run: dotnet nuget push **/*.nupkg
--api-key ${{ secrets.NUGET_DEPLOY_KEY }}
--source https://api.nuget.org/v3/index.json
--no-symbols 1
--no-symbols
--skip-duplicate
3 changes: 2 additions & 1 deletion hcaptchanet.sln → BenjaminAbt.HCaptchaNET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{246E4F1E-C4B3-4180-906C-605E72C69097}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.github\workflows\ci.yml = .github\workflows\ci.yml
.github\workflows\build.yml = .github\workflows\build.yml
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
global.json = global.json
README.md = README.md
version.json = version.json
Expand Down
Binary file added BenjaminAbt.HCaptchaNET.snk
Binary file not shown.
34 changes: 28 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,41 @@
<PackageProjectUrl>https://github.com/BenjaminAbt/hcaptcha</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<DefaultLanguage>en-US</DefaultLanguage>
<NoPackageAnalysis>true</NoPackageAnalysis>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>embedded</DebugType>
<IsPackable>false</IsPackable>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup Label="Env">
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsBenchmarkProject>$(MsBuildProjectName.Contains('Benchmark'))</IsBenchmarkProject>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' != 'true' AND '$(IsBenchmarkProject)' != 'true'">
<GenerateDocumentationFile Condition="'$(Configuration)' == 'Release'">true</GenerateDocumentationFile>
<PropertyGroup Label="Project Defaults">
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="C#">
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)BenjaminAbt.HCaptchaNET.snk</AssemblyOriginatorKeyFile>

<PublicKey>
0024000004800000940000000602000000240000525341310004000001000100a9ba6ecd5a2e4a
a9095322a9baebe05966db4f05bf23df1457fc7b084079d7b320a3b0bcf5bb278d9e66f8f70d7e
3d813aeb6a96baf75ef83033a5e0e5558df774d575599cdafbe6e047522db722b6244860a0d5b3
b3bfbe24c50d698411c5d19e3d3765c9599809e2808ed0d6b2f9129395a95468484eac0815b070
ea5b95dc
</PublicKey>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup Label=".NET Dependencies">
<PackageVersion Include="Refit" Version="7.2.22" />
<PackageVersion Include="Refit.HttpClientFactory" Version="7.2.22" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "6.0.101"
"version": "9.0.100"
}
}
Binary file added public.snk
Binary file not shown.
8 changes: 3 additions & 5 deletions sample/sample.aspnetcore/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Benjamin Abt 2020-2021, all rights reserved
// Copyright © Benjamin Abt 2020-2024, all rights reserved

using Microsoft.AspNetCore.Mvc;

Expand All @@ -13,9 +13,7 @@ public class HomeController : Controller
public IActionResult Index(HCaptchaVerifyResponse hCaptcha) => View(new IndexViewModel(hCaptcha));
}

public class IndexViewModel
public class IndexViewModel(HCaptchaVerifyResponse? response = null)
{
public HCaptchaVerifyResponse? Response { get; }

public IndexViewModel(HCaptchaVerifyResponse? response = null) => Response = response;
public HCaptchaVerifyResponse? Response { get; } = response;
}
19 changes: 15 additions & 4 deletions sample/sample.aspnetcore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
// Copyright © Benjamin Abt 2020-2021, all rights reserved

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
// Copyright © Benjamin Abt 2020-2024, all rights reserved

namespace BenjaminAbt.HCaptcha.Samples.AspNetCore;

/// <summary>
/// The entry point for the application, responsible for setting up and running the web host.
/// </summary>
public class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
/// <param name="args">The command-line arguments passed to the application.</param>
public static void Main(string[] args)
{
// Build and run the host
CreateHostBuilder(args).Build().Run();
}

/// <summary>
/// Creates and configures the <see cref="IHostBuilder"/> for the application.
/// </summary>
/// <param name="args">The command-line arguments passed to the application.</param>
/// <returns>An <see cref="IHostBuilder"/> that configures the web host.</returns>
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
// Use the Startup class for configuring services and middleware
webBuilder.UseStartup<Startup>();
});
}
9 changes: 1 addition & 8 deletions sample/sample.aspnetcore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
Expand All @@ -8,13 +8,6 @@
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"hcaptcha.aspnetcore": {
"commandName": "Project",
"launchBrowser": true,
Expand Down
41 changes: 28 additions & 13 deletions sample/sample.aspnetcore/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
// Copyright © Benjamin Abt 2020-2021, all rights reserved
// Copyright © Benjamin Abt 2020-2024, all rights reserved

using BenjaminAbt.HCaptcha.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace BenjaminAbt.HCaptcha.Samples.AspNetCore;

/// <summary>
/// Configures services and the HTTP request pipeline for the application.
/// </summary>
public class Startup
{
/// <summary>
/// Gets the configuration settings for the application.
/// </summary>
public IConfiguration Configuration { get; }

/// <summary>
/// Initializes a new instance of the <see cref="Startup"/> class.
/// </summary>
/// <param name="configuration">The configuration settings for the application.</param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

/// <summary>
/// Configures services for dependency injection in the application.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to which services are added.</param>
public void ConfigureServices(IServiceCollection services)
{
// HCaptcha
// Add hCaptcha services using the configuration from the "HCaptcha" section
services.AddHCaptcha(Configuration.GetSection("HCaptcha"));

// Mvc
// Add MVC controllers with views and configure the hCaptcha model binder
services.AddControllersWithViews(mvcOptions =>
// add model binder
// Add custom model binder for hCaptcha
mvcOptions.AddHCaptchaModelBinder());
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// <summary>
/// Configures the HTTP request pipeline for the application.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> used to configure the middleware pipeline.</param>
/// <param name="env">The <see cref="IWebHostEnvironment"/> containing information about the hosting environment.</param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
// Use the developer exception page in development
app.UseDeveloperExceptionPage();
}

// Enable routing in the middleware pipeline
app.UseRouting();

app.UseEndpoints(endpoints =>
{
// Mvc
// Map MVC controllers to their respective endpoints
endpoints.MapControllers();
});
}
Expand Down
2 changes: 0 additions & 2 deletions sample/sample.aspnetcore/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
}



<div class="container">
<h1 class="mt-5">hCaptcha Demo</h1>
<form class="card p-2" action="" method="POST">
Expand All @@ -20,7 +19,6 @@
</form>
</div>


@{
var response = Model?.Response;
if (response != null)
Expand Down
1 change: 0 additions & 1 deletion sample/sample.aspnetcore/sample.aspnetcore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>BenjaminAbt.HCaptcha.Samples.AspNetCore</AssemblyName>
<RootNamespace>BenjaminAbt.HCaptcha.Samples.AspNetCore</RootNamespace>
</PropertyGroup>
Expand Down
20 changes: 18 additions & 2 deletions src/HCaptcha.AspNetCore/AuthorEntityBinderProvider.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
// Copyright © Benjamin Abt 2020-2021, all rights reserved
// Copyright © Benjamin Abt 2020-2024, all rights reserved

using System;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;

namespace BenjaminAbt.HCaptcha.AspNetCore;

/// <summary>
/// Provides a model binder for binding an <see cref="HCaptchaVerifyResponse"/> to an action parameter.
/// </summary>
public class AuthorEntityBinderProvider : IModelBinderProvider
{
/// <summary>
/// Returns a model binder for the <see cref="HCaptchaVerifyResponse"/> model type, if applicable.
/// </summary>
/// <param name="context">The context that provides information about the model being bound.</param>
/// <returns>
/// An <see cref="IModelBinder"/> instance if the model type is <see cref="HCaptchaVerifyResponse"/>, otherwise <c>null</c>.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="context"/> is <c>null</c>.
/// </exception>
public IModelBinder? GetBinder(ModelBinderProviderContext context)
{
// Ensure the context is not null
ArgumentNullException.ThrowIfNull(context);

// Check if the model type is HCaptchaVerifyResponse
if (context.Metadata.ModelType == typeof(HCaptchaVerifyResponse))
{
// Return a binder for HCaptchaVerifyResponse
return new BinderTypeModelBinder(typeof(HCaptchaModelBinder));
}

// Return null if no binder is required for the model type
return null;
}
}
Loading

0 comments on commit f6cea48

Please sign in to comment.