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)); }
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; }
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 }
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); }
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."); }
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; }