Commit 4fc0ac241f11148a19c2ee4ecfeb912f66cd3b0d
1 parent
fe6c058f
Exists in
master
and in
22 other branches
contact: Send message for non logged users
Showing
3 changed files
with
26 additions
and
10 deletions
Show diff stats
app/controllers/public/contact_controller.rb
| 1 | class ContactController < PublicController | 1 | class ContactController < PublicController |
| 2 | 2 | ||
| 3 | - before_filter :login_required | ||
| 4 | - | ||
| 5 | needs_profile | 3 | needs_profile |
| 6 | 4 | ||
| 7 | def new | 5 | def new |
| 8 | - @contact | 6 | + @contact = build_contact |
| 9 | if request.post? && params[:confirm] == 'true' | 7 | if request.post? && params[:confirm] == 'true' |
| 10 | - @contact = user.build_contact(profile, params[:contact]) | ||
| 11 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil | 8 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil |
| 12 | @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil | 9 | @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil |
| 13 | if @contact.deliver | 10 | if @contact.deliver |
| @@ -16,8 +13,17 @@ class ContactController < PublicController | @@ -16,8 +13,17 @@ class ContactController < PublicController | ||
| 16 | else | 13 | else |
| 17 | session[:notice] = _('Contact not sent') | 14 | session[:notice] = _('Contact not sent') |
| 18 | end | 15 | end |
| 16 | + end | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + protected | ||
| 20 | + | ||
| 21 | + def build_contact | ||
| 22 | + params[:contact] ||= {} | ||
| 23 | + if logged_in? | ||
| 24 | + user.build_contact profile, params[:contact] | ||
| 19 | else | 25 | else |
| 20 | - @contact = user.build_contact(profile) | 26 | + Contact.new params[:contact].merge(dest: profile) |
| 21 | end | 27 | end |
| 22 | end | 28 | end |
| 23 | 29 |
app/views/contact/new.html.erb
| @@ -13,11 +13,16 @@ | @@ -13,11 +13,16 @@ | ||
| 13 | 13 | ||
| 14 | <%= required_fields_message %> | 14 | <%= required_fields_message %> |
| 15 | 15 | ||
| 16 | - <% location_fields = select_city(true) %> | 16 | + <% unless logged_in? %> |
| 17 | + <%= required f.text_field(:name) %> | ||
| 18 | + <%= required f.text_field(:email) %> | ||
| 19 | + <% end %> | ||
| 17 | 20 | ||
| 21 | + <% location_fields = select_city(true) %> | ||
| 18 | <% unless environment.enabled?('disable_select_city_for_contact') || location_fields.blank? %> | 22 | <% unless environment.enabled?('disable_select_city_for_contact') || location_fields.blank? %> |
| 19 | <%= labelled_form_field _('City and state'), location_fields %> | 23 | <%= labelled_form_field _('City and state'), location_fields %> |
| 20 | <% end %> | 24 | <% end %> |
| 25 | + | ||
| 21 | <%= required f.text_field(:subject) %> | 26 | <%= required f.text_field(:subject) %> |
| 22 | 27 | ||
| 23 | <%= render :file => 'shared/tiny_mce' %> | 28 | <%= render :file => 'shared/tiny_mce' %> |
| @@ -25,5 +30,9 @@ | @@ -25,5 +30,9 @@ | ||
| 25 | 30 | ||
| 26 | <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> | 31 | <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> |
| 27 | 32 | ||
| 28 | - <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> | 33 | + <% unless logged_in? %> |
| 34 | + <%= recaptcha_tags :ajax => true, :display => {:theme => 'clean'} %> | ||
| 35 | + <% end %> | ||
| 36 | + | ||
| 37 | + <%= submit_button(:send, _('Send'), :onclick => "jQuery('#confirm').val('true')") %> | ||
| 29 | <% end %> | 38 | <% end %> |
test/functional/contact_controller_test.rb
| @@ -90,11 +90,12 @@ class ContactControllerTest < ActionController::TestCase | @@ -90,11 +90,12 @@ class ContactControllerTest < ActionController::TestCase | ||
| 90 | assert_no_tag :tag => 'select', :attributes => {:name => 'state'} | 90 | assert_no_tag :tag => 'select', :attributes => {:name => 'state'} |
| 91 | end | 91 | end |
| 92 | 92 | ||
| 93 | - should 'not allow if not logged' do | 93 | + should 'show name, email and captcha if not logged' do |
| 94 | logout | 94 | logout |
| 95 | get :new, :profile => profile.identifier | 95 | get :new, :profile => profile.identifier |
| 96 | - assert_response :redirect | ||
| 97 | - assert_redirected_to :controller => 'account', :action => 'login' | 96 | + assert_tag :tag => 'input', :attributes => {:name => 'contact[name]'} |
| 97 | + assert_tag :tag => 'input', :attributes => {:name => 'contact[email]'} | ||
| 98 | + assert_tag :attributes => {id: 'dynamic_recaptcha'} | ||
| 98 | end | 99 | end |
| 99 | 100 | ||
| 100 | should 'identify sender' do | 101 | should 'identify sender' do |