From 9fb8fe7df08f19e8bcd83d874023387d8287dc9b Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Wed, 19 Oct 2011 13:47:59 -0700 Subject: [PATCH] honeypot --- Gemfile.lock | 6 +++--- app/controllers/application_controller.rb | 5 +++++ app/helpers/application_helper.rb | 10 ++++++++-- app/views/devise/registrations/new.html.erb | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 075f929..d3ffc97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,7 +6,7 @@ GIT GIT remote: https://github.com/activescaffold/active_scaffold.git - revision: da126afef3d59bb0b1e8cbefb6af9186e0146275 + revision: 082cf10d1b88c3f2d208480e9841d0468cb8b47f specs: active_scaffold (3.1.5) rails (~> 3.1.0) @@ -94,7 +94,7 @@ GEM i18n (~> 0.4) ffi (1.0.9) fssm (0.2.7) - guard (0.8.6) + guard (0.8.7) thor (~> 0.14.6) guard-rspec (0.4.5) guard (>= 0.4.0) @@ -203,7 +203,7 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.30) - uglifier (1.0.3) + uglifier (1.0.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) warden (1.0.6) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 21df3d9..09f9d75 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base before_filter :authenticate_user! include SentientController protect_from_forgery + before_filter :check_honeypot rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception| flash.now[:error] = exception.message @@ -35,4 +36,8 @@ class ApplicationController < ActionController::Base helper_method :client_remote_ip helper_method :respond_to + def check_honeypot + render :nothing => true if params[Settings.honeypot].present? + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c5a6972..958166c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,8 +24,8 @@ module ApplicationHelper messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join sentence = I18n.t("errors.messages.not_saved", - :count => resource.errors.count, - :resource => resource.class.model_name.human.downcase) + :count => resource.errors.count, + :resource => resource.class.model_name.human.downcase) html = <<-HTML
@@ -37,4 +37,10 @@ module ApplicationHelper html.html_safe end + def honeypot + content_tag('div', :style => 'position: absolute; left: -2000px;') do + text_field_tag("#{Settings.honeypot}", nil, :tabindex => 900) + end + end + end diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index d9ca1cf..5cbad66 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -6,6 +6,8 @@ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> + + <%= honeypot %>
<%= f.label :first_name %>
<%= f.text_field :first_name %>