Exemple #1
0
        public virtual CommentCreateResult Comment(IStory forStory, string storyUrl, IUser byUser, string content, bool subscribe, string userIPAddress, string userAgent, string urlReferer, NameValueCollection serverVariables)
        {
            CommentCreateResult result = ValidateComment(forStory, byUser, content, userIPAddress, userAgent);

            if (result == null)
            {
                content = SanitizeHtml(content);

                if (!_settings.AllowPossibleSpamCommentSubmit)
                {
                    result = EnsureNotSpam <CommentCreateResult>(byUser, userIPAddress, userAgent, storyUrl, urlReferer, content, "comment", serverVariables, "Possible spam rejected : {0}, {1}, {2}".FormatWith(storyUrl, forStory.Title, byUser), "Your comment appears to be a spam.");

                    if (result != null)
                    {
                        return(result);
                    }
                }

                using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                {
                    IComment comment = forStory.PostComment(content, SystemTime.Now(), byUser, userIPAddress);

                    if (subscribe)
                    {
                        forStory.SubscribeComment(byUser);
                    }
                    else
                    {
                        forStory.UnsubscribeComment(byUser);
                    }

                    if (_settings.AllowPossibleSpamCommentSubmit && _settings.SendMailWhenPossibleSpamCommentSubmitted)
                    {
                        unitOfWork.Commit();
                        _spamProtection.IsSpam(CreateSpamCheckContent(byUser, userIPAddress, userAgent, storyUrl, urlReferer, content, "comment", serverVariables), (source, isSpam) => _spamPostprocessor.Process(source, isSpam, storyUrl, comment));
                    }
                    else
                    {
                        _eventAggregator.GetEvent <CommentSubmitEvent>().Publish(new CommentSubmitEventArgs(comment, storyUrl));
                        unitOfWork.Commit();
                    }

                    result = new CommentCreateResult();
                }
            }

            return(result);
        }
Exemple #2
0
        public virtual CommentCreateResult Comment(IStory forStory, string storyUrl, IUser byUser, string content, bool subscribe, string userIPAddress, string userAgent, string urlReferer, NameValueCollection serverVariables)
        {
            CommentCreateResult result = ValidateComment(forStory, byUser, content, userIPAddress, userAgent);

            if (result == null)
            {
                content = SanitizeHtml(content);

                if (!_settings.AllowPossibleSpamCommentSubmit)
                {
                    result = EnsureNotSpam <CommentCreateResult>(byUser, userIPAddress, userAgent, storyUrl, urlReferer, content, "comment", serverVariables, "Possible spam rejected : {0}, {1}, {2}".FormatWith(storyUrl, forStory.Title, byUser), "Your comment appears to be a spam.");

                    if (result != null)
                    {
                        return(result);
                    }
                }

                IComment comment = forStory.PostComment(content, SystemTime.Now(), byUser, userIPAddress);

                if (subscribe)
                {
                    forStory.SubscribeComment(byUser);
                }
                else
                {
                    forStory.UnsubscribeComment(byUser);
                }

                _userScoreService.StoryCommented(forStory, byUser);

                // Notify the Comment Subscribers that a new comment is posted
                _emailSender.SendComment(storyUrl, comment, forStory.Subscribers);

                if (_settings.AllowPossibleSpamCommentSubmit && _settings.SendMailWhenPossibleSpamCommentSubmitted)
                {
                    _spamProtection.IsSpam(CreateSpamCheckContent(byUser, userIPAddress, userAgent, storyUrl, urlReferer, content, "comment", serverVariables), (source, isSpam) => _spamPostprocessor.Process(source, isSpam, storyUrl, comment));
                }

                result = new CommentCreateResult();
            }

            return(result);
        }