Exemplo n.º 1
0
        public virtual async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            Session["Dummy"] = "Dummy";             // OWIN External Login hack

            Uri returnUri;

            Uri.TryCreate(returnUrl, UriKind.Absolute, out returnUri);

            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null || returnUri == null)
            {
                return(returnUri != null ? (ActionResult)Redirect(returnUri.AbsoluteUri) : RedirectToRoute("homepage"));
            }

            var claimedIdentifier = loginInfo.Login.ProviderKey + "@" + loginInfo.Login.LoginProvider;
            var commenter         = RavenSession.Query <Commenter>()
                                    .FirstOrDefault(c => c.OpenId == claimedIdentifier) ?? new Commenter
            {
                Key    = Guid.NewGuid(),
                OpenId = claimedIdentifier,
            };

            SetCommenterValuesFromResponse(loginInfo, commenter);

            CommenterUtil.SetCommenterCookie(Response, commenter.Key.MapTo <string>());
            RavenSession.Store(commenter);

            return(Redirect(returnUri.AbsoluteUri));
        }
Exemplo n.º 2
0
        public virtual async Task <ActionResult> Comment(CommentInput input, string id, Guid key)
        {
            if (ModelState.IsValid == false)
            {
                return(RedirectToAction("Details"));
            }

            if (IsIpAddressBlocked())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.PaymentRequired));
            }

            var post = RavenSession
                       .Include <Post>(x => x.CommentsId)
                       .Load("posts/" + 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);
            await 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>());

            OutputCacheManager.RemoveItem(SectionController.NameConst, MVC.Section.ActionNames.List);

            return(PostingCommentSucceeded(post, input));
        }
        public ActionResult Login(string url, string returnUrl)
        {
            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = Request.UrlReferrer != null?Request.UrlReferrer.ToString() : Url.RouteUrl("homepage");
            }

            using (var openIdRelyingParty = new OpenIdRelyingParty())
            {
                var response = openIdRelyingParty.GetResponse();
                if (response == null)
                {
                    return(HandleNullResponse(url, returnUrl));
                }

                switch (response.Status)
                {
                case AuthenticationStatus.Authenticated:
                    var claimedIdentifier = response.ClaimedIdentifier.ToString();
                    var commenter         = RavenSession.Query <Commenter>()
                                            .FirstOrDefault(c => c.OpenId == claimedIdentifier) ?? new Commenter
                    {
                        Key    = Guid.NewGuid(),
                        OpenId = claimedIdentifier,
                    };

                    SetCommenterValuesFromOpenIdResponse(response, commenter);

                    CommenterUtil.SetCommenterCookie(Response, commenter.Key.MapTo <string>());
                    RavenSession.Store(commenter);

                    return(Redirect(returnUrl));

                case AuthenticationStatus.Canceled:
                    TempData["Message"] = "Canceled at provider";
                    return(Redirect(returnUrl));

                case AuthenticationStatus.Failed:
                    TempData["Message"] = response.Exception.Message;
                    return(Redirect(returnUrl));
                }
                return(new EmptyResult());
            }
        }
Exemplo n.º 4
0
        public ActionResult Comment(CommentInput input, int id, Guid showPostEvenIfPrivate)
        {
            var post = RavenSession
                       .Include <Post>(x => x.CommentsId)
                       .Load(id);

            if (post == null || post.IsPublicPost(showPostEvenIfPrivate) == 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, showPostEvenIfPrivate));
            }

            TaskExecutor.ExcuteLater(new AddCommentTask(input, Request.MapTo <AddCommentTask.RequestValues>(), id));

            CommenterUtil.SetCommenterCookie(Response, input.CommenterKey.MapTo <string>());

            return(PostingCommentSucceeded(post));
        }