diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 9ad043bb6..c1fa928a7 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -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 diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 9d0af3892..df43ab8b0 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -30,6 +30,8 @@ Acepto la polĂ­tica de privacidad y el aviso legal <% end %> + <%= render 'shared/captcha' %> +
<%= f.submit %>
diff --git a/app/views/shared/_captcha.html.erb b/app/views/shared/_captcha.html.erb new file mode 100644 index 000000000..0793594e6 --- /dev/null +++ b/app/views/shared/_captcha.html.erb @@ -0,0 +1,3 @@ +<% if Rails.application.secrets.recaptcha_public_key %> +
+<% end %> \ No newline at end of file