mirror of https://github.com/abpframework/abp.git
4 changed files with 88 additions and 10 deletions
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Comments; |
|||
|
|||
namespace Volo.CmsKit.Public.Comments; |
|||
|
|||
[Serializable] |
|||
public class CreateCommentWithParameteresInput |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(CommentConsts), nameof(CommentConsts.MaxTextLength))] |
|||
public string Text { get; set; } |
|||
|
|||
[Required] |
|||
public string EntityType { get; set; } |
|||
|
|||
[Required] |
|||
public string EntityId { get; set; } |
|||
|
|||
public Guid? RepliedCommentId { get; set; } |
|||
|
|||
public Guid? CaptchaToken { get; set; } |
|||
|
|||
public int CaptchaAnswer { get; set; } |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.CmsKit.Comments; |
|||
using Volo.CmsKit.Public.Comments; |
|||
using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting; |
|||
using Volo.CmsKit.Public.Web.Security.Captcha; |
|||
|
|||
namespace Volo.CmsKit.Public.Web.Controllers; |
|||
|
|||
//[Route("cms-kit/public-comments")]
|
|||
public class CmsKitPublicCommentsController : AbpController |
|||
{ |
|||
public ICommentPublicAppService CommentPublicAppService { get; } |
|||
protected CmsKitCommentOptions CmsKitCommentOptions { get; } |
|||
public SimpleMathsCaptchaGenerator SimpleMathsCaptchaGenerator { get; } |
|||
|
|||
public CmsKitPublicCommentsController( |
|||
ICommentPublicAppService commentPublicAppService, |
|||
IOptions<CmsKitCommentOptions> cmsKitCommentOptions, |
|||
SimpleMathsCaptchaGenerator simpleMathsCaptchaGenerator) |
|||
{ |
|||
CommentPublicAppService = commentPublicAppService; |
|||
CmsKitCommentOptions = cmsKitCommentOptions.Value; |
|||
SimpleMathsCaptchaGenerator = simpleMathsCaptchaGenerator; |
|||
} |
|||
|
|||
[HttpPost] |
|||
public async Task ValidateAsync([FromBody] CreateCommentWithParameteresInput input) |
|||
{ |
|||
if (CmsKitCommentOptions.IsRecaptchaEnabled && input.CaptchaToken.HasValue) |
|||
{ |
|||
SimpleMathsCaptchaGenerator.Validate(input.CaptchaToken.Value, input.CaptchaAnswer); |
|||
} |
|||
|
|||
await CommentPublicAppService.CreateAsync(input.EntityType, input.EntityId, |
|||
new CreateCommentInput() |
|||
{ |
|||
Text = input.Text, |
|||
RepliedCommentId = input.RepliedCommentId, |
|||
CaptchaAnswer = input.CaptchaAnswer, |
|||
CaptchaToken = input.CaptchaToken |
|||
}); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue