class Public::ContactsController < ApplicationController layout "public" def index end def new @contact = Contact.new end def create @contact = Contact.new(params.require(:contact).permit(:website, :place, :tel, :name, :email, :message)) if @contact.valid? if valid_captcha?(params['g-recaptcha-response']) @contact.save #QuestionMailer.send_contact(@contact).deliver #QuestionMailer.remerciement(@contact).deliver render :action => :create else render :action => :captcha end else render :action => :new end end def valid_captcha?(recaptcha_response) return true if Rails.env.test? @c = Curl::Easy.new("https://www.google.com/recaptcha/api/siteverify") do |curl| curl.verbose = true end @c.http_post( Curl::PostField.content(:secret, RECAPTCHA_SECRET_KEY), Curl::PostField.content(:response, recaptcha_response) ) @debug = JSON.parse(@c.body_str) #["successe"] return @debug["success"] end end