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..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 @@ -214,6 +214,8 @@ "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", + "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 ef5a30a055..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 @@ -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 captcha code doesn't match text on the picture! Please try again."); + throw new UserFriendlyException(_localizer["CaptchaCodeErrorMessage"]); } } @@ -86,7 +95,7 @@ public class SimpleMathsCaptchaGenerator : ISingletonDependency } else { - throw new CaptchaException("The captcha code is missing!"); + throw new UserFriendlyException(_localizer["CaptchaCodeMissingMessage"]); } }