From de43e96e8cd3c4ca55d2ad14a3938971c471a9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20P=C4=B1=C3=A7akc=C4=B1?= Date: Thu, 16 Feb 2023 15:54:17 +0300 Subject: [PATCH 1/3] Update SimpleMathsCaptchaGenerator.cs --- .../Security/Captcha/SimpleMathsCaptchaGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ef5a30a055..a8b46c51c0 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 @@ -74,7 +74,7 @@ public class SimpleMathsCaptchaGenerator : ISingletonDependency var request = Session[requestId]; if (request.Output.Result != value) { - throw new CaptchaException("The captcha code doesn't match text on the picture! Please try again."); + throw new CaptchaException("The answer you entered for the CAPTCHA was not correct. Please try again."); } } 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 2/3] 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"]); } } From 73a2ea2f5f61bd81c4fa11fee3f1fb060b53c5c3 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:39:56 +0300 Subject: [PATCH 3/3] refactoring --- .../Volo/CmsKit/Localization/Resources/en.json | 3 ++- .../Security/Captcha/CaptchaException.cs | 15 --------------- .../Captcha/SimpleMathsCaptchaGenerator.cs | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/CaptchaException.cs 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 126e084d26..9bb8dd275c 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 @@ -215,6 +215,7 @@ "DeleteBlogPostMessage": "The blog will be deleted. Are you sure?", "CaptchaCode": "Captcha code", "CommentTextRequired": "Comment is required", - "CaptchaCodeErrorMessage" : "The answer you entered for the CAPTCHA was not correct. Please try again" + "CaptchaCodeErrorMessage" : "The answer you entered for the CAPTCHA was not correct. Please try again", + "CaptchaCodeMissingMessage": "The captcha code is missing!" } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/CaptchaException.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/CaptchaException.cs deleted file mode 100644 index 7914e85b02..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Security/Captcha/CaptchaException.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Runtime.Serialization; -using Volo.Abp; - -namespace Volo.CmsKit.Public.Web.Security.Captcha; - -public class CaptchaException : UserFriendlyException -{ - public CaptchaException(string message) : base(message) - { - } - - public CaptchaException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context) - { - } -} \ 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 e30a9d2e5a..220e24f892 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 @@ -95,7 +95,7 @@ public class SimpleMathsCaptchaGenerator : ISingletonDependency } else { - throw new CaptchaException("The captcha code is missing!"); + throw new UserFriendlyException(_localizer["CaptchaCodeMissingMessage"]); } }