Skip to content

Commit

Permalink
We need to send the date to Defensio in the right format, and provide…
Browse files Browse the repository at this point in the history
… the IP.
  • Loading branch information
lazyatom committed Aug 14, 2008
1 parent 0e3d61f commit 601e2fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/vanilla/dynasnips/comments.rb
@@ -1,4 +1,6 @@
require 'vanilla/dynasnip'
require 'defensio'
require 'date'

class Comments < Dynasnip
usage %|
Expand Down Expand Up @@ -32,7 +34,9 @@ def post(*args)

return "You need to add some details!" if comment.empty?

unless comment_is_spam?(comment)
if comment_is_spam?(comment)
"Sorry - your comment looks like spam, according to Defensio :("
else
Soup << comment.merge({
:name => "#{snip_name}-comment-#{existing_comments.length + 1}",
:commenting_on => snip_name,
Expand All @@ -58,6 +62,7 @@ def render_comments(comments)
end

def comment_is_spam?(comment)
snip_date = Date.parse(Soup[app.request.params[:snip]].updated_at)
Defensio.configure(YAML.load(File.read('defensio.yml')))
defensio_params = {
:comment_author_email => comment[:email],
Expand All @@ -66,9 +71,10 @@ def comment_is_spam?(comment)
:comment_content => comment[:content],
:comment_type => "comment",
:user_ip => app.request.ip,
:article_date => Soup[app.request.params[:snip]].updated_at
:article_date => snip_date.strftime("%Y/%m/%d")
}
Defensio.audit_comment(defensio_params)["defensio_result"]["spam"]
audit = Defensio.audit_comment(defensio_params)
audit["defensio_result"]["spam"]
end

attribute :comment_template, %{
Expand Down
2 changes: 1 addition & 1 deletion lib/vanilla/request.rb
Expand Up @@ -28,7 +28,7 @@ def cookies
end

def ip
@rack_request.ip
@rack_request.env["REMOTE_ADDR"]
end

private
Expand Down

0 comments on commit 601e2fe

Please sign in to comment.