Skip to content

Commit

Permalink
Merge pull request #1385 from DigitalCurationCentre/issue501
Browse files Browse the repository at this point in the history
Enable recaptcha for contact_us form: fixes #501
  • Loading branch information
jollopre authored Apr 16, 2018
2 parents 785a36c + 9e70b54 commit 8856060
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class ContactUs::ContactsController < ApplicationController

def create
@contact = ContactUs::Contact.new(params[:contact_us_contact])

if verify_recaptcha(model: @contact) && @contact.save
redirect_to(ContactUs.success_redirect || '/', :notice => _('Contact email was successfully sent.'))
else
flash[:alert] = _('Captcha verification failed, please retry.')
redirect_to request.referrer
#render_new_page
end
end

def new
@contact = ContactUs::Contact.new
render_new_page
end

protected

def render_new_page
case ContactUs.form_gem
when 'formtastic' then render 'new_formtastic'
when 'simple_form' then render 'new_simple_form'
else
render 'new'
end
end

end

0 comments on commit 8856060

Please sign in to comment.