diff --git a/app/controllers/public/contact_controller.rb b/app/controllers/public/contact_controller.rb index 36fee63..bad75d0 100644 --- a/app/controllers/public/contact_controller.rb +++ b/app/controllers/public/contact_controller.rb @@ -1,13 +1,10 @@ class ContactController < PublicController - before_filter :login_required - needs_profile def new - @contact + @contact = build_contact if request.post? && params[:confirm] == 'true' - @contact = user.build_contact(profile, params[:contact]) @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil if @contact.deliver @@ -16,8 +13,17 @@ class ContactController < PublicController else session[:notice] = _('Contact not sent') end + end + end + + protected + + def build_contact + params[:contact] ||= {} + if logged_in? + user.build_contact profile, params[:contact] else - @contact = user.build_contact(profile) + Contact.new params[:contact].merge(dest: profile) end end diff --git a/app/views/contact/new.html.erb b/app/views/contact/new.html.erb index d17b468..327f045 100644 --- a/app/views/contact/new.html.erb +++ b/app/views/contact/new.html.erb @@ -13,11 +13,16 @@ <%= required_fields_message %> - <% location_fields = select_city(true) %> + <% unless logged_in? %> + <%= required f.text_field(:name) %> + <%= required f.text_field(:email) %> + <% end %> + <% location_fields = select_city(true) %> <% unless environment.enabled?('disable_select_city_for_contact') || location_fields.blank? %> <%= labelled_form_field _('City and state'), location_fields %> <% end %> + <%= required f.text_field(:subject) %> <%= render :file => 'shared/tiny_mce' %> @@ -25,5 +30,9 @@ <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> - <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> + <% unless logged_in? %> + <%= recaptcha_tags :ajax => true, :display => {:theme => 'clean'} %> + <% end %> + + <%= submit_button(:send, _('Send'), :onclick => "jQuery('#confirm').val('true')") %> <% end %> diff --git a/test/functional/contact_controller_test.rb b/test/functional/contact_controller_test.rb index 5006770..ad73a41 100644 --- a/test/functional/contact_controller_test.rb +++ b/test/functional/contact_controller_test.rb @@ -90,11 +90,12 @@ class ContactControllerTest < ActionController::TestCase assert_no_tag :tag => 'select', :attributes => {:name => 'state'} end - should 'not allow if not logged' do + should 'show name, email and captcha if not logged' do logout get :new, :profile => profile.identifier - assert_response :redirect - assert_redirected_to :controller => 'account', :action => 'login' + assert_tag :tag => 'input', :attributes => {:name => 'contact[name]'} + assert_tag :tag => 'input', :attributes => {:name => 'contact[email]'} + assert_tag :attributes => {id: 'dynamic_recaptcha'} end should 'identify sender' do -- libgit2 0.21.2