Esempio n. 1
0
        public ActionResult Submit(string url, string title, string category, string description, string tags)
        {
            string captchaChallenge = null;
            string captchaResponse  = null;
            bool   captchaEnabled   = !CurrentUser.ShouldHideCaptcha();

            if (captchaEnabled)
            {
                captchaChallenge = HttpContext.Request.Form[CaptchaValidator.ChallengeInputName];
                captchaResponse  = HttpContext.Request.Form[CaptchaValidator.ResponseInputName];
            }

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaChallenge), "Captcha challenge cannot be blank."),
                new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaResponse), "Captcha verification words cannot be blank."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => captchaEnabled && !CaptchaValidator.Validate(CurrentUserIPAddress, captchaChallenge, captchaResponse), "Captcha verification words are incorrect.")
                );

            if (viewData == null)
            {
                try
                {
                    StoryCreateResult result = _storyService.Create(
                        CurrentUser,
                        url.NullSafe(),
                        title.NullSafe(),
                        category.NullSafe(),
                        description.NullSafe(),
                        tags.NullSafe(),
                        CurrentUserIPAddress,
                        HttpContext.Request.UserAgent,
                        ((HttpContext.Request.UrlReferrer != null) ? HttpContext.Request.UrlReferrer.ToString() : null),
                        HttpContext.Request.ServerVariables,
                        story => string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName }))
                        );

                    viewData = new JsonCreateViewData
                    {
                        isSuccessful = string.IsNullOrEmpty(result.ErrorMessage),
                        errorMessage = result.ErrorMessage,
                        url          = result.DetailUrl
                    };
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("submitting story")
                    };
                }
            }

            return(Json(viewData));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(CreateStory createStory)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Board"));
            }

            bool successful = await StoryService.Create(createStory);

            if (!successful)
            {
                return(BadRequest("Could not create Story"));
            }

            return(RedirectToAction("Board", "Board"));
        }
Esempio n. 3
0
        public ActionResult Submit(string url, string title, string category, string description, string tags)
        {
            string captchaChallenge = null;
            string captchaResponse  = null;
            bool   captchaEnabled   = !CurrentUser.ShouldHideCaptcha();

            if (captchaEnabled)
            {
                captchaChallenge = HttpContext.Request.Form[CaptchaValidator.ChallengeInputName];
                captchaResponse  = HttpContext.Request.Form[CaptchaValidator.ResponseInputName];
            }

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaChallenge), "Pole Captcha nie mo¿e byæ puste."),
                new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaResponse), "Pole Captcha nie mo¿e byæ puste."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany"),
                new Validation(() => captchaEnabled && !CaptchaValidator.Validate(CurrentUserIPAddress, captchaChallenge, captchaResponse), "Nieudana weryfikacja Captcha")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        StoryCreateResult result = _storyService.Create(
                            CurrentUser,
                            url.NullSafe(),
                            title.NullSafe(),
                            category.NullSafe(),
                            description.NullSafe(),
                            tags.NullSafe(),
                            CurrentUserIPAddress,
                            HttpContext.Request.UserAgent,
                            ((HttpContext.Request.UrlReferrer != null) ? HttpContext.Request.UrlReferrer.ToString() : null),
                            HttpContext.Request.ServerVariables,
                            story => string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName }))
                            );

                        viewData = new JsonCreateViewData
                        {
                            isSuccessful = string.IsNullOrEmpty(result.ErrorMessage),
                            errorMessage = result.ErrorMessage,
                            url          = result.DetailUrl
                        };

                        unitOfWork.Commit();
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("dodania artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }