diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs index 6ae524f0f2..c0eae8650e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs @@ -13,4 +13,8 @@ public class CreateCommentInput public string Text { get; set; } public Guid? RepliedCommentId { get; set; } + + public Guid? CaptchaToken { get; set; } + + public int CaptchaAnswer { get; set; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo.CmsKit.Public.Application.csproj b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo.CmsKit.Public.Application.csproj index 9f6d08fea6..b092c3f511 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo.CmsKit.Public.Application.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo.CmsKit.Public.Application.csproj @@ -1,4 +1,4 @@ - + @@ -9,6 +9,8 @@ + + diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs index ef7e6be9fd..ecd7bb294d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; +using SixLabors.ImageSharp.Formats.Gif; +using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Authorization; using Volo.Abp.Data; @@ -13,6 +15,7 @@ using Volo.Abp.Users; using Volo.CmsKit.Comments; using Volo.CmsKit.Features; using Volo.CmsKit.GlobalFeatures; +using Volo.CmsKit.Public.Application.Security.VoloCaptcha; using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Comments; @@ -26,16 +29,20 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli public IDistributedEventBus DistributedEventBus { get; } protected CommentManager CommentManager { get; } + public SimpleMathsCaptchaGenerator SimpleMathsCaptchaGenerator { get; } + public CommentPublicAppService( ICommentRepository commentRepository, ICmsUserLookupService cmsUserLookupService, IDistributedEventBus distributedEventBus, - CommentManager commentManager) + CommentManager commentManager, + SimpleMathsCaptchaGenerator simpleMathsCaptchaGenerator) { CommentRepository = commentRepository; CmsUserLookupService = cmsUserLookupService; DistributedEventBus = distributedEventBus; CommentManager = commentManager; + SimpleMathsCaptchaGenerator = simpleMathsCaptchaGenerator; } public virtual async Task> GetListAsync(string entityType, string entityId) @@ -51,6 +58,11 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli [Authorize] public virtual async Task CreateAsync(string entityType, string entityId, CreateCommentInput input) { + if (input.RepliedCommentId.HasValue) + { + SimpleMathsCaptchaGenerator.Validate(input.CaptchaToken.Value, input.CaptchaAnswer); + } + var user = await CmsUserLookupService.GetByIdAsync(CurrentUser.GetId()); if (input.RepliedCommentId.HasValue)