From 5722c53d48253ea84c0ec07f76e6318be587278b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20P=C4=B1=C3=A7akc=C4=B1?= Date: Fri, 17 Feb 2023 09:11:32 +0300 Subject: [PATCH] refactoring --- .../Volo/CmsKit/Localization/Resources/en.json | 3 ++- .../Security/Captcha/SimpleMathsCaptchaGenerator.cs | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json index d4a32c194f..126e084d26 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json +++ b/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.", "DeleteBlogPostMessage": "The blog will be deleted. Are you sure?", "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" } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/SimpleMathsCaptchaGenerator.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/SimpleMathsCaptchaGenerator.cs index a8b46c51c0..e30a9d2e5a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/SimpleMathsCaptchaGenerator.cs +++ b/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.PixelFormats; using SixLabors.ImageSharp.Processing; +using Volo.Abp; +using Volo.CmsKit.Localization; +using Microsoft.Extensions.Localization; using Volo.Abp.DependencyInjection; using Color = SixLabors.ImageSharp.Color; using PointF = SixLabors.ImageSharp.PointF; @@ -17,6 +20,12 @@ namespace Volo.CmsKit.Public.Web.Security.Captcha; public class SimpleMathsCaptchaGenerator : ISingletonDependency { + private readonly IStringLocalizer _localizer; + + public SimpleMathsCaptchaGenerator(IStringLocalizer localizer) + { + _localizer = localizer; + } private static Dictionary Session { get; set; } = new Dictionary(); public CaptchaOutput Generate() @@ -74,7 +83,7 @@ public class SimpleMathsCaptchaGenerator : ISingletonDependency var request = Session[requestId]; 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"]); } }