From 49c58dc5de3688d842025b83cbc91a69ef621641 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 4 Mar 2025 13:47:36 -0500 Subject: Added reCAPTCHA to help filter spam comments --- app/controllers/comments_controller.rb | 6 ++++++ app/views/comments/_form.html.haml | 3 +++ 2 files changed, 9 insertions(+) (limited to 'app') diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 9413339..31fe411 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -5,6 +5,12 @@ class CommentsController < ApplicationController raise ActiveRecord::RecordNotFound unless @blog raise ActiveRecord::RecordNotFound unless @blog.published + unless verify_recaptcha + flash.alert = "Error posting comment." + render "blogs/show" + return + end + @comment = @blog.comments.new(comment_params) @comment.request_ip = request.ip @comment.user_agent = request.user_agent diff --git a/app/views/comments/_form.html.haml b/app/views/comments/_form.html.haml index 13a0903..12692c2 100644 --- a/app/views/comments/_form.html.haml +++ b/app/views/comments/_form.html.haml @@ -24,6 +24,9 @@ .comment-website-field.comment-field .comment-field-label= f.label :website, "Website (Optional)" .comment-field-input= f.text_field :website, type: :url + .comment-website-field.comment-field + .comment-field-label + .comment-field-input= recaptcha_tags .comment-submit-button.comment-field .comment-field-label .comment-field-input= f.submit "Post" -- cgit 1.4.1