Esempio n. 1
0
        private void ValidateCreatingComment(Comment comment)
        {
            var catchSpamInComments = Config.Get <AkismetModuleConfig>().ProtectComments;

            if (catchSpamInComments)
            {
                Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule");
                if (!akismetApiClient.VerifyKey())
                {
                    return;
                }

                var newAkismetData = new AkismetData()
                {
                    AkismetDataId = Guid.NewGuid(),
                    ContentItemId = comment.Id,
                    ItemType      = typeof(Comment).FullName,
                    UserIP        = HttpContext.Current.Request.UserHostAddress,
                    UserAgent     = HttpContext.Current.Request.UserAgent,
                    Referrer      = HttpContext.Current.Request.UrlReferrer.OriginalString,
                };

                var newComment = new AkismetComment()
                {
                    Blog               = "http://www.sitefinity.com",
                    CommentContent     = comment.Content,
                    CommentType        = "comment",
                    Referrer           = newAkismetData.Referrer,
                    UserAgent          = newAkismetData.UserAgent,
                    UserIp             = newAkismetData.UserIP,
                    CommentAuthor      = comment.AuthorName,
                    CommentAuthorEmail = comment.Email,
                    CommentAuthorUrl   = comment.Website
                };
                var isSpam = akismetApiClient.CommentCheck(newComment);

                if (isSpam)
                {
                    comment.CommentStatus = CommentStatus.Spam;
                }

                var akismetDbContext = new AkismetEntityContext();
                akismetDbContext.AkismetDataList.Add(newAkismetData);
                akismetDbContext.SaveChanges();
            }
        }
Esempio n. 2
0
        private void ValidateCreatingForumPost(ForumPost post)
        {
            var catchSpamInForums = Config.Get <AkismetModuleConfig>().ProtectForums;

            if (catchSpamInForums)
            {
                Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule");
                if (!akismetApiClient.VerifyKey())
                {
                    return;
                }

                var newAkismetData = new AkismetData()
                {
                    AkismetDataId = Guid.NewGuid(),
                    ContentItemId = post.Id,
                    ItemType      = typeof(ForumPost).FullName,
                    UserIP        = HttpContext.Current.Request.UserHostAddress,
                    UserAgent     = HttpContext.Current.Request.UserAgent,
                    Referrer      = HttpContext.Current.Request.UrlReferrer.OriginalString
                };

                var newForumPost = new AkismetComment()
                {
                    Blog           = "http://www.sitefinity.com",
                    CommentContent = post.Content,
                    CommentType    = "comment",
                    Referrer       = newAkismetData.Referrer,
                    UserAgent      = newAkismetData.UserAgent,
                    UserIp         = newAkismetData.UserIP,
                };
                var isSpam = akismetApiClient.CommentCheck(newForumPost);
                post.IsMarkedSpam = isSpam;
                if (isSpam)
                {
                    post.IsPublished = false;
                }

                var akismetDbContext = new AkismetEntityContext();
                akismetDbContext.AkismetDataList.Add(newAkismetData);
                akismetDbContext.SaveChanges();
            }
        }