예제 #1
0
        public bool CheckForSpam(PostComments.Comment comment)
        {
            //Create a new instance of the Akismet API and verify your key is valid.
            string blog = ConfigurationManager.AppSettings["MainUrl"];
            var    api  = new Akismet(akismetKey, blog, comment.UserAgent);

            if (!api.VerifyKey())
            {
                throw new Exception("Akismet API key invalid.");
            }

            var akismetComment = new AkismetComment
            {
                Blog               = blog,
                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));
        }
예제 #2
0
        public void MarkSpam(PostComments.Comment comment)
        {
            //Create a new instance of the Akismet API and verify your key is valid.
            string blog = ConfigurationManager.AppSettings["MainUrl"];
            var    api  = new Akismet(akismetKey, blog, comment.UserAgent);

            if (!api.VerifyKey())
            {
                throw new Exception("Akismet API key invalid.");
            }

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

#if !DEBUG
            api.SubmitSpam(akismetComment);
#endif
        }
예제 #3
0
        public static void MarkSpam(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.SubmitSpam(akismetComment);
#endif
        }
예제 #4
0
        public void Execute()
        {
            var post     = Session.Load <Post>(_postId);
            var comments = Session.Load <PostComments>(_postId);

            var comment = new PostComments.Comment
            {
                Id              = comments.GenerateNewCommentId(),
                Author          = _commentInput.Name,
                Body            = _commentInput.Body,
                CreatedAt       = DateTimeOffset.Now,
                Email           = _commentInput.Email,
                Url             = _commentInput.Url,
                Important       = _requestValues.IsAuthenticated,
                UserAgent       = _requestValues.UserAgent,
                UserHostAddress = _requestValues.UserHostAddress
            };

            comment.IsSpam = new AskimetService(Session).CheckForSpam(comment);

            if (comment.IsSpam)
            {
                comments.Spam.Add(comment);
            }
            else
            {
                post.CommentsCount++;
                comments.Comments.Add(comment);
            }

            SendNewCommentEmail(post, comment);
        }
예제 #5
0
        public static bool CheckForSpam(PostComments.Comment comment)
        {
#if DEBUG
            return(false);
#endif
            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));
        }
예제 #6
0
        public void CanMapFromCommentToNewCommentViewModel()
        {
            var comment = new PostComments.Comment();
            var ex      = Record.Exception(() => comment.MapTo <NewCommentEmailViewModel>());

            Assert.Null(ex);
        }
예제 #7
0
        public static IHtmlString Gravatar(this PostComments.Comment comment, int size)
        {
            var ret = string.Format(@"<img src=""http://www.gravatar.com/avatar.php?gravatar_id={0}&size={1}&default=identicon"" alt=""{2}"" width=""{1}"" height=""{1}"">"
                                    , GetHashedEmail(comment.Email), size, comment.Author);

            return(new NonEncodedHtmlString(ret));
        }
예제 #8
0
        private void ResetNumberOfSpamComments(PostComments.Comment comment)
        {
            if (comment.CommenterId == null)
            {
                return;
            }
            var commenter = RavenSession.Load <Commenter>(comment.CommenterId);

            if (commenter == null)
            {
                return;
            }
            commenter.NumberOfSpamComments = 0;
        }
예제 #9
0
        public override void Execute()
        {
            var post = DocumentSession
                       .Include <Post>(x => x.AuthorId)
                       .Include(x => x.CommentsId)
                       .Load(postId);
            var postAuthor = DocumentSession.Load <User>(post.AuthorId);
            var comments   = DocumentSession.Load <PostComments>(post.CommentsId);

            var comment = new PostComments.Comment
            {
                Id              = comments.GenerateNewCommentId().ToString(),
                Author          = commentInput.Name,
                Body            = commentInput.Body,
                CreatedAt       = DateTimeOffset.Now,
                Email           = commentInput.Email,
                Url             = commentInput.Url,
                Important       = requestValues.IsAuthenticated,                           // TODO: Don't mark as important based on that
                UserAgent       = requestValues.UserAgent,
                UserHostAddress = requestValues.UserHostAddress,
            };

            comment.IsSpam = AkismetService.CheckForSpam(comment);

            var commenter = DocumentSession.GetCommenter(commentInput.CommenterKey) ?? new Commenter {
                Key = commentInput.CommenterKey ?? Guid.Empty
            };

            SetCommenter(commenter, comment);

            if (requestValues.IsAuthenticated == false && comment.IsSpam)
            {
                if (commenter.NumberOfSpamComments > 4)
                {
                    return;
                }

                comments.Spam.Add(comment);
            }
            else
            {
                post.CommentsCount++;
                comments.Comments.Add(comment);
            }

            SendNewCommentEmail(post, comment, postAuthor);
        }
예제 #10
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment)
        {
            var viewModel = comment.MapTo <NewCommentEmailViewModel>();

            viewModel.PostId    = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = post.Title;
            viewModel.BlogName  = Session.Load <BlogConfig>("Blog/Config").Title;

            var subject = string.Format("Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName);

            if (comment.IsSpam)
            {
                subject = "Spam " + subject;
            }

            CommandExecutor.ExcuteLater(new SendEmailCommand(viewModel.Email, subject, "NewComment", viewModel));
        }
예제 #11
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;
        }
예제 #12
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));
        }
예제 #13
0
        public override void Execute()
        {
            var comment = new PostComments.Comment
            {
                Author          = commentInput.Author,
                Approved        = true,
                Content         = commentInput.Body,
                CreatedAt       = DateTimeOffset.UtcNow,
                Email           = commentInput.Email,
                Website         = commentInput.Website,
                UserAgent       = requestValues.UserAgent,
                UserHostAddress = requestValues.UserHostAddress,
                Replies         = new List <PostComments.Comment>(),
            };
            var isSpam = false;         // TODO AkismetService.CheckForSpam(comment);

            var post = DocumentSession.Load <BlogPost>(postId);
            //var postAuthor = DocumentSession.Load<User>(post.AuthorId);
            var comments = DocumentSession.Load <PostComments>(postId + "/comments");

            // TODO if (comments == null)

            if (isSpam)
            {
                comments.Spam.Add(comment);
            }
            else
            {
                if (commentInput.InReplyTo > 0)
                {
                    foreach (var c in comments.Comments)
                    {
                        if (c.Id != commentInput.InReplyTo)
                        {
                            continue;
                        }
                        if (c.Replies == null)
                        {
                            c.Replies = new List <PostComments.Comment>();
                        }
                        c.Replies.Add(comment);
                        break;
                    }
                }
                else
                {
                    comment.Id = comments.GenerateNewCommentId();
                    comments.Comments.Add(comment);
                }
                post.CommentsCount++;
            }


//			if (requestValues.IsAuthenticated == false && comment.IsSpam)
//			{
//				if (commenter.NumberOfSpamComments > 4)
//					return;
//				comments.Spam.Add(comment);
//			}
//			else
//			{
//				post.CommentsCount++;
//				comments.Comments.Add(comment);
//			}
//
//          // Now send out email notifications
//			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));
//		}
        }
예제 #14
0
        public void CanMapFromCommentToNewCommentViewModel()
        {
            var comment = new PostComments.Comment();

            Assert.DoesNotThrow(() => comment.MapTo <NewCommentEmailViewModel>());
        }