Browse Source

Added a new controller to web for removing the app layer

pull/15039/head
malik masis 4 years ago
parent
commit
61f0a0f17d
  1. 26
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentWithParameteresInput.cs
  2. 47
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/CmsKitPublicCommentsController.cs
  3. 5
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs
  4. 20
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js

26
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentWithParameteresInput.cs

@ -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; }
}

47
modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/CmsKitPublicCommentsController.cs

@ -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
});
}
}

5
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs

@ -9,8 +9,8 @@ using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Public.Application.Security.VoloCaptcha;
using Volo.CmsKit.Public.Comments;
using Volo.CmsKit.Public.Web.Security.Captcha;
using Volo.CmsKit.Web.Renderers;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting;
@ -129,9 +129,6 @@ public class CommentingViewComponent : AbpViewComponent
public string Captcha { get; set; }
public string CaptchaImageBase64 { get; set; }
}
}

20
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js

@ -127,17 +127,25 @@
formAsObject.repliedCommentId = null;
}
volo.cmsKit.public.comments.commentPublic.create(
$commentArea.attr('data-entity-type'),
$commentArea.attr('data-entity-id'),
{
$.ajax({
type: 'POST',
url: 'CmsKitPublicComments/Validate',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({
entityId: $commentArea.attr('data-entity-id'),
entityType: $commentArea.attr('data-entity-type'),
repliedCommentId: formAsObject.repliedCommentId,
text: formAsObject.commentText,
captchaToken: formAsObject.captchaId,
captchaAnswer: formAsObject.input?.captcha
}),
success: function () {
widgetManager.refresh($widget);
},
error: function (data) {
abp.message.error(data.responseJSON.error.message);
}
).then(function () {
widgetManager.refresh($widget);
});
});
});

Loading…
Cancel
Save