adds recaptcha verification to debates
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
Acepto la política de privacidad y el aviso legal
|
||||
<% end %>
|
||||
|
||||
<%= render 'shared/captcha' %>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
|
||||
3
app/views/shared/_captcha.html.erb
Normal file
3
app/views/shared/_captcha.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<% if Rails.application.secrets.recaptcha_public_key %>
|
||||
<div class="g-recaptcha" data-sitekey="6LeJIQoTAAAAAA0Mj8YroyORPa-MjfcyTDnKXRSV"></div>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user