clearance 2.10.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql.yml +39 -0
  3. data/.github/workflows/standardrb.yml +22 -0
  4. data/.github/workflows/tests.yml +8 -4
  5. data/Appraisals +4 -5
  6. data/CHANGELOG.md +68 -1
  7. data/CODEOWNERS +2 -0
  8. data/Gemfile +18 -14
  9. data/Gemfile.lock +146 -106
  10. data/README.md +1 -3
  11. data/Rakefile +1 -1
  12. data/app/controllers/clearance/passwords_controller.rb +9 -9
  13. data/app/controllers/clearance/users_controller.rb +1 -1
  14. data/app/mailers/clearance_mailer.rb +1 -1
  15. data/clearance.gemspec +39 -38
  16. data/config/routes.rb +7 -7
  17. data/gemfiles/rails_7.2.gemfile +5 -1
  18. data/gemfiles/rails_8.0.gemfile +4 -0
  19. data/gemfiles/{rails_7.1.gemfile → rails_8.1.gemfile} +6 -2
  20. data/lib/clearance/authentication.rb +4 -0
  21. data/lib/clearance/back_door.rb +3 -3
  22. data/lib/clearance/configuration.rb +6 -6
  23. data/lib/clearance/constraints.rb +2 -2
  24. data/lib/clearance/controller.rb +2 -2
  25. data/lib/clearance/default_sign_in_guard.rb +1 -1
  26. data/lib/clearance/password_strategies/bcrypt.rb +2 -2
  27. data/lib/clearance/session.rb +4 -6
  28. data/lib/clearance/sign_in_guard.rb +1 -1
  29. data/lib/clearance/testing/deny_access_matcher.rb +4 -4
  30. data/lib/clearance/token.rb +1 -1
  31. data/lib/clearance/user.rb +7 -7
  32. data/lib/clearance/version.rb +1 -1
  33. data/lib/clearance.rb +10 -10
  34. data/lib/generators/clearance/install/install_generator.rb +16 -15
  35. data/lib/generators/clearance/routes/routes_generator.rb +5 -5
  36. data/lib/generators/clearance/routes/templates/routes.rb +10 -10
  37. data/lib/generators/clearance/specs/specs_generator.rb +4 -4
  38. data/lib/generators/clearance/views/views_generator.rb +4 -4
  39. data/spec/acceptance/clearance_installation_spec.rb +3 -3
  40. data/spec/clearance/back_door_spec.rb +5 -5
  41. data/spec/clearance/constraints/signed_in_spec.rb +14 -14
  42. data/spec/clearance/constraints/signed_out_spec.rb +4 -4
  43. data/spec/clearance/default_sign_in_guard_spec.rb +6 -6
  44. data/spec/clearance/rack_session_spec.rb +9 -9
  45. data/spec/clearance/session_spec.rb +60 -62
  46. data/spec/clearance/sign_in_guard_spec.rb +7 -7
  47. data/spec/clearance/testing/controller_helpers_spec.rb +15 -14
  48. data/spec/clearance/testing/deny_access_matcher_spec.rb +2 -1
  49. data/spec/clearance/testing/view_helpers_spec.rb +2 -2
  50. data/spec/clearance/token_spec.rb +3 -3
  51. data/spec/configuration_spec.rb +8 -21
  52. data/spec/controllers/apis_controller_spec.rb +2 -2
  53. data/spec/controllers/forgeries_controller_spec.rb +12 -12
  54. data/spec/controllers/passwords_controller_spec.rb +28 -28
  55. data/spec/controllers/permissions_controller_spec.rb +12 -12
  56. data/spec/controllers/sessions_controller_spec.rb +6 -6
  57. data/spec/controllers/users_controller_spec.rb +6 -6
  58. data/spec/dummy/config/environments/test.rb +3 -3
  59. data/spec/factories/users.rb +3 -3
  60. data/spec/generators/clearance/install/install_generator_spec.rb +11 -11
  61. data/spec/generators/clearance/routes/routes_generator_spec.rb +1 -1
  62. data/spec/generators/clearance/specs/specs_generator_spec.rb +2 -2
  63. data/spec/generators/clearance/views/views_generator_spec.rb +2 -2
  64. data/spec/mailers/clearance_mailer_spec.rb +3 -2
  65. data/spec/models/user_spec.rb +2 -2
  66. data/spec/password_strategies/argon2_spec.rb +3 -3
  67. data/spec/password_strategies/bcrypt_spec.rb +5 -4
  68. data/spec/password_strategies/password_strategies_spec.rb +2 -1
  69. data/spec/requests/authentication_cookie_spec.rb +4 -3
  70. data/spec/requests/backdoor_spec.rb +1 -1
  71. data/spec/requests/cookie_options_spec.rb +2 -2
  72. data/spec/requests/csrf_rotation_spec.rb +1 -1
  73. data/spec/requests/password_maintenance_spec.rb +1 -1
  74. data/spec/requests/token_expiration_spec.rb +2 -2
  75. data/spec/routing/clearance_routes_spec.rb +36 -36
  76. data/spec/support/clearance.rb +1 -1
  77. data/spec/support/fake_model_without_password_strategy.rb +5 -2
  78. data/spec/support/generator_spec_helpers.rb +2 -2
  79. data/spec/support/request_with_remember_token.rb +1 -1
  80. metadata +7 -4
data/Rakefile CHANGED
@@ -25,4 +25,4 @@ task :erb_lint do
25
25
  end
26
26
 
27
27
  desc "Run the specs and acceptance tests"
28
- task default: %w(spec spec:acceptance erb_lint)
28
+ task default: %w[spec spec:acceptance erb_lint]
@@ -1,4 +1,4 @@
1
- require 'active_support/deprecation'
1
+ require "active_support/deprecation"
2
2
 
3
3
  class Clearance::PasswordsController < Clearance::BaseController
4
4
  before_action :ensure_existing_user, only: [:edit, :update]
@@ -10,7 +10,7 @@ class Clearance::PasswordsController < Clearance::BaseController
10
10
  end
11
11
 
12
12
  def create
13
- if user = find_user_for_create
13
+ if (user = find_user_for_create)
14
14
  user.forgot_password!
15
15
  deliver_email(user)
16
16
  end
@@ -38,7 +38,7 @@ class Clearance::PasswordsController < Clearance::BaseController
38
38
  session[:password_reset_token] = nil
39
39
  else
40
40
  flash_failure_after_update
41
- render template: "passwords/edit", status: :unprocessable_entity
41
+ render template: "passwords/edit", status: :unprocessable_content
42
42
  end
43
43
  end
44
44
 
@@ -56,8 +56,8 @@ class Clearance::PasswordsController < Clearance::BaseController
56
56
  user_param = Clearance.configuration.user_id_parameter
57
57
  token = params[:token] || session[:password_reset_token]
58
58
 
59
- Clearance.configuration.user_model.
60
- find_by(id: params[user_param], confirmation_token: token.to_s)
59
+ Clearance.configuration.user_model
60
+ .find_by(id: params[user_param], confirmation_token: token.to_s)
61
61
  end
62
62
 
63
63
  def email_from_password_params
@@ -65,8 +65,8 @@ class Clearance::PasswordsController < Clearance::BaseController
65
65
  end
66
66
 
67
67
  def find_user_for_create
68
- Clearance.configuration.user_model.
69
- find_by_normalized_email(email_from_password_params)
68
+ Clearance.configuration.user_model
69
+ .find_by_normalized_email(email_from_password_params)
70
70
  end
71
71
 
72
72
  def find_user_for_edit
@@ -80,14 +80,14 @@ class Clearance::PasswordsController < Clearance::BaseController
80
80
  def ensure_email_present
81
81
  if email_from_password_params.blank?
82
82
  flash_failure_when_missing_email
83
- render template: "passwords/new", status: :unprocessable_entity
83
+ render template: "passwords/new", status: :unprocessable_content
84
84
  end
85
85
  end
86
86
 
87
87
  def ensure_existing_user
88
88
  unless find_user_by_id_and_confirmation_token
89
89
  flash_failure_when_forbidden
90
- render template: "passwords/new", status: :unprocessable_entity
90
+ render template: "passwords/new", status: :unprocessable_content
91
91
  end
92
92
  end
93
93
 
@@ -14,7 +14,7 @@ class Clearance::UsersController < Clearance::BaseController
14
14
  sign_in @user
15
15
  redirect_back_or url_after_create
16
16
  else
17
- render template: "users/new", status: :unprocessable_entity
17
+ render template: "users/new", status: :unprocessable_content
18
18
  end
19
19
  end
20
20
 
@@ -7,7 +7,7 @@ class ClearanceMailer < ActionMailer::Base
7
7
  subject: I18n.t(
8
8
  :change_password,
9
9
  scope: [:clearance, :models, :clearance_mailer]
10
- ),
10
+ )
11
11
  )
12
12
  end
13
13
  end
data/clearance.gemspec CHANGED
@@ -1,34 +1,36 @@
1
- require_relative 'lib/clearance/version'
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ require "clearance/version"
2
3
 
3
4
  Gem::Specification.new do |s|
4
- s.add_dependency 'bcrypt', '>= 3.1.1'
5
- s.add_dependency 'argon2', '~> 2.0', '>= 2.0.2'
6
- s.add_dependency 'email_validator', '~> 2.0'
7
- s.add_dependency 'railties', '>= 5.0'
8
- s.add_dependency 'activemodel', '>= 5.0'
9
- s.add_dependency 'activerecord', '>= 5.0'
10
- s.add_dependency 'actionmailer', '>= 5.0'
5
+ s.add_dependency "bcrypt", ">= 3.1.1"
6
+ s.add_dependency "argon2", "~> 2.0", ">= 2.0.2"
7
+ s.add_dependency "email_validator", "~> 2.0"
8
+ s.add_dependency "railties", ">= 5.0"
9
+ s.add_dependency "activemodel", ">= 5.0"
10
+ s.add_dependency "activerecord", ">= 5.0"
11
+ s.add_dependency "actionmailer", ">= 5.0"
11
12
  s.authors = [
12
- 'Dan Croak',
13
- 'Eugene Bolshakov',
14
- 'Mike Burns',
15
- 'Joe Ferris',
16
- 'Nick Quaranto',
17
- 'Josh Nichols',
18
- 'Matt Jankowski',
19
- 'Josh Clayton',
20
- 'Gabe Berke-Williams',
21
- 'Greg Lazarev',
22
- 'Mike Breen',
23
- 'Prem Sichanugrist',
24
- 'Harlow Ward',
25
- 'Ryan McGeary',
26
- 'Derek Prior',
27
- 'Jason Morrison',
28
- 'Galen Frechette',
29
- 'Josh Steiner',
30
- 'Dorian Marié',
31
- 'Sara Jackson'
13
+ "Dan Croak",
14
+ "Eugene Bolshakov",
15
+ "Mike Burns",
16
+ "Joe Ferris",
17
+ "Nick Quaranto",
18
+ "Josh Nichols",
19
+ "Matt Jankowski",
20
+ "Josh Clayton",
21
+ "Gabe Berke-Williams",
22
+ "Greg Lazarev",
23
+ "Mike Breen",
24
+ "Prem Sichanugrist",
25
+ "Harlow Ward",
26
+ "Ryan McGeary",
27
+ "Derek Prior",
28
+ "Jason Morrison",
29
+ "Galen Frechette",
30
+ "Josh Steiner",
31
+ "Dorian Marié",
32
+ "Sara Jackson",
33
+ "Fernando Perales"
32
34
  ]
33
35
  s.description = <<-DESCRIPTION
34
36
  Clearance is built to support authentication and authorization via an
@@ -37,16 +39,15 @@ Gem::Specification.new do |s|
37
39
  It provides some core classes commonly used for these features, along with
38
40
  some opinionated defaults - but is intended to be easy to override.
39
41
  DESCRIPTION
40
- s.email = 'support@thoughtbot.com'
41
- s.extra_rdoc_files = %w(LICENSE README.md)
42
+ s.email = "support@thoughtbot.com"
43
+ s.extra_rdoc_files = %w[LICENSE README.md]
42
44
  s.files = `git ls-files`.split("\n")
43
- s.homepage = 'https://github.com/thoughtbot/clearance'
44
- s.license = 'MIT'
45
- s.name = %q{clearance}
46
- s.rdoc_options = ['--charset=UTF-8']
47
- s.require_paths = ['lib']
48
- s.required_ruby_version = Gem::Requirement.new('>= 3.1.6')
49
- s.summary = 'Rails authentication & authorization with email & password.'
50
- s.test_files = `git ls-files -- {spec}/*`.split("\n")
45
+ s.homepage = "https://github.com/thoughtbot/clearance"
46
+ s.license = "MIT"
47
+ s.name = "clearance"
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.required_ruby_version = Gem::Requirement.new(">= 3.3.11")
51
+ s.summary = "Rails authentication & authorization with email & password."
51
52
  s.version = Clearance::VERSION
52
53
  end
data/config/routes.rb CHANGED
@@ -1,28 +1,28 @@
1
1
  if Clearance.configuration.routes_enabled?
2
2
  Rails.application.routes.draw do
3
3
  resources :passwords,
4
- controller: 'clearance/passwords',
4
+ controller: "clearance/passwords",
5
5
  only: [:create, :new]
6
6
 
7
7
  resource :session,
8
- controller: 'clearance/sessions',
8
+ controller: "clearance/sessions",
9
9
  only: [:create]
10
10
 
11
11
  resources :users,
12
- controller: 'clearance/users',
12
+ controller: "clearance/users",
13
13
  only: Clearance.configuration.user_actions do
14
14
  if Clearance.configuration.allow_password_reset?
15
15
  resource :password,
16
- controller: 'clearance/passwords',
16
+ controller: "clearance/passwords",
17
17
  only: [:edit, :update]
18
18
  end
19
19
  end
20
20
 
21
- get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
22
- delete '/sign_out' => 'clearance/sessions#destroy', as: 'sign_out'
21
+ get "/sign_in" => "clearance/sessions#new", :as => "sign_in"
22
+ delete "/sign_out" => "clearance/sessions#destroy", :as => "sign_out"
23
23
 
24
24
  if Clearance.configuration.allow_sign_up?
25
- get '/sign_up' => 'clearance/users#new', as: 'sign_up'
25
+ get "/sign_up" => "clearance/users#new", :as => "sign_up"
26
26
  end
27
27
  end
28
28
  end
@@ -5,16 +5,20 @@ source "https://rubygems.org"
5
5
  gem "addressable"
6
6
  gem "ammeter"
7
7
  gem "appraisal"
8
+ gem "benchmark"
8
9
  gem "capybara"
9
10
  gem "database_cleaner"
10
11
  gem "erb_lint", require: false
11
12
  gem "factory_bot_rails"
13
+ gem "ffi", "< 1.18.0"
12
14
  gem "nokogiri"
13
15
  gem "pry", require: false
14
16
  gem "rails-controller-testing"
15
17
  gem "rspec-rails"
16
18
  gem "shoulda-matchers"
17
- gem "sqlite3", "~> 1.7"
19
+ gem "sqlite3", "~> 2.8"
20
+ gem "standard", ">= 1.35.1", require: false
21
+ gem "timecop"
18
22
  gem "railties", "~> 7.2.0"
19
23
 
20
24
  gemspec path: "../"
@@ -5,16 +5,20 @@ source "https://rubygems.org"
5
5
  gem "addressable"
6
6
  gem "ammeter"
7
7
  gem "appraisal"
8
+ gem "benchmark"
8
9
  gem "capybara"
9
10
  gem "database_cleaner"
10
11
  gem "erb_lint", require: false
11
12
  gem "factory_bot_rails"
13
+ gem "ffi", "< 1.18.0"
12
14
  gem "nokogiri"
13
15
  gem "pry", require: false
14
16
  gem "rails-controller-testing"
15
17
  gem "rspec-rails"
16
18
  gem "shoulda-matchers"
17
19
  gem "sqlite3", ">= 2.1"
20
+ gem "standard", ">= 1.35.1", require: false
21
+ gem "timecop"
18
22
  gem "railties", "~> 8.0.0"
19
23
 
20
24
  gemspec path: "../"
@@ -5,16 +5,20 @@ source "https://rubygems.org"
5
5
  gem "addressable"
6
6
  gem "ammeter"
7
7
  gem "appraisal"
8
+ gem "benchmark"
8
9
  gem "capybara"
9
10
  gem "database_cleaner"
10
11
  gem "erb_lint", require: false
11
12
  gem "factory_bot_rails"
13
+ gem "ffi", "< 1.18.0"
12
14
  gem "nokogiri"
13
15
  gem "pry", require: false
14
16
  gem "rails-controller-testing"
15
17
  gem "rspec-rails"
16
18
  gem "shoulda-matchers"
17
- gem "sqlite3", "~> 1.7"
18
- gem "railties", "~> 7.1.0"
19
+ gem "sqlite3", "~> 2.8"
20
+ gem "standard", ">= 1.35.1", require: false
21
+ gem "timecop"
22
+ gem "railties", "~> 8.1.0"
19
23
 
20
24
  gemspec path: "../"
@@ -62,8 +62,12 @@ module Clearance
62
62
  #
63
63
  # Signing in will also regenerate the CSRF token for the current session,
64
64
  # provided {Configuration#rotate_csrf_on_sign_in?} is set.
65
+ # Disabling this because rubocop/standardrb wants to change `&block` to `&`,
66
+ # and that breaks Ruby 3.0.4 tests
67
+ # rubocop:disable Style/ArgumentsForwarding
65
68
  def sign_in(user, &block)
66
69
  clearance_session.sign_in(user, &block)
70
+ # rubocop:enable Style/ArgumentsForwarding
67
71
 
68
72
  if signed_in? && Clearance.configuration.rotate_csrf_on_sign_in?
69
73
  if request.respond_to?(:reset_csrf_token)
@@ -80,13 +80,13 @@ module Clearance
80
80
 
81
81
  # @api private
82
82
  def error_message
83
- unless allowed_environments.empty?
83
+ if allowed_environments.empty?
84
+ "BackDoor auth is disabled."
85
+ else
84
86
  <<-EOS.squish
85
87
  Can't use auth backdoor outside of
86
88
  configured environments (#{allowed_environments.join(", ")}).
87
89
  EOS
88
- else
89
- "BackDoor auth is disabled."
90
90
  end
91
91
  end
92
92
  end
@@ -157,11 +157,11 @@ module Clearance
157
157
  @cookie_domain = nil
158
158
  @cookie_expiration = ->(cookies) { 1.year.from_now.utc }
159
159
  @cookie_name = "remember_token"
160
- @cookie_path = '/'
160
+ @cookie_path = "/"
161
161
  @httponly = true
162
162
  @same_site = nil
163
- @mailer_sender = 'reply@example.com'
164
- @redirect_url = '/'
163
+ @mailer_sender = "reply@example.com"
164
+ @redirect_url = "/"
165
165
  @url_after_destroy = nil
166
166
  @url_after_denied_access_when_signed_out = nil
167
167
  @rotate_csrf_on_sign_in = true
@@ -208,12 +208,12 @@ module Clearance
208
208
  def allow_password_reset?
209
209
  @allow_password_reset
210
210
  end
211
-
211
+
212
212
  # Specifies which controller actions are allowed for user resources.
213
213
  # This will be `[:create]` is `allow_sign_up` is true (the default), and
214
214
  # empty otherwise.
215
215
  # @return [Array<Symbol>]
216
- def user_actions
216
+ def user_actions
217
217
  if allow_sign_up?
218
218
  [:create]
219
219
  else
@@ -234,7 +234,7 @@ module Clearance
234
234
  # In the default configuration, this is `user_id`.
235
235
  # @return [Symbol]
236
236
  def user_id_parameter
237
- "#{user_parameter}_id".to_sym
237
+ :"#{user_parameter}_id"
238
238
  end
239
239
 
240
240
  # @return [Boolean] are Clearance's built-in routes enabled?
@@ -1,5 +1,5 @@
1
- require 'clearance/constraints/signed_in'
2
- require 'clearance/constraints/signed_out'
1
+ require "clearance/constraints/signed_in"
2
+ require "clearance/constraints/signed_out"
3
3
 
4
4
  module Clearance
5
5
  # Clearance provides Rails routing constraints that can control access and the
@@ -1,5 +1,5 @@
1
- require 'clearance/authentication'
2
- require 'clearance/authorization'
1
+ require "clearance/authentication"
2
+ require "clearance/authorization"
3
3
 
4
4
  module Clearance
5
5
  # Adds clearance controller helpers to the controller it is mixed into.
@@ -29,7 +29,7 @@ module Clearance
29
29
  I18n.t(
30
30
  :bad_email_or_password,
31
31
  scope: [:clearance, :controllers, :sessions],
32
- default: I18n.t('flashes.failure_after_create').html_safe
32
+ default: I18n.t("flashes.failure_after_create").html_safe
33
33
  )
34
34
  end
35
35
  end
@@ -11,7 +11,7 @@ module Clearance
11
11
  # by setting a higher cost in an initializer:
12
12
  # `BCrypt::Engine.cost = 12`
13
13
  module BCrypt
14
- require 'bcrypt'
14
+ require "bcrypt"
15
15
 
16
16
  def authenticated?(password)
17
17
  if encrypted_password.present?
@@ -25,7 +25,7 @@ module Clearance
25
25
  if new_password.present?
26
26
  self.encrypted_password = ::BCrypt::Password.create(
27
27
  new_password,
28
- cost: configured_bcrypt_cost,
28
+ cost: configured_bcrypt_cost
29
29
  )
30
30
  end
31
31
  end
@@ -1,4 +1,4 @@
1
- require 'clearance/default_sign_in_guard'
1
+ require "clearance/default_sign_in_guard"
2
2
 
3
3
  module Clearance
4
4
  # Represents a clearance session, ultimately persisted in
@@ -57,9 +57,7 @@ module Clearance
57
57
  @current_user = nil
58
58
  end
59
59
 
60
- if block_given?
61
- block.call(status)
62
- end
60
+ block&.call(status)
63
61
  end
64
62
 
65
63
  # Invalidates the users remember token and removes the remember token cookie
@@ -89,7 +87,7 @@ module Clearance
89
87
  #
90
88
  # @return [Boolean]
91
89
  def signed_out?
92
- ! signed_in?
90
+ !signed_in?
93
91
  end
94
92
 
95
93
  # True if a successful authentication has been performed
@@ -179,7 +177,7 @@ module Clearance
179
177
  same_site: Clearance.configuration.same_site,
180
178
  path: Clearance.configuration.cookie_path,
181
179
  secure: Clearance.configuration.secure_cookie,
182
- value: value,
180
+ value: value
183
181
  }
184
182
  end
185
183
 
@@ -1,4 +1,4 @@
1
- require 'clearance/session_status'
1
+ require "clearance/session_status"
2
2
 
3
3
  module Clearance
4
4
  # The base class for {DefaultSignInGuard} and all custom sign in guards.
@@ -43,12 +43,12 @@ module Clearance
43
43
  @flash = opts[:flash]
44
44
  @url = opts[:redirect]
45
45
 
46
- @failure_message = ''
47
- @failure_message_when_negated = ''
46
+ @failure_message = ""
47
+ @failure_message_when_negated = ""
48
48
  end
49
49
 
50
50
  def description
51
- 'deny access'
51
+ "deny access"
52
52
  end
53
53
 
54
54
  def matches?(controller)
@@ -104,7 +104,7 @@ module Clearance
104
104
  "Didn't expect to set the flash to #{@flash}"
105
105
  true
106
106
  else
107
- @failure_message << "Expected the flash to be set to #{@flash} "\
107
+ @failure_message << "Expected the flash to be set to #{@flash} " \
108
108
  "but was #{flash_alert_value}"
109
109
  false
110
110
  end
@@ -8,7 +8,7 @@ module Clearance
8
8
  #
9
9
  # @return [String]
10
10
  def self.new
11
- SecureRandom.hex(20).encode('UTF-8')
11
+ SecureRandom.hex(20).encode("UTF-8")
12
12
  end
13
13
  end
14
14
  end
@@ -1,7 +1,7 @@
1
- require 'digest/sha1'
2
- require 'active_model'
3
- require 'email_validator'
4
- require 'clearance/token'
1
+ require "digest/sha1"
2
+ require "active_model"
3
+ require "email_validator"
4
+ require "clearance/token"
5
5
 
6
6
  module Clearance
7
7
  # Required to be included in your configued user class, which is `User` by
@@ -113,7 +113,7 @@ module Clearance
113
113
  # @api private
114
114
  module ClassMethods
115
115
  def authenticate(email, password)
116
- if user = find_by_normalized_email(email)
116
+ if (user = find_by_normalized_email(email))
117
117
  if password.present? && user.authenticated?(password)
118
118
  user
119
119
  end
@@ -150,9 +150,9 @@ module Clearance
150
150
 
151
151
  included do
152
152
  validates :email,
153
- email: { mode: :strict },
153
+ email: {mode: :strict},
154
154
  presence: true,
155
- uniqueness: { allow_blank: true, case_sensitive: true },
155
+ uniqueness: {allow_blank: true, case_sensitive: true},
156
156
  unless: :email_optional?
157
157
 
158
158
  validates :password, presence: true, unless: :skip_password_validation?
@@ -1,3 +1,3 @@
1
1
  module Clearance
2
- VERSION = "2.10.0".freeze
2
+ VERSION = "2.12.0".freeze
3
3
  end
data/lib/clearance.rb CHANGED
@@ -1,13 +1,13 @@
1
- require 'clearance/configuration'
2
- require 'clearance/sign_in_guard'
3
- require 'clearance/session'
4
- require 'clearance/rack_session'
5
- require 'clearance/back_door'
6
- require 'clearance/controller'
7
- require 'clearance/user'
8
- require 'clearance/password_strategies'
9
- require 'clearance/constraints'
10
- require 'clearance/engine'
1
+ require "clearance/configuration"
2
+ require "clearance/sign_in_guard"
3
+ require "clearance/session"
4
+ require "clearance/rack_session"
5
+ require "clearance/back_door"
6
+ require "clearance/controller"
7
+ require "clearance/user"
8
+ require "clearance/password_strategies"
9
+ require "clearance/constraints"
10
+ require "clearance/engine"
11
11
 
12
12
  module Clearance
13
13
  end
@@ -1,14 +1,15 @@
1
- require 'rails/generators/base'
2
- require 'rails/generators/active_record'
1
+ require "rails/generators/base"
2
+ require "rails/generators/active_record"
3
3
 
4
4
  module Clearance
5
5
  module Generators
6
6
  class InstallGenerator < Rails::Generators::Base
7
7
  include Rails::Generators::Migration
8
- source_root File.expand_path('../templates', __FILE__)
8
+
9
+ source_root File.expand_path("../templates", __FILE__)
9
10
 
10
11
  def create_clearance_initializer
11
- copy_file 'clearance.rb', 'config/initializers/clearance.rb'
12
+ copy_file "clearance.rb", "config/initializers/clearance.rb"
12
13
  end
13
14
 
14
15
  def inject_clearance_into_application_controller
@@ -24,7 +25,7 @@ module Clearance
24
25
  inject_into_file(
25
26
  "app/models/user.rb",
26
27
  " include Clearance::User\n\n",
27
- after: "class User < #{models_inherit_from}\n",
28
+ after: "class User < #{models_inherit_from}\n"
28
29
  )
29
30
  else
30
31
  @inherit_from = models_inherit_from
@@ -41,7 +42,12 @@ module Clearance
41
42
  end
42
43
 
43
44
  def display_readme_in_terminal
44
- readme 'README'
45
+ readme "README"
46
+ end
47
+
48
+ # for generating a timestamp when using `create_migration`
49
+ def self.next_migration_number(dir)
50
+ ActiveRecord::Generators::Base.next_migration_number(dir)
45
51
  end
46
52
 
47
53
  private
@@ -62,7 +68,7 @@ module Clearance
62
68
  migration_template(
63
69
  "db/migrate/#{migration_name}.rb.erb",
64
70
  "db/migrate/#{migration_name}.rb",
65
- config.merge(migration_version: migration_version),
71
+ config.merge(migration_version: migration_version)
66
72
  )
67
73
  end
68
74
  end
@@ -76,7 +82,7 @@ module Clearance
76
82
  email: "t.string :email",
77
83
  encrypted_password: "t.string :encrypted_password, limit: 128",
78
84
  confirmation_token: "t.string :confirmation_token, limit: 128",
79
- remember_token: "t.string :remember_token, limit: 128",
85
+ remember_token: "t.string :remember_token, limit: 128"
80
86
  }.reject { |column| existing_users_columns.include?(column.to_s) }
81
87
  end
82
88
 
@@ -87,7 +93,7 @@ module Clearance
87
93
  index_users_on_confirmation_token:
88
94
  "add_index :users, :confirmation_token, unique: true",
89
95
  index_users_on_remember_token:
90
- "add_index :users, :remember_token, unique: true",
96
+ "add_index :users, :remember_token, unique: true"
91
97
  }.reject { |index| existing_users_indexes.include?(index.to_s) }
92
98
  end
93
99
 
@@ -102,7 +108,7 @@ module Clearance
102
108
  end
103
109
 
104
110
  def migration_name_without_timestamp(file)
105
- file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, '')
111
+ file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, "")
106
112
  end
107
113
 
108
114
  def users_table_exists?
@@ -117,11 +123,6 @@ module Clearance
117
123
  ActiveRecord::Base.connection.indexes(:users).map(&:name)
118
124
  end
119
125
 
120
- # for generating a timestamp when using `create_migration`
121
- def self.next_migration_number(dir)
122
- ActiveRecord::Generators::Base.next_migration_number(dir)
123
- end
124
-
125
126
  def migration_version
126
127
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
127
128
  end