public async Task <ActionResult> Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } // begin recaptcha check const string captchaMessage = ""; var isCaptchaCodeValid = ReCaptchaUtility.GetCaptchaResponse(captchaMessage, Request); if (!isCaptchaCodeValid) { ModelState.AddModelError("", "Incorrect recaptcha answer."); return(View()); } // end recaptcha check try { var user = new WhoaVerseUser { UserName = model.UserName, RegistrationDateTime = DateTime.Now }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, isPersistent : false); // redirect new users to Welcome actionresult return(RedirectToAction("Welcome", "Home")); } AddErrors(result); } catch (Exception) { ModelState.AddModelError(string.Empty, "Something bad happened. You broke Whoaverse."); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Submit([Bind(Include = "Id,Votes,Name,Date,Type,Linkdescription,Title,Rank,MessageContent,Subverse")] Message message) { // abort if model state is invalid if (!ModelState.IsValid) { return(View()); } // save temp values for the view in case submission fails ViewBag.selectedSubverse = message.Subverse; ViewBag.message = message.MessageContent; ViewBag.title = message.Title; ViewBag.linkDescription = message.Linkdescription; // check if user is banned if (Utils.User.IsUserGloballyBanned(message.Name) || Utils.User.IsUserBannedFromSubverse(User.Identity.Name, message.Subverse)) { ViewBag.SelectedSubverse = message.Subverse; return(View("~/Views/Home/Comments.cshtml", message)); } // check if user has reached hourly posting quota for target subverse if (Utils.User.UserHourlyPostingQuotaForSubUsed(User.Identity.Name, message.Subverse)) { ModelState.AddModelError("", "You have reached your hourly submission quota for this subverse."); return(View()); } // check if user has reached daily posting quota for target subverse if (Utils.User.UserDailyPostingQuotaForSubUsed(User.Identity.Name, message.Subverse)) { ModelState.AddModelError("", "You have reached your daily submission quota for this subverse."); return(View()); } // verify recaptcha if user has less than 25 CCP if (Karma.CommentKarma(User.Identity.Name) < 25) { const string captchaMessage = ""; var isCaptchaCodeValid = ReCaptchaUtility.GetCaptchaResponse(captchaMessage, Request); if (!isCaptchaCodeValid) { ModelState.AddModelError("", "Incorrect recaptcha answer."); // TODO // SET PREVENT SPAM DELAY TO 0 return(View()); } } // everything was okay, process incoming submission // abort if model state is invalid if (!ModelState.IsValid) { return(View("Submit")); } // check if subverse exists var targetSubverse = _db.Subverses.Find(message.Subverse.Trim()); if (targetSubverse == null || message.Subverse.Equals("all", StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError(string.Empty, "Sorry, The subverse you are trying to post to does not exist."); return(View("Submit")); } // check if subverse has "authorized_submitters_only" set and dissalow submission if user is not allowed submitter if (targetSubverse.authorized_submitters_only) { if (!Utils.User.IsUserSubverseModerator(User.Identity.Name, targetSubverse.name)) { // user is not a moderator, check if user is an administrator if (!Utils.User.IsUserSubverseAdmin(User.Identity.Name, targetSubverse.name)) { ModelState.AddModelError("", "You are not authorized to submit links or start discussions in this subverse. Please contact subverse moderators for authorization."); return(View("Submit")); } } } // submission is a link post // generate a thumbnail if submission is a direct link to image or video if (message.Type == 2 && message.MessageContent != null && message.Linkdescription != null) { // abort if title contains unicode if (Submissions.ContainsUnicode(message.Linkdescription)) { ModelState.AddModelError(string.Empty, "Sorry, the link description may not contain unicode characters."); return(View("Submit")); } // abort if title less than 10 characters if (message.Linkdescription.Length < 10) { ModelState.AddModelError(string.Empty, "Sorry, the link description may not be less than 10 characters."); return(View("Submit")); } var domain = UrlUtility.GetDomainFromUri(message.MessageContent); // check if target subvere allows submissions from globally banned hostnames if (!targetSubverse.exclude_sitewide_bans) { // check if hostname is banned before accepting submission if (BanningUtility.IsHostnameBanned(domain)) { ModelState.AddModelError(string.Empty, "Sorry, the hostname you are trying to submit is banned."); return(View("Submit")); } } // check if same link was submitted before and deny submission var existingSubmission = _db.Messages.FirstOrDefault(s => s.MessageContent.Equals(message.MessageContent, StringComparison.OrdinalIgnoreCase) && s.Subverse.Equals(message.Subverse, StringComparison.OrdinalIgnoreCase)); // submission is a repost, discard it and inform the user if (existingSubmission != null) { ModelState.AddModelError(string.Empty, "Sorry, this link has already been submitted by someone else."); // todo: offer the option to repost after informing the user about it return(RedirectToRoute( "SubverseComments", new { controller = "Comment", action = "Comments", id = existingSubmission.Id, subversetoshow = existingSubmission.Subverse } )); } // check if user has reached daily crossposting quota if (Utils.User.DailyCrossPostingQuotaUsed(User.Identity.Name, message.MessageContent)) { ModelState.AddModelError("", "You have reached your daily crossposting quota for this URL."); return(View()); } // check if target subverse has thumbnails setting enabled before generating a thumbnail if (targetSubverse.enable_thumbnails) { // try to generate and assign a thumbnail to submission model message.Thumbnail = ThumbGenerator.ThumbnailFromSubmissionModel(message); } // flag the submission as anonymized if it was submitted to a subverse with active anonymized_mode if (targetSubverse.anonymized_mode) { message.Anonymized = true; } else { message.Name = User.Identity.Name; } // accept submission and save it to the database message.Subverse = targetSubverse.name; // grab server timestamp and modify submission timestamp to have posting time instead of "started writing submission" time message.Date = DateTime.Now; message.Likes = 1; _db.Messages.Add(message); // update last submission received date for target subverse targetSubverse.last_submission_received = DateTime.Now; _db.SaveChanges(); } else if (message.Type == 1 && message.Title != null) { // submission is a self post // abort if title contains unicode if (Submissions.ContainsUnicode(message.Title)) { ModelState.AddModelError(string.Empty, "Sorry, the message title may not contain unicode characters."); return(View("Submit")); } // abort if title less than 10 characters if (message.Title.Length < 10) { ModelState.AddModelError(string.Empty, "Sorry, the the message title may not be less than 10 characters."); return(View("Submit")); } // accept submission and save it to the database // trim trailing blanks from subverse name if a user mistakenly types them message.Subverse = targetSubverse.name; // flag the submission as anonymized if it was submitted to a subverse with active anonymized_mode if (targetSubverse.anonymized_mode) { message.Anonymized = true; } else { message.Name = User.Identity.Name; } // grab server timestamp and modify submission timestamp to have posting time instead of "started writing submission" time message.Date = DateTime.Now; message.Likes = 1; _db.Messages.Add(message); // update last submission received date for target subverse targetSubverse.last_submission_received = DateTime.Now; if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave)) { message.MessageContent = ContentProcessor.Instance.Process(message.MessageContent, ProcessingStage.InboundPreSave, message); } _db.SaveChanges(); if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave)) { ContentProcessor.Instance.Process(message.MessageContent, ProcessingStage.InboundPostSave, message); } } return(RedirectToRoute( "SubverseComments", new { controller = "Comment", action = "Comments", id = message.Id, subversetoshow = message.Subverse } )); }