adds recaptcha verification to debates
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
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