Skip to content
Browse files

check anonymous comments for spam

  • Loading branch information...
1 parent f2ccff5 commit 44516b662249f46e43986403116a79c2be3ade71 @bborn committed
Showing with 12 additions and 0 deletions.
  1. +12 −0 app/models/sb_post.rb
View
12 app/models/sb_post.rb
@@ -1,5 +1,8 @@
class SbPost < ActiveRecord::Base
acts_as_activity :user, :if => Proc.new{|record| record.user } #don't record an activity if there's no user
+ include Rakismet::Model
+ rakismet_attrs :author => :username, :comment_type => 'comment', :content => :body, :user_ip => :author_ip
+
belongs_to :forum, :counter_cache => true
belongs_to :user, :counter_cache => true
@@ -23,6 +26,7 @@ class SbPost < ActiveRecord::Base
named_scope :with_query_options, :select => 'sb_posts.*, topics.title as topic_title, forums.name as forum_name', :joins => 'inner join topics on sb_posts.topic_id = topics.id inner join forums on topics.forum_id = forums.id', :order => 'sb_posts.created_at desc'
named_scope :recent, :order => 'sb_posts.created_at'
+ validate :check_spam
def monitor_topic
return unless user
@@ -49,4 +53,12 @@ def to_xml(options = {})
def username
user ? user.login : (author_name.blank? ? :anonymous.l : author_name)
end
+
+ def check_spam
+ if AppConfig.akismet_key && self.spam?
+ self.errors.add_to_base(:comment_spam_error.l)
+ end
+ end
+
+
end

0 comments on commit 44516b6

Please sign in to comment.
Something went wrong with that request. Please try again.