Пример #1
0
 /// <summary>Submits AkismetComment object into Akismet database.</summary>
 /// <param name="comment">AkismetComment object to submit.</param>
 public void SubmitSpam(AkismetComment comment)
 {
     string value = HttpPost(String.Format(submitSpamUrl, apiKey), CreateData(comment), CharSet);
     #if DEBUG
     Console.WriteLine("SubmitSpam() = {0}.", value);
     #endif
 }
Пример #2
0
        /// <summary>Submits AkismetComment object into Akismet database.</summary>
        /// <param name="comment">AkismetComment object to submit.</param>
        public void SubmitSpam(AkismetComment comment)
        {
            string value = HttpPost(String.Format(submitSpamUrl, apiKey), CreateData(comment), CharSet);

#if DEBUG
            Console.WriteLine("SubmitSpam() = {0}.", value);
#endif
        }
Пример #3
0
        /// <summary>Checks AkismetComment object against Akismet database.</summary>
        /// <param name="comment">AkismetComment object to check.</param>
        /// <returns>'True' if spam, 'False' if not spam.</returns>
        public bool CommentCheck(AkismetComment comment)
        {
            bool value = false;

            value = Convert.ToBoolean(HttpPost(String.Format(commentCheckUrl, apiKey), CreateData(comment), CharSet));

            #if DEBUG
            Console.WriteLine("CommentCheck() = {0}.", value);
            #endif

            return value;
        }
Пример #4
0
        /// <summary>Checks AkismetComment object against Akismet database.</summary>
        /// <param name="comment">AkismetComment object to check.</param>
        /// <returns>'True' if spam, 'False' if not spam.</returns>
        public bool CommentCheck(AkismetComment comment)
        {
            bool value = false;

            value = Convert.ToBoolean(HttpPost(String.Format(commentCheckUrl, apiKey), CreateData(comment), CharSet));

#if DEBUG
            Console.WriteLine("CommentCheck() = {0}.", value);
#endif

            return(value);
        }
Пример #5
0
        /// <summary>Takes an AkismetComment object and returns an (escaped) string of data to POST.</summary>
        /// <param name="comment">AkismetComment object to translate.</param>
        /// <returns>A System.String containing the data to POST to Akismet API.</returns>
        private string CreateData(AkismetComment comment)
        {
            string value = String.Format("blog={0}&user_ip={1}&user_agent={2}&referrer={3}&permalink={4}&comment_type={5}" +
                                         "&comment_author={6}&comment_author_email={7}&comment_author_url={8}&comment_content={9}",
                                         HttpUtility.UrlEncode(comment.Blog),
                                         HttpUtility.UrlEncode(comment.UserIp),
                                         HttpUtility.UrlEncode(comment.UserAgent),
                                         HttpUtility.UrlEncode(comment.Referrer),
                                         HttpUtility.UrlEncode(comment.Permalink),
                                         HttpUtility.UrlEncode(comment.CommentType),
                                         HttpUtility.UrlEncode(comment.CommentAuthor),
                                         HttpUtility.UrlEncode(comment.CommentAuthorEmail),
                                         HttpUtility.UrlEncode(comment.CommentAuthorUrl),
                                         HttpUtility.UrlEncode(comment.CommentContent)
                                         );

            return(value);
        }
Пример #6
0
        public JsonResult ChangeSpamMark(int id)
        {
            Comment comment = CommentServices.FindEntityByIdentity(id);

            //Create a new instance of the Akismet API and verify your key is valid.
            Akismet api = new Akismet(BgResources.Akismet_API_key, Request.Url.AbsoluteUri, HttpContext.Request.UserAgent);

            if (!api.VerifyKey())
            {
                return Json(new { result = "error", text = Resources.AppMessages.AkismetApikeyInvalid });
            }

            //Now create an instance of AkismetComment, populating it with values
            //from the POSTed form collection.
            AkismetComment akismetComment = new AkismetComment
            {
                Blog = Request.Url.Scheme + "://" + Request.Url.Host,
                UserIp =  comment.Ip,
                UserAgent = comment.UserAgent,
                CommentContent = comment.Message,
                CommentType = "comment",
                CommentAuthor = comment.AnonymousUser != null ? comment.AnonymousUser.Username : comment.User.Username,
                CommentAuthorEmail = comment.AnonymousUser != null ? comment.AnonymousUser.Email : comment.User.Email,
                CommentAuthorUrl = comment.AnonymousUser != null ? comment.AnonymousUser.Web : String.Empty
            };

            if (comment.IsSpam)
            {
                comment.IsSpam = false;
                api.SubmitHam(akismetComment);
            }
            else
            {
                comment.IsSpam = true;
                api.SubmitSpam(akismetComment);
            }

            BlogServices.SaveComment(comment);

            return Json(new { result = "ok" });
        }
Пример #7
0
        /// <summary>Takes an AkismetComment object and returns an (escaped) string of data to POST.</summary>
        /// <param name="comment">AkismetComment object to translate.</param>
        /// <returns>A System.String containing the data to POST to Akismet API.</returns>
        private string CreateData(AkismetComment comment)
        {
            string value = String.Format("blog={0}&user_ip={1}&user_agent={2}&referrer={3}&permalink={4}&comment_type={5}" +
                "&comment_author={6}&comment_author_email={7}&comment_author_url={8}&comment_content={9}",
                HttpUtility.UrlEncode(comment.Blog),
                HttpUtility.UrlEncode(comment.UserIp),
                HttpUtility.UrlEncode(comment.UserAgent),
                HttpUtility.UrlEncode(comment.Referrer),
                HttpUtility.UrlEncode(comment.Permalink),
                HttpUtility.UrlEncode(comment.CommentType),
                HttpUtility.UrlEncode(comment.CommentAuthor),
                HttpUtility.UrlEncode(comment.CommentAuthorEmail),
                HttpUtility.UrlEncode(comment.CommentAuthorUrl),
                HttpUtility.UrlEncode(comment.CommentContent)
            );

            return value;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (String.IsNullOrEmpty(BgResources.Akismet_API_key))
            {
                return;
            }

            if (CodeFirstSecurity.IsAuthenticated)
            {
                return;
            }

            //Create a new instance of the Akismet API and verify your key is valid.
            Akismet api = new Akismet(BgResources.Akismet_API_key, filterContext.HttpContext.Request.Url.AbsoluteUri , filterContext.HttpContext.Request.UserAgent);

            if (!api.VerifyKey())
            {
                filterContext.Controller.ViewData.ModelState.AddModelError("akismetkey", Resources.AppMessages.AkismetApikeyInvalid);
                return;
            }

            //Now create an instance of AkismetComment, populating it with values
            //from the POSTed form collection.
            AkismetComment akismetComment = new AkismetComment
            {
                Blog = filterContext.HttpContext.Request.Url.Scheme + "://" + filterContext.HttpContext.Request.Url.Host,
                UserIp = filterContext.HttpContext.Request.UserHostAddress,
                UserAgent = filterContext.HttpContext.Request.UserAgent,
                CommentContent =  filterContext.HttpContext.Request.Unvalidated()[this.CommentField],
                CommentType = "comment",
                CommentAuthor = filterContext.HttpContext.Request[this.AuthorField],
                CommentAuthorEmail = filterContext.HttpContext.Request[this.EmailField],
                CommentAuthorUrl = filterContext.HttpContext.Request[this.WebsiteField]
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            if (api.CommentCheck(akismetComment))
            {
                filterContext.Controller.ViewData.ModelState.AddModelError("isspam", Resources.AppMessages.SpamDetected);
            }

            base.OnActionExecuting(filterContext);
        }