adds recaptcha verification to debates

This commit is contained in:
rgarcia
2015-07-22 20:44:10 +02:00
committed by Juanjo Bazán
parent ef2cd18028
commit cbef22606e
3 changed files with 15 additions and 2 deletions

View File

@@ -24,8 +24,11 @@ class DebatesController < ApplicationController
def create def create
@debate = Debate.new(debate_params) @debate = Debate.new(debate_params)
@debate.author = current_user @debate.author = current_user
@debate.save if verify_captcha? and @debate.save
respond_with @debate redirect_to @debate, notice: t('flash.actions.create.notice')
else
render :new
end
end end
def update def update
@@ -47,4 +50,9 @@ class DebatesController < ApplicationController
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user) raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
end end
def verify_captcha?
return true unless Rails.application.secrets.recaptcha_public_key
verify_recaptcha(model: @debate)
end
end end

View File

@@ -30,6 +30,8 @@
Acepto la política de privacidad y el aviso legal Acepto la política de privacidad y el aviso legal
<% end %> <% end %>
<%= render 'shared/captcha' %>
<div class="actions"> <div class="actions">
<%= f.submit %> <%= f.submit %>
</div> </div>

View File

@@ -0,0 +1,3 @@
<% if Rails.application.secrets.recaptcha_public_key %>
<div class="g-recaptcha" data-sitekey="6LeJIQoTAAAAAA0Mj8YroyORPa-MjfcyTDnKXRSV"></div>
<% end %>