Browse Source

honeypot

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
9fb8fe7df0
  1. 6
      Gemfile.lock
  2. 5
      app/controllers/application_controller.rb
  3. 10
      app/helpers/application_helper.rb
  4. 2
      app/views/devise/registrations/new.html.erb

6
Gemfile.lock

@ -6,7 +6,7 @@ GIT
GIT GIT
remote: https://github.com/activescaffold/active_scaffold.git remote: https://github.com/activescaffold/active_scaffold.git
revision: da126afef3d59bb0b1e8cbefb6af9186e0146275 revision: 082cf10d1b88c3f2d208480e9841d0468cb8b47f
specs: specs:
active_scaffold (3.1.5) active_scaffold (3.1.5)
rails (~> 3.1.0) rails (~> 3.1.0)
@ -94,7 +94,7 @@ GEM
i18n (~> 0.4) i18n (~> 0.4)
ffi (1.0.9) ffi (1.0.9)
fssm (0.2.7) fssm (0.2.7)
guard (0.8.6) guard (0.8.7)
thor (~> 0.14.6) thor (~> 0.14.6)
guard-rspec (0.4.5) guard-rspec (0.4.5)
guard (>= 0.4.0) guard (>= 0.4.0)
@ -203,7 +203,7 @@ GEM
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.30) tzinfo (0.3.30)
uglifier (1.0.3) uglifier (1.0.4)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
warden (1.0.6) warden (1.0.6)

5
app/controllers/application_controller.rb

@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
before_filter :authenticate_user! before_filter :authenticate_user!
include SentientController include SentientController
protect_from_forgery protect_from_forgery
before_filter :check_honeypot
rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception| rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception|
flash.now[:error] = exception.message flash.now[:error] = exception.message
@ -35,4 +36,8 @@ class ApplicationController < ActionController::Base
helper_method :client_remote_ip helper_method :client_remote_ip
helper_method :respond_to helper_method :respond_to
def check_honeypot
render :nothing => true if params[Settings.honeypot].present?
end
end end

10
app/helpers/application_helper.rb

@ -24,8 +24,8 @@ module ApplicationHelper
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t("errors.messages.not_saved", sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count, :count => resource.errors.count,
:resource => resource.class.model_name.human.downcase) :resource => resource.class.model_name.human.downcase)
html = <<-HTML html = <<-HTML
<div id="error_explanation"> <div id="error_explanation">
@ -37,4 +37,10 @@ module ApplicationHelper
html.html_safe html.html_safe
end end
def honeypot
content_tag('div', :style => 'position: absolute; left: -2000px;') do
text_field_tag("#{Settings.honeypot}", nil, :tabindex => 900)
end
end
end end

2
app/views/devise/registrations/new.html.erb

@ -7,6 +7,8 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
<%= honeypot %>
<div><%= f.label :first_name %><br /> <div><%= f.label :first_name %><br />
<%= f.text_field :first_name %></div> <%= f.text_field :first_name %></div>

Loading…
Cancel
Save