From b042d42e3bcdb3c2f2a30b3059211e82187295dd Mon Sep 17 00:00:00 2001 From: Julian Rubisch Date: Sat, 17 Jun 2023 18:45:16 +0200 Subject: [PATCH 1/2] chore: Add invisible_captcha to user registration --- bullet_train/Gemfile.lock | 3 +++ .../app/controllers/concerns/registrations/controller_base.rb | 2 ++ bullet_train/app/views/devise/registrations/new.html.erb | 2 ++ bullet_train/bullet_train.gemspec | 3 +++ 4 files changed, 10 insertions(+) diff --git a/bullet_train/Gemfile.lock b/bullet_train/Gemfile.lock index f618a11aa..e3c4376f6 100644 --- a/bullet_train/Gemfile.lock +++ b/bullet_train/Gemfile.lock @@ -28,6 +28,7 @@ PATH hiredis http_accept_language image_processing + invisible_captcha microscope nice_partials (~> 0.9) pagy @@ -202,6 +203,8 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) + invisible_captcha (2.1.0) + rails (>= 5.2) json (2.6.3) language_server-protocol (3.17.0.2) loofah (2.20.0) diff --git a/bullet_train/app/controllers/concerns/registrations/controller_base.rb b/bullet_train/app/controllers/concerns/registrations/controller_base.rb index a528e74c8..9f906dabe 100644 --- a/bullet_train/app/controllers/concerns/registrations/controller_base.rb +++ b/bullet_train/app/controllers/concerns/registrations/controller_base.rb @@ -1,6 +1,8 @@ module Registrations::ControllerBase extend ActiveSupport::Concern + invisible_captcha only: :create + included do def new # We have to set the session here because Safari wouldn't save it on a redirect to this URL. diff --git a/bullet_train/app/views/devise/registrations/new.html.erb b/bullet_train/app/views/devise/registrations/new.html.erb index aa234d63d..f1b2f118c 100644 --- a/bullet_train/app/views/devise/registrations/new.html.erb +++ b/bullet_train/app/views/devise/registrations/new.html.erb @@ -6,6 +6,8 @@ <%= render 'account/shared/notices' %> <%= render 'account/shared/forms/errors', form: f %> + <%= invisible_captcha %> + <%= render 'shared/fields/email_field', form: f, method: :email, options: {autofocus: true} do %> <% content_for :help do %> <%= link_to t('devise.links.have_account'), new_user_session_path %> diff --git a/bullet_train/bullet_train.gemspec b/bullet_train/bullet_train.gemspec index 83e8f4f8e..2703bfbd0 100644 --- a/bullet_train/bullet_train.gemspec +++ b/bullet_train/bullet_train.gemspec @@ -105,4 +105,7 @@ Gem::Specification.new do |spec| # Password strength. spec.add_dependency "devise-pwned_password" + + # Captcha + spec.add_dependency "invisible_captcha" end From e9fe7501e01d0fc32c3703013c0cfb7b1f98334b Mon Sep 17 00:00:00 2001 From: Julian Rubisch Date: Fri, 30 Jun 2023 11:49:37 +0200 Subject: [PATCH 2/2] fix: Hoist invisible_captcha require --- .../controllers/concerns/registrations/controller_base.rb | 4 ++-- bullet_train/lib/bullet_train/engine.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bullet_train/app/controllers/concerns/registrations/controller_base.rb b/bullet_train/app/controllers/concerns/registrations/controller_base.rb index 9f906dabe..13ad29bba 100644 --- a/bullet_train/app/controllers/concerns/registrations/controller_base.rb +++ b/bullet_train/app/controllers/concerns/registrations/controller_base.rb @@ -1,9 +1,9 @@ module Registrations::ControllerBase extend ActiveSupport::Concern - invisible_captcha only: :create - included do + invisible_captcha only: :create + def new # We have to set the session here because Safari wouldn't save it on a redirect to this URL. if params[:invitation_uuid] diff --git a/bullet_train/lib/bullet_train/engine.rb b/bullet_train/lib/bullet_train/engine.rb index 28216abf0..89003503a 100644 --- a/bullet_train/lib/bullet_train/engine.rb +++ b/bullet_train/lib/bullet_train/engine.rb @@ -19,6 +19,12 @@ rescue LoadError end +begin + # And the same holds true for invisible_captcha + require "invisible_captcha" +rescue LoadError +end + module BulletTrain class Engine < ::Rails::Engine end