Captcha
This commit is contained in:
parent
e7e21cf829
commit
57f9e92274
2
Gemfile
2
Gemfile
@ -58,7 +58,7 @@ end
|
|||||||
# Use unicorn as the app server
|
# Use unicorn as the app server
|
||||||
gem "unicorn"
|
gem "unicorn"
|
||||||
|
|
||||||
|
gem 'curb'
|
||||||
|
|
||||||
# Use debugger
|
# Use debugger
|
||||||
# gem 'debugger', group: [:development, :test]
|
# gem 'debugger', group: [:development, :test]
|
||||||
|
@ -57,6 +57,7 @@ GEM
|
|||||||
commonjs (0.2.7)
|
commonjs (0.2.7)
|
||||||
concurrent-ruby (1.1.8)
|
concurrent-ruby (1.1.8)
|
||||||
crass (1.0.6)
|
crass (1.0.6)
|
||||||
|
curb (0.9.11)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (2.8.1)
|
execjs (2.8.1)
|
||||||
formtastic (3.1.5)
|
formtastic (3.1.5)
|
||||||
@ -208,6 +209,7 @@ DEPENDENCIES
|
|||||||
bcrypt-ruby (~> 3.1.2)
|
bcrypt-ruby (~> 3.1.2)
|
||||||
carrierwave
|
carrierwave
|
||||||
coffee-rails (~> 4.0.0)
|
coffee-rails (~> 4.0.0)
|
||||||
|
curb
|
||||||
formtastic
|
formtastic
|
||||||
formtastic-bootstrap
|
formtastic-bootstrap
|
||||||
haml-rails
|
haml-rails
|
||||||
|
@ -11,16 +11,46 @@ class Public::ContactsController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@contact = Contact.new(params.require(:contact).permit(:website, :place, :tel, :name, :email, :message))
|
@contact = Contact.new(params.require(:contact).permit(:website, :place, :tel, :name, :email, :message))
|
||||||
|
|
||||||
|
|
||||||
if @contact.save
|
|
||||||
QuestionMailer.send_contact(@contact).deliver
|
|
||||||
QuestionMailer.remerciement(@contact).deliver
|
|
||||||
render :action => :create
|
|
||||||
else
|
|
||||||
|
|
||||||
render :action => :new
|
if @contact.save
|
||||||
end
|
if valid_captcha?(params['g-recaptcha-response'])
|
||||||
|
QuestionMailer.send_contact(@contact).deliver
|
||||||
|
QuestionMailer.remerciement(@contact).deliver
|
||||||
|
render :action => :create
|
||||||
|
|
||||||
|
else
|
||||||
|
render :action => :captcha
|
||||||
|
end
|
||||||
|
else
|
||||||
|
|
||||||
|
render :action => :new
|
||||||
|
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
|
||||||
|
@ -6,4 +6,23 @@
|
|||||||
=f.input :tel, :label => "Téléphone :"
|
=f.input :tel, :label => "Téléphone :"
|
||||||
=f.input :place, :label => "Lieu de votre projet :"
|
=f.input :place, :label => "Lieu de votre projet :"
|
||||||
=f.input :message, :label => "Message :"
|
=f.input :message, :label => "Message :"
|
||||||
=f.submit "Envoyer", :class => "btn"
|
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||||
|
|
||||||
|
=raw '<div class="g-recaptcha" data-sitekey="'+RECAPTCHA_SITE_KEY+'"></div>'
|
||||||
|
|
||||||
|
=f.submit "Envoyer", :class => "btn"
|
||||||
|
|
||||||
|
:javascript
|
||||||
|
$("form").validationEngine();
|
||||||
|
|
||||||
|
$("form").submit(function(event) {
|
||||||
|
|
||||||
|
var recaptcha = $("#g-recaptcha-response").val();
|
||||||
|
if (recaptcha === "") {
|
||||||
|
event.preventDefault();
|
||||||
|
alert("Merci de cliquer sur la case 'Je ne suis pas un robot.'");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
1
app/views/public/contacts/captcha.js.erb
Normal file
1
app/views/public/contacts/captcha.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
$("#form").append("Captcha invalide");
|
@ -36,4 +36,8 @@ CMSnb::Application.configure do
|
|||||||
|
|
||||||
|
|
||||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||||
|
|
||||||
|
RECAPTCHA_SITE_KEY = '6Ldj6LQUAAAAACY6SmePKeUcpbcY9WVD47-u8l_s'
|
||||||
|
RECAPTCHA_SECRET_KEY = '6Ldj6LQUAAAAAO-11feITBPmDATAF--NqcXh5_WP'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -87,4 +87,7 @@ CMSnb::Application.configure do
|
|||||||
|
|
||||||
config.action_mailer.delivery_method = :sendmail
|
config.action_mailer.delivery_method = :sendmail
|
||||||
|
|
||||||
|
RECAPTCHA_SITE_KEY = '6Ldj6LQUAAAAACY6SmePKeUcpbcY9WVD47-u8l_s'
|
||||||
|
RECAPTCHA_SECRET_KEY = '6Ldj6LQUAAAAAO-11feITBPmDATAF--NqcXh5_WP'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user