Exemplo n.º 1
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment, User postAuthor)
        {
            if (requestValues.IsAuthenticated)
                return; // we don't send email for authenticated users

            var viewModel = comment.MapTo<NewCommentEmailViewModel>();
            viewModel.PostId = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = HttpUtility.HtmlDecode(post.Title);
            viewModel.PostSlug = SlugConverter.TitleToSlug(post.Title);
            viewModel.BlogName = DocumentSession.Load<BlogConfig>("Blog/Config").Title;
            viewModel.Key = post.ShowPostEvenIfPrivate.MapTo<string>();

            var subject = string.Format("{2}Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName, comment.IsSpam ? "[Spam] " : string.Empty);

            TaskExecutor.ExcuteLater(new SendEmailTask(viewModel.Email, subject, "NewComment", postAuthor.Email, viewModel));
        }
Exemplo n.º 2
0
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            Models.Post newPost;
            using (var session = MvcApplication.DocumentStore.OpenSession())
            {
                var user = ValidateUser(username, password);
                var comments = new PostComments
                    {
                        Comments = new List<PostComments.Comment>(),
                        Spam = new List<PostComments.Comment>()
                    };
                session.Store(comments);

                var postScheduleringStrategy = new PostSchedulingStrategy(session, DateTimeOffset.Now);
                var publishDate = post.dateCreated == null
                                      ? postScheduleringStrategy.Schedule()
                                      : postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

                newPost = new Models.Post
                    {
                        AuthorId = user.Id,
                        Body = post.description,
                        CommentsId = comments.Id,
                        CreatedAt = DateTimeOffset.Now,
                        SkipAutoReschedule = post.dateCreated != null,
                        PublishAt = publishDate,
                        Tags = post.categories,
                        Title = post.title,
                        CommentsCount = 0,
                        AllowComments = true,
                    };
                session.Store(newPost);
                comments.Post = new PostComments.PostReference
                    {
                        Id = newPost.Id,
                        PublishAt = publishDate
                    };

                session.SaveChanges();
            }

            return newPost.Id;
        }
Exemplo n.º 3
0
        public static void MarkHam(PostComments.Comment comment)
        {
            var api = new Akismet(AkismetKey, BlogUrl, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
                {
                    Blog = BlogUrl,
                    UserIp = comment.UserHostAddress,
                    UserAgent = comment.UserAgent,
                    CommentContent = comment.Body,
                    CommentType = "comment",
                    CommentAuthor = comment.Author,
                    CommentAuthorEmail = comment.Email,
                    CommentAuthorUrl = comment.Url,
                };
            #if !DEBUG
            api.SubmitHam(akismetComment);
            #endif
        }
Exemplo n.º 4
0
        public static bool CheckForSpam(PostComments.Comment comment)
        {
            var api = new Akismet(AkismetKey, BlogUrl, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
                {
                    Blog = BlogUrl,
                    UserIp = comment.UserHostAddress,
                    UserAgent = comment.UserAgent,
                    CommentContent = comment.Body,
                    CommentType = "comment",
                    CommentAuthor = comment.Author,
                    CommentAuthorEmail = comment.Email,
                    CommentAuthorUrl = comment.Url,
                };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return api.CommentCheck(akismetComment);
        }
Exemplo n.º 5
0
 private void ValidateCommentsAllowed(Post post, PostComments comments)
 {
     if (comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments))
         ModelState.AddModelError("CommentsClosed", "This post is closed for new comments.");
     if (post.AllowComments == false)
         ModelState.AddModelError("CommentsClosed", "This post does not allow comments.");
 }
Exemplo n.º 6
0
        private void SetCommenter(Commenter commenter, PostComments.Comment comment)
        {
            if (requestValues.IsAuthenticated)
                return;

            commentInput.MapPropertiesToInstance(commenter);
            commenter.IsTrustedCommenter = comment.IsSpam == false;

            if (comment.IsSpam)
                commenter.NumberOfSpamComments++;

            DocumentSession.Store(commenter);
            comment.CommenterId = commenter.Id;
        }