This commit is contained in:
Nicolas Bally 2019-08-26 16:07:27 +02:00
parent 0d50f90c67
commit b456490186
4 changed files with 69 additions and 26 deletions

View File

@ -8,6 +8,10 @@ class ContactController < ApplicationController
def create def create
@lang = LangSite.first @lang = LangSite.first
if valid_captcha?(params['g-recaptcha-response'])
if true
@params = params @params = params
DemandeMail.prise(@params).deliver DemandeMail.prise(@params).deliver
DemandeMail.remerciement(@params).deliver DemandeMail.remerciement(@params).deliver
@ -37,8 +41,36 @@ class ContactController < ApplicationController
) )
@debug = @c.body_str @debug = @c.body_str
else
render :inline => "ok"
end
else
redirect_to :back
end
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 end

View File

@ -97,6 +97,10 @@
=text_area_tag :message, "", :placeholder => "Message", :style => "height:10em;" =text_area_tag :message, "", :placeholder => "Message", :style => "height:10em;"
%p Les champs marqués d'un * sont requis. %p Les champs marqués d'un * sont requis.
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
=raw '<div class="g-recaptcha" data-sitekey="'+RECAPTCHA_SITE_KEY+'"></div>'
=submit_tag "Envoyer", :style => "display:block;text-align:center;margin:auto;color:white;background:#9ab354;border-radius:1em; padding:0.5em 1em; font-size:1em; border:0px;" =submit_tag "Envoyer", :style => "display:block;text-align:center;margin:auto;color:white;background:#9ab354;border-radius:1em; padding:0.5em 1em; font-size:1em; border:0px;"
:javascript :javascript

View File

@ -46,4 +46,8 @@ Rails.application.configure do
config.action_mailer.default_url_options = { :host => HOSTNAME } config.action_mailer.default_url_options = { :host => HOSTNAME }
UAL_API_HOST = "localhost:3000" UAL_API_HOST = "localhost:3000"
RECAPTCHA_SITE_KEY = '6Ldj6LQUAAAAACY6SmePKeUcpbcY9WVD47-u8l_s'
RECAPTCHA_SECRET_KEY = '6Ldj6LQUAAAAAO-11feITBPmDATAF--NqcXh5_WP'
end end

View File

@ -82,6 +82,9 @@ Rails.application.configure do
#config.action_mailer.delivery_method = :file #config.action_mailer.delivery_method = :file
config.action_mailer.default_url_options = { :host => HOSTNAME } config.action_mailer.default_url_options = { :host => HOSTNAME }
RECAPTCHA_SITE_KEY = '6Ldj6LQUAAAAACY6SmePKeUcpbcY9WVD47-u8l_s'
RECAPTCHA_SECRET_KEY = '6Ldj6LQUAAAAAO-11feITBPmDATAF--NqcXh5_WP'
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
:address => "localhost", :address => "localhost",