public ActionResult Comment(CommentInput input, int id, Guid key) { var post = RavenSession .Include<Post>(x => x.CommentsId) .Load(id); if (post == null || post.IsPublicPost(key) == false) return HttpNotFound(); var comments = RavenSession.Load<PostComments>(post.CommentsId); if (comments == null) return HttpNotFound(); var commenter = RavenSession.GetCommenter(input.CommenterKey); if (commenter == null) { input.CommenterKey = Guid.NewGuid(); } ValidateCommentsAllowed(post, comments); ValidateCaptcha(input, commenter); if (ModelState.IsValid == false) return PostingCommentFailed(post, input, key); TaskExecutor.ExcuteLater(new AddCommentTask(input, Request.MapTo<AddCommentTask.RequestValues>(), id)); CommenterUtil.SetCommenterCookie(Response, input.CommenterKey.MapTo<string>()); return PostingCommentSucceeded(post, input); }
private void ValidateCaptcha(CommentInput input, Commenter commenter) { if (Request.IsAuthenticated || (commenter != null && commenter.IsTrustedCommenter == true)) return; if (RecaptchaValidatorWrapper.Validate(ControllerContext.HttpContext)) return; ModelState.AddModelError("CaptchaNotValid", "You did not type the verification word correctly. Please try again."); }
private ActionResult PostingCommentFailed(Post post, CommentInput input, Guid key) { if (Request.IsAjaxRequest()) return Json(new { Success = false, message = ModelState.FirstErrorMessage() }); var postReference = post.MapTo<PostReference>(); var result = Details(postReference.DomainId, postReference.Slug, key); var model = result as ViewResult; if (model != null) { var viewModel = model.Model as PostViewModel; if (viewModel != null) viewModel.Input = input; } return result; }
private ActionResult PostingCommentSucceeded(Post post, CommentInput input) { const string successMessage = "Your comment will be posted soon. Thanks!"; if (Request.IsAjaxRequest()) return Json(new { Success = true, message = successMessage }); TempData["new-comment"] = input; var postReference = post.MapTo<PostReference>(); return Redirect(Url.Action("Details", new { Id = postReference.DomainId, postReference.Slug, key = post.ShowPostEvenIfPrivate }) + "#comments-form-location"); }
public AddCommentTask(CommentInput commentInput, RequestValues requestValues, int postId) { this.commentInput = commentInput; this.requestValues = requestValues; this.postId = postId; }