public IActionResult OnGet(string link)
        {
            if (link == null)
            {
                return(NotFound());
            }

            var resultLink = _repository.Single(LinkSpecification.ByUrl(link));

            if (resultLink == null)
            {
                return(NotFound());
            }

            var resultTopic = _repository.SingleInclude(BaseSpecification <Topic> .ById(resultLink.TopicId), new List <ISpecification <Topic> > {
                TopicSpecification.IncludeQuestions()
            });

            if (resultTopic == null)
            {
                return(NotFound());
            }

            Questions = resultTopic.Questions;
            Link      = link;
            Title     = resultTopic.Title;

            return(Page());
        }
Beispiel #2
0
        public IActionResult OnGet(string link)
        {
            if (link == null)
            {
                return(NotFound());
            }

            var resultLink = _repository.Single(LinkSpecification.ByUrl(link));

            if (resultLink == null)
            {
                return(NotFound());
            }

            var resultTopic = _repository.Single(BaseSpecification <Topic> .ById(resultLink.TopicId));

            if (resultTopic == null)
            {
                return(NotFound());
            }

            if (resultTopic.PreventSpam)
            {
                ShowReCaptcha = true;
            }

            Title        = resultTopic.Title;
            ShortcutLink = link;
            return(Page());
        }
        private bool IsValidUrl(string generatedUrl)
        {
            var result = _repository.Single(LinkSpecification.ByUrl(generatedUrl));

            return(result == null);
        }
Beispiel #4
0
        public IActionResult OnPost()
        {
            var resultLink = _repository.Single(LinkSpecification.ByUrl(ShortcutLink));

            if (resultLink == null)
            {
                return(NotFound());
            }

            var resultTopic = _repository.SingleInclude(BaseSpecification <Topic> .ById(resultLink.TopicId), new List <ISpecification <Topic> > {
                TopicSpecification.IncludeQuestions()
            });

            if (resultTopic == null)
            {
                return(NotFound());
            }

            if (resultTopic.PreventNSFW)
            {
                if (IsNsfw(Question.Content))
                {
                    ModelState.AddModelError("Question.Content", "Question contains word/s that are considered as NSFW");
                }
            }

            if (resultTopic.PreventSpam)
            {
                if (!ReCaptchaHelper.ValidateRecaptcha(Request.Form["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("Question.Content", "Invalid ReCaptcha");
                }
            }

            switch (resultTopic.DuplicationCheck)
            {
            case DuplicationCheck.IpAddress:
            {
                if (IpAddressExists(WebHelper.GetRemoteIP, resultTopic.Id))
                {
                    ModelState.AddModelError("Question.Content", "You have already asked a question on this poll");
                    break;
                }
                else if (ModelState.IsValid)
                {
                    AddIpAddress(resultTopic.Id);
                }
                break;
            }

            case DuplicationCheck.BrowserCookie:
            {
                const string cookieKey = "PID";
                if (CookieExists(cookieKey, ShortcutLink))
                {
                    ModelState.AddModelError("Question.Content", "You have already asked a question on this poll");
                    break;
                }
                else if (ModelState.IsValid)
                {
                    WebHelper.SetCookie(cookieKey, ShortcutLink, null);
                }
                break;
            }

            case DuplicationCheck.None: break;

            default:
                _logger.LogError($"Unkown duplication check case {resultTopic.DuplicationCheck}.");
                throw new InvalidEnumArgumentException("Unrecognized case value.");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            resultTopic.Questions.Add(Question);

            _repository.Update(resultTopic);

            InterrogateClient.UpdateList(ShortcutLink, Question);

            InterrogateClient.UpdateQuestionCount(ShortcutLink, resultTopic.Questions.Count);

            return(RedirectToPage("Result"));
        }