|
|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Volo.Abp;
|
|
|
|
|
using Volo.Abp.AspNetCore.Mvc;
|
|
|
|
|
using Volo.Abp.ObjectMapping;
|
|
|
|
|
using Volo.CmsKit.Comments;
|
|
|
|
|
@ -12,7 +14,7 @@ using Volo.CmsKit.Public.Web.Security.Captcha;
|
|
|
|
|
namespace Volo.CmsKit.Public.Web.Controllers;
|
|
|
|
|
|
|
|
|
|
//[Route("cms-kit/public-comments")]
|
|
|
|
|
public class CmsKitPublicCommentsController : AbpController
|
|
|
|
|
public class CmsKitPublicCommentsController : CmsKitPublicControllerBase
|
|
|
|
|
{
|
|
|
|
|
public ICommentPublicAppService CommentPublicAppService { get; }
|
|
|
|
|
protected CmsKitCommentOptions CmsKitCommentOptions { get; }
|
|
|
|
|
@ -31,12 +33,35 @@ public class CmsKitPublicCommentsController : AbpController
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public virtual async Task ValidateAsync([FromBody] CreateCommentWithParametersInput input)
|
|
|
|
|
{
|
|
|
|
|
if (CmsKitCommentOptions.IsRecaptchaEnabled && input.CaptchaToken.HasValue)
|
|
|
|
|
if (CmsKitCommentOptions.IsRecaptchaEnabled)
|
|
|
|
|
{
|
|
|
|
|
CheckCaptchaTokenNullity(input.CaptchaToken);
|
|
|
|
|
|
|
|
|
|
SimpleMathsCaptchaGenerator.Validate(input.CaptchaToken.Value, input.CaptchaAnswer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dto = ObjectMapper.Map<CreateCommentWithParametersInput, CreateCommentInput> (input);
|
|
|
|
|
await CommentPublicAppService.CreateAsync(input.EntityType, input.EntityId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public virtual async Task UpdateAsync(Guid id, [FromBody] UpdateCommentInput input)
|
|
|
|
|
{
|
|
|
|
|
if (CmsKitCommentOptions.IsRecaptchaEnabled)
|
|
|
|
|
{
|
|
|
|
|
CheckCaptchaTokenNullity(input.CaptchaToken);
|
|
|
|
|
|
|
|
|
|
SimpleMathsCaptchaGenerator.Validate(input.CaptchaToken.Value, input.CaptchaAnswer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await CommentPublicAppService.UpdateAsync(id, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckCaptchaTokenNullity(Guid? captchaToken)
|
|
|
|
|
{
|
|
|
|
|
if (!captchaToken.HasValue)
|
|
|
|
|
{
|
|
|
|
|
throw new UserFriendlyException(L["CaptchaCodeMissingMessage"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|