public async Task <ActionResult> CreateSubverse([Bind("Name, Title, Description, Type, Sidebar, CreationDate, Owner")] AddSubverse subverseTmpModel) { // abort if model state is invalid if (!ModelState.IsValid) { PreventSpamAttribute.Reset(HttpContext); return(View(subverseTmpModel)); } var title = subverseTmpModel.Title; if (String.IsNullOrEmpty(title)) { title = $"/v/{subverseTmpModel.Name}"; //backwards compatibility, previous code always uses this } var cmd = new CreateSubverseCommand(subverseTmpModel.Name, title, subverseTmpModel.Description, subverseTmpModel.Sidebar).SetUserContext(User); var respones = await cmd.Execute(); if (respones.Success) { return(RedirectToRoute(Models.ROUTE_NAMES.SUBVERSE_INDEX, new { subverse = subverseTmpModel.Name })); } else { PreventSpamAttribute.Reset(HttpContext); ModelState.AddModelError(string.Empty, respones.DebugMessage()); return(View(subverseTmpModel)); } }
public async Task <ActionResult> Reply(MessageReplyViewModel message) { if (!ModelState.IsValid) { PreventSpamAttribute.Reset(HttpContext); if (Request.IsAjaxRequest()) { return(new JsonResult(CommandResponse.FromStatus(Status.Invalid, ModelState.GetFirstErrorMessage()))); } else { return(View()); } } if (message.ID <= 0) { return(RedirectToAction("Sent", "Messages")); } var cmd = new SendMessageReplyCommand(message.ID, message.Body).SetUserContext(User); var response = await cmd.Execute(); return(JsonResult(response)); }
public async Task <ActionResult> ReportContent(ReportContentModel model) { if (ModelState.IsValid) { var cmd = new SaveRuleReportCommand(model.ContentType, model.ID, model.RuleSetID.Value).SetUserContext(User); var result = await cmd.Execute(); return(JsonResult(result)); } else { PreventSpamAttribute.Reset(HttpContext); return(JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); } }
public async Task <ActionResult> Reply(MessageReplyViewModel message) { if (!ModelState.IsValid) { PreventSpamAttribute.Reset(); if (Request.IsAjaxRequest()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ModelState.GetFirstErrorMessage())); } else { return(View()); } } if (message.ID <= 0) { return(RedirectToAction("Sent", "Messages")); } var cmd = new SendMessageReplyCommand(message.ID, message.Body); var response = await cmd.Execute(); if (response.Success) { if (Request.IsAjaxRequest()) { return(new HttpStatusCodeResult(HttpStatusCode.OK)); } else { return(RedirectToAction("Sent", "Messages")); } } else { if (Request.IsAjaxRequest()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, response.Message)); } else { ModelState.AddModelError(string.Empty, response.Message); return(View()); } } }
public async Task <ActionResult> EditComment([FromBody()] CommentEditInput commentModel) { if (ModelState.IsValid) { var cmd = new EditCommentCommand(commentModel.ID, commentModel.Content).SetUserContext(User); var result = await cmd.Execute(); if (!result.Success) { PreventSpamAttribute.Reset(HttpContext); } return(JsonResult(result)); } else { PreventSpamAttribute.Reset(HttpContext); return(JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); } }
public async Task <ActionResult> SubmitComment(CommentInput commentModel) { if (!ModelState.IsValid) { //we want to reset spam filter if the modelstate was not triggered by preventspam PreventSpamAttribute.Reset(HttpContext); return(JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); } else { var cmd = new CreateCommentCommand(commentModel.SubmissionID.Value, commentModel.ParentID, commentModel.Content).SetUserContext(User); var result = await cmd.Execute(); if (result.Success) { //if good return formatted comment if (Request.IsAjaxRequest()) { var comment = result.Response; comment.IsOwner = true; ViewBag.CommentId = comment.ID; //why? ViewBag.rootComment = comment.ParentID == null; //why? return(PartialView("~/Views/Shared/Comments/_SubmissionComment.cshtml", comment)); } else { return(new EmptyResult()); } } else { PreventSpamAttribute.Reset(HttpContext); return(JsonResult(result)); } } }
public async Task <ActionResult> Submit(CreateSubmissionViewModel model) { //set this incase invalid submittal var userData = UserData; model.RequireCaptcha = userData.Information.CommentPoints.Sum < VoatSettings.Instance.MinimumCommentPointsForCaptchaSubmission && VoatSettings.Instance.CaptchaEnabled; // abort if model state is invalid if (!ModelState.IsValid) { PreventSpamAttribute.Reset(this.HttpContext); return(View(model)); } //Check Captcha if (model.RequireCaptcha) { var captchaSuccess = await ReCaptchaUtility.Validate(Request); if (!captchaSuccess) { ModelState.AddModelError(string.Empty, "Incorrect recaptcha answer"); return(View(model)); } } //new pipeline var userSubmission = new Domain.Models.UserSubmission(); userSubmission.IsAdult = model.IsAdult; userSubmission.IsAnonymized = model.IsAnonymized; userSubmission.Subverse = model.Subverse.TrimSafe(); userSubmission.Title = model.Title.StripWhiteSpace(); userSubmission.Content = (model.Type == Domain.Models.SubmissionType.Text ? model.Content.TrimSafe() : null); userSubmission.Url = (model.Type == Domain.Models.SubmissionType.Link ? model.Url.TrimSafe() : null); var q = new CreateSubmissionCommand(userSubmission).SetUserContext(User); var result = await q.Execute(); if (result.Success) { // redirect to comments section of newly posted submission return(RedirectToRoute( "SubverseCommentsWithSort_Short", new { submissionID = result.Response.ID, subverseName = result.Response.Subverse, sort = (string)null } )); } else { //Help formatting issues with unicode. if (model.Title.ContainsUnicode()) { model.Title = model.Title.StripUnicode(); ModelState.AddModelError(String.Empty, "Voat has strip searched your title and removed it's unicode. Please verify you approve of what you see."); } else { ModelState.AddModelError(string.Empty, result.DebugMessage()); } PreventSpamAttribute.Reset(HttpContext); return(View(model)); } }