Browse Source

Merge pull request #17928 from abpframework/salihozkara/cmskit

Fix the version problem in cms kit
pull/17931/head
maliming 3 years ago
committed by GitHub
parent
commit
e2e2478af4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Directory.Packages.props
  2. 20
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/SimpleMathsCaptchaGenerator.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Volo.CmsKit.Public.Web.csproj

2
Directory.Packages.props

@ -139,7 +139,7 @@
<PackageVersion Include="SharpZipLib" Version="1.4.2" /> <PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Shouldly" Version="4.0.3" /> <PackageVersion Include="Shouldly" Version="4.0.3" />
<PackageVersion Include="SixLabors.ImageSharp" Version="2.1.6" /> <PackageVersion Include="SixLabors.ImageSharp" Version="2.1.6" />
<PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta13" /> <PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0" />
<PackageVersion Include="Slugify.Core" Version="4.0.1" /> <PackageVersion Include="Slugify.Core" Version="4.0.1" />
<PackageVersion Include="Spectre.Console" Version="0.47.0" /> <PackageVersion Include="Spectre.Console" Version="0.47.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.6.122" /> <PackageVersion Include="StackExchange.Redis" Version="2.6.122" />

20
modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/SimpleMathsCaptchaGenerator.cs

@ -116,7 +116,9 @@ public class SimpleMathsCaptchaGenerator : ITransientDependency
var random = new Random(); var random = new Random();
var startWith = (byte)random.Next(5, 10); var startWith = (byte)random.Next(5, 10);
image.Mutate(ctx => ctx.BackgroundColor(Color.Transparent)); image.Mutate(ctx => ctx.BackgroundColor(Color.Transparent));
var fontFamily = SystemFonts.Families.FirstOrDefault(x => x.IsStyleAvailable(options.FontStyle))?.Name ?? SystemFonts.Families.First().Name; var fontFamily = SystemFonts.Families
.FirstOrDefault(x => x.GetAvailableStyles().Contains(options.FontStyle), SystemFonts.Families.First())
.Name;
var font = SystemFonts.CreateFont(fontFamily, options.FontSize, options.FontStyle); var font = SystemFonts.CreateFont(fontFamily, options.FontSize, options.FontStyle);
foreach (var character in stringText) foreach (var character in stringText)
@ -125,7 +127,7 @@ public class SimpleMathsCaptchaGenerator : ITransientDependency
var color = options.TextColor[random.Next(0, options.TextColor.Length)]; var color = options.TextColor[random.Next(0, options.TextColor.Length)];
var location = new PointF(startWith + position, random.Next(6, 13)); var location = new PointF(startWith + position, random.Next(6, 13));
image.Mutate(ctx => ctx.DrawText(text, font, color, location)); image.Mutate(ctx => ctx.DrawText(text, font, color, location));
position += TextMeasurer.Measure(character.ToString(), new RendererOptions(font, location)).Width; position += TextMeasurer.MeasureSize(character.ToString(), new TextOptions(font)).Width;
} }
//add rotation //add rotation
@ -133,7 +135,7 @@ public class SimpleMathsCaptchaGenerator : ITransientDependency
image.Mutate(ctx => ctx.Transform(rotation)); image.Mutate(ctx => ctx.Transform(rotation));
// add the dynamic image to original image // add the dynamic image to original image
var size = (ushort)TextMeasurer.Measure(stringText, new RendererOptions(font)).Width; var size = (ushort)TextMeasurer.MeasureSize(stringText, new TextOptions(font)).Width;
var img = new Image<Rgba32>(size + 15, options.Height); var img = new Image<Rgba32>(size + 15, options.Height);
img.Mutate(ctx => ctx.BackgroundColor(Color.White)); img.Mutate(ctx => ctx.BackgroundColor(Color.White));
@ -146,7 +148,7 @@ public class SimpleMathsCaptchaGenerator : ITransientDependency
var y1 = random.Next(0, img.Height); var y1 = random.Next(0, img.Height);
img.Mutate(ctx => img.Mutate(ctx =>
ctx.DrawLines(options.TextColor[random.Next(0, options.TextColor.Length)], ctx.DrawLine(options.TextColor[random.Next(0, options.TextColor.Length)],
RandomTextGenerator.GenerateNextFloat(options.MinLineThickness, options.MaxLineThickness), RandomTextGenerator.GenerateNextFloat(options.MinLineThickness, options.MaxLineThickness),
new PointF[] { new PointF(x0, y0), new PointF(x1, y1) }) new PointF[] { new PointF(x0, y0), new PointF(x1, y1) })
); );
@ -154,14 +156,14 @@ public class SimpleMathsCaptchaGenerator : ITransientDependency
img.Mutate(ctx => ctx.DrawImage(image, 0.80f)); img.Mutate(ctx => ctx.DrawImage(image, 0.80f));
Parallel.For(0, options.NoiseRate, i => Parallel.For(0, options.NoiseRate, _ =>
{ {
var x0 = random.Next(0, img.Width); var x0 = random.Next(0, img.Width - 1);
var y0 = random.Next(0, img.Height); var y0 = random.Next(0, img.Height - 1);
img.Mutate( img.Mutate(
ctx => ctx ctx => ctx
.DrawLines(options.NoiseRateColor[random.Next(0, options.NoiseRateColor.Length)], .DrawLine(options.NoiseRateColor[random.Next(0, options.NoiseRateColor.Length)],
RandomTextGenerator.GenerateNextFloat(0.5, 1.5), new PointF[] { new Vector2(x0, y0), new Vector2(x0, y0) }) RandomTextGenerator.GenerateNextFloat(0.5, 1.5), new (x0, y0), new (x0 + 0.01f, y0 + 0.01f))
); );
}); });

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/Volo.CmsKit.Public.Web.csproj

@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" /> <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" />
<PackageReference Include="Markdig.Signed" /> <PackageReference Include="Markdig.Signed" />
<PackageReference Include="HtmlSanitizer" /> <PackageReference Include="HtmlSanitizer" />
<PackageReference Include="SixLabors.ImageSharp" VersionOverride="1.0.4"/> <PackageReference Include="SixLabors.ImageSharp"/>
<PackageReference Include="SixLabors.ImageSharp.Drawing" /> <PackageReference Include="SixLabors.ImageSharp.Drawing" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save