diff --git a/app/controllers/public/contact_controller.rb b/app/controllers/public/contact_controller.rb index 8beba51..dc16cd0 100644 --- a/app/controllers/public/contact_controller.rb +++ b/app/controllers/public/contact_controller.rb @@ -2,9 +2,10 @@ class ContactController < PublicController needs_profile + inverse_captcha :field => 'e_mail' def new @contact - if request.post? + if request.post? && params[self.icaptcha_field].blank? @contact = Contact.new(params[:contact]) @contact.dest = profile @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : _('Missing') diff --git a/app/views/contact/new.rhtml b/app/views/contact/new.rhtml index 0cbe865..e763f2a 100644 --- a/app/views/contact/new.rhtml +++ b/app/views/contact/new.rhtml @@ -16,6 +16,8 @@ <%= required f.text_area(:message, :rows => 10, :cols => 60) %> <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> + <%= icaptcha_field() %> + <%= submit_button(:send, _('Send')) %> <% end %> diff --git a/test/functional/contact_controller_test.rb b/test/functional/contact_controller_test.rb index 48929f8..7e84918 100644 --- a/test/functional/contact_controller_test.rb +++ b/test/functional/contact_controller_test.rb @@ -97,5 +97,19 @@ class ContactControllerTest < Test::Unit::TestCase get :new, :profile => profile.identifier assert_no_tag :tag => 'select', :attributes => {:name => 'state'} end + + should 'be able to post contact while inverse captcha field filled' do + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} + + assert_response :redirect + assert_redirected_to :action => 'new' + end + + should 'not be able to post contact while inverse captcha field filled' do + post :new, :profile => enterprise.identifier, @controller.icaptcha_field => 'filled', :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} + + assert_response :success + assert_template 'new' + end end -- libgit2 0.21.2