Browse Source

refactoring

pull/15727/head
Onur Pıçakcı 4 years ago
parent
commit
5722c53d48
  1. 3
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  2. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/SimpleMathsCaptchaGenerator.cs

3
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -214,6 +214,7 @@
"Feature:TagEnableDescription": "CMS Kit's tag system that allows tagging entities such as BlogPost.", "Feature:TagEnableDescription": "CMS Kit's tag system that allows tagging entities such as BlogPost.",
"DeleteBlogPostMessage": "The blog will be deleted. Are you sure?", "DeleteBlogPostMessage": "The blog will be deleted. Are you sure?",
"CaptchaCode": "Captcha code", "CaptchaCode": "Captcha code",
"CommentTextRequired": "Comment is required" "CommentTextRequired": "Comment is required",
"CaptchaCodeErrorMessage" : "The answer you entered for the CAPTCHA was not correct. Please try again"
} }
} }

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

@ -9,6 +9,9 @@ using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using Volo.Abp;
using Volo.CmsKit.Localization;
using Microsoft.Extensions.Localization;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Color = SixLabors.ImageSharp.Color; using Color = SixLabors.ImageSharp.Color;
using PointF = SixLabors.ImageSharp.PointF; using PointF = SixLabors.ImageSharp.PointF;
@ -17,6 +20,12 @@ namespace Volo.CmsKit.Public.Web.Security.Captcha;
public class SimpleMathsCaptchaGenerator : ISingletonDependency public class SimpleMathsCaptchaGenerator : ISingletonDependency
{ {
private readonly IStringLocalizer<CmsKitResource> _localizer;
public SimpleMathsCaptchaGenerator(IStringLocalizer<CmsKitResource> localizer)
{
_localizer = localizer;
}
private static Dictionary<Guid, CaptchaRequest> Session { get; set; } = new Dictionary<Guid, CaptchaRequest>(); private static Dictionary<Guid, CaptchaRequest> Session { get; set; } = new Dictionary<Guid, CaptchaRequest>();
public CaptchaOutput Generate() public CaptchaOutput Generate()
@ -74,7 +83,7 @@ public class SimpleMathsCaptchaGenerator : ISingletonDependency
var request = Session[requestId]; var request = Session[requestId];
if (request.Output.Result != value) if (request.Output.Result != value)
{ {
throw new CaptchaException("The answer you entered for the CAPTCHA was not correct. Please try again."); throw new UserFriendlyException(_localizer["CaptchaCodeErrorMessage"]);
} }
} }

Loading…
Cancel
Save