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

View File

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

View File

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