Skip to content

Commit 25f8757

Browse files
committed
Use ImplicitUsings / Added MinVer
1 parent 09fa867 commit 25f8757

File tree

9 files changed

+49
-67
lines changed

9 files changed

+49
-67
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# AspNetCore.Honeypot
22

33
It's a simple honeypot implementation for ASP.NET Core to detect bot posts.
4-
5-
https://www.nuget.org/packages/AspNetCore.Honeypot
64

75
[![nuget](https://img.shields.io/nuget/v/AspNetCore.Honeypot.svg)](https://www.nuget.org/packages/AspNetCore.Honeypot)
86

File renamed without changes.

src/AspNetCore.Honeypot/AspNetCore.Honeypot.csproj

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5-
<Nullable>enable</Nullable>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
67
<Authors>usercode</Authors>
78
<Description>Simple honeypot implementation for ASP.NET Core to detect bot posts.</Description>
8-
<Version>1.1.0</Version>
9-
<PublishRepositoryUrl>true</PublishRepositoryUrl>
10-
<PackageProjectUrl>https://github.com/usercode/AspNetCore.Honeypot</PackageProjectUrl>
11-
<PackageIcon>usercode.png</PackageIcon>
12-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13-
<PackageTags>asp.net; honeypot</PackageTags>
14-
<IncludeSymbols>true</IncludeSymbols>
15-
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
9+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
10+
<PackageProjectUrl>https://github.com/usercode/AspNetCore.Honeypot</PackageProjectUrl>
11+
<PackageIcon>logo.png</PackageIcon>
12+
<PackageReadmeFile>readme.md</PackageReadmeFile>
13+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
14+
<PackageTags>asp.net; honeypot</PackageTags>
15+
<IncludeSymbols>true</IncludeSymbols>
16+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1617
</PropertyGroup>
1718

18-
<ItemGroup>
19-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
20-
</ItemGroup>
21-
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
21+
</ItemGroup>
22+
2223
<ItemGroup>
2324
<FrameworkReference Include="Microsoft.AspnetCore.App" />
2425
</ItemGroup>
2526

26-
<ItemGroup>
27-
<None Include="..\usercode.png" Pack="true" PackagePath="" />
28-
</ItemGroup>
29-
27+
<ItemGroup>
28+
<None Include="..\..\logo.png" Pack="true" PackagePath="" />
29+
<None Include="..\..\readme.md" Pack="true" PackagePath="" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<PackageReference Include="MinVer" Version="4.3.0">
34+
<PrivateAssets>all</PrivateAssets>
35+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
36+
</PackageReference>
37+
</ItemGroup>
38+
3039
</Project>

src/AspNetCore.Honeypot/Extensions.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using Microsoft.AspNetCore.Html;
2-
using Microsoft.AspNetCore.Http;
3-
using Microsoft.AspNetCore.Mvc.Rendering;
1+
using Microsoft.AspNetCore.Http;
42
using Microsoft.Extensions.DependencyInjection;
5-
using System;
6-
using System.Linq;
7-
using System.Net.Http;
83

94
namespace AspNetCore.Honeypot;
105

@@ -13,14 +8,19 @@ namespace AspNetCore.Honeypot;
138
/// </summary>
149
public static class Extensions
1510
{
16-
public static IServiceCollection AddHoneypot(this IServiceCollection services)
11+
/// <summary>
12+
/// AddHoneypot
13+
/// </summary>
14+
/// <param name="services"></param>
15+
/// <param name="options"></param>
16+
/// <returns></returns>
17+
public static IServiceCollection AddHoneypot(this IServiceCollection services, Action<HoneypotOptions>? options = null)
1718
{
18-
return AddHoneypot(services, x => { });
19-
}
19+
if (options != null)
20+
{
21+
services.Configure(options);
22+
}
2023

21-
public static IServiceCollection AddHoneypot(this IServiceCollection services, Action<HoneypotOptions> options)
22-
{
23-
services.Configure(options);
2424
services.AddTransient<HoneypotService>();
2525

2626
return services;

src/AspNetCore.Honeypot/HoneypotAttribute.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.Mvc.Filters;
3-
using System;
4-
using System.Collections.Generic;
53
using System.Net;
6-
using System.Net.Http;
7-
using System.Text;
8-
using System.Linq;
9-
using Microsoft.Extensions.DependencyInjection;
10-
using Microsoft.Extensions.Options;
114

125
namespace AspNetCore.Honeypot;
136

src/AspNetCore.Honeypot/HoneypotOptions.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace AspNetCore.Honeypot;
1+
namespace AspNetCore.Honeypot;
62

73
/// <summary>
84
/// HoneypotOptions
@@ -17,22 +13,22 @@ public HoneypotOptions()
1713

1814
public HoneypotOptions(string prefix)
1915
{
20-
EnableFieldCheck = true;
21-
EnableTimeCheck = true;
16+
IsFieldCheckEnabled = true;
17+
IsTimeCheckEnabled = true;
2218
PrefixFieldName = prefix;
2319
TimeFieldName = "_time";
24-
MinTimeDuration = TimeSpan.FromSeconds(2);
20+
MinTimeDuration = TimeSpan.FromSeconds(1);
2521
}
2622

2723
/// <summary>
2824
/// EnableFieldCheck
2925
/// </summary>
30-
public bool EnableFieldCheck { get; set; }
26+
public bool IsFieldCheckEnabled { get; set; }
3127

3228
/// <summary>
3329
/// EnableTimeCheck
3430
/// </summary>
35-
public bool EnableTimeCheck { get; set; }
31+
public bool IsTimeCheckEnabled { get; set; }
3632

3733
/// <summary>
3834
/// PrefixFieldName

src/AspNetCore.Honeypot/HoneypotService.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
using Microsoft.AspNetCore.Html;
2-
using Microsoft.AspNetCore.Http;
3-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.AspNetCore.Http;
42
using Microsoft.Extensions.Options;
53
using Microsoft.Extensions.Primitives;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Text;
104

115
namespace AspNetCore.Honeypot;
126

@@ -38,13 +32,13 @@ public bool IsTrapped(HttpContext httpContext)
3832
{
3933
bool trapped = false;
4034

41-
if (Options.EnableFieldCheck)
35+
if (Options.IsFieldCheckEnabled)
4236
{
4337
//check fields
4438
trapped = httpContext.Request.Form.Any(x => Options.IsFieldName(x.Key) && x.Value.Any(v => string.IsNullOrEmpty(v) == false));
4539
}
4640

47-
if (Options.EnableTimeCheck && trapped == false)
41+
if (Options.IsTimeCheckEnabled && trapped == false)
4842
{
4943
//check time
5044
if (httpContext.Request.Form.TryGetValue(Options.TimeFieldName, out StringValues timeValues))

src/AspNetCore.Honeypot/TagHelpers/HoneypotFieldTagHelper.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc.Rendering;
2-
using Microsoft.AspNetCore.Razor.TagHelpers;
1+
using Microsoft.AspNetCore.Razor.TagHelpers;
32
using Microsoft.Extensions.Options;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Text;
73

84
namespace AspNetCore.Honeypot;
95

src/AspNetCore.Honeypot/TagHelpers/HoneypotTimeTagHelper.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc.Rendering;
2-
using Microsoft.AspNetCore.Razor.TagHelpers;
1+
using Microsoft.AspNetCore.Razor.TagHelpers;
32
using Microsoft.Extensions.Options;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Text;
73

84
namespace AspNetCore.Honeypot;
95

0 commit comments

Comments
 (0)