From d0b3227689df5d237328e73a3ec8d39369b3e756 Mon Sep 17 00:00:00 2001 From: Nixon Date: Sat, 26 Oct 2024 15:32:54 -0300 Subject: [PATCH] Make gem add bcrypt more resilient --- CHANGELOG.md | 1 + .../authentication/authentication_generator.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 871fdaa..76d6661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## New version * We don't need to add `config.action_mailer.default_url_options` anymore +* Make gem add bcrypt more resilient ## Authentication Zero 4.0.2 ## diff --git a/lib/generators/authentication/authentication_generator.rb b/lib/generators/authentication/authentication_generator.rb index 1cf4667..ad0b807 100644 --- a/lib/generators/authentication/authentication_generator.rb +++ b/lib/generators/authentication/authentication_generator.rb @@ -19,7 +19,11 @@ class AuthenticationGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) def add_gems - gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]" + if bcrypt_present? + uncomment_lines "Gemfile", /gem "bcrypt"/ + else + gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]" + end if options.pwned? gem "pwned", comment: "Use Pwned to check if a password has been found in any of the huge data breaches [https://github.com/philnash/pwned]" @@ -241,6 +245,10 @@ def sudoable? options.sudoable? && !options.api? end + def bcrypt_present? + File.read("Gemfile").include?('gem "bcrypt"') + end + def importmaps? Rails.root.join("config/importmap.rb").exist? end