devise 4.9.4 → 5.0.0.rc

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -392
  3. data/MIT-LICENSE +2 -2
  4. data/README.md +51 -47
  5. data/app/controllers/devise/confirmations_controller.rb +1 -1
  6. data/app/controllers/devise/sessions_controller.rb +4 -4
  7. data/app/controllers/devise/unlocks_controller.rb +1 -1
  8. data/app/helpers/devise_helper.rb +1 -26
  9. data/app/views/devise/confirmations/new.html.erb +2 -2
  10. data/app/views/devise/passwords/edit.html.erb +5 -5
  11. data/app/views/devise/passwords/new.html.erb +3 -3
  12. data/app/views/devise/registrations/edit.html.erb +9 -10
  13. data/app/views/devise/registrations/new.html.erb +8 -8
  14. data/app/views/devise/sessions/new.html.erb +6 -6
  15. data/app/views/devise/shared/_error_messages.html.erb +1 -1
  16. data/app/views/devise/shared/_links.html.erb +6 -6
  17. data/app/views/devise/unlocks/new.html.erb +2 -2
  18. data/lib/devise/controllers/sign_in_out.rb +1 -16
  19. data/lib/devise/failure_app.rb +12 -24
  20. data/lib/devise/hooks/activatable.rb +1 -1
  21. data/lib/devise/hooks/timeoutable.rb +1 -1
  22. data/lib/devise/mailers/helpers.rb +9 -15
  23. data/lib/devise/mapping.rb +1 -1
  24. data/lib/devise/models/authenticatable.rb +2 -14
  25. data/lib/devise/models/database_authenticatable.rb +6 -24
  26. data/lib/devise/models/lockable.rb +1 -1
  27. data/lib/devise/models/validatable.rb +3 -1
  28. data/lib/devise/orm.rb +10 -12
  29. data/lib/devise/parameter_sanitizer.rb +1 -2
  30. data/lib/devise/rails/routes.rb +3 -4
  31. data/lib/devise/rails.rb +7 -1
  32. data/lib/devise/test/controller_helpers.rb +1 -12
  33. data/lib/devise/version.rb +1 -1
  34. data/lib/devise.rb +12 -20
  35. data/lib/generators/active_record/devise_generator.rb +5 -11
  36. data/lib/generators/devise/controllers_generator.rb +1 -1
  37. data/lib/generators/templates/devise.rb +7 -4
  38. metadata +7 -16
  39. data/lib/devise/rails/deprecated_constant_accessor.rb +0 -39
  40. data/lib/devise/secret_key_finder.rb +0 -27
  41. data/lib/devise/test_helpers.rb +0 -15
@@ -77,9 +77,9 @@ module Devise
77
77
 
78
78
  flash.now[:alert] = i18n_message(:invalid) if is_flashing_format?
79
79
  self.response = recall_app(warden_options[:recall]).call(request.env).tap { |response|
80
- response[0] = Rack::Utils.status_code(
81
- response[0].in?(300..399) ? Devise.responder.redirect_status : Devise.responder.error_status
82
- )
80
+ status = response[0].in?(300..399) ? Devise.responder.redirect_status : Devise.responder.error_status
81
+ # Avoid warnings translating status to code using Rails if available (e.g. `unprocessable_entity` => `unprocessable_content`)
82
+ response[0] = ActionDispatch::Response.try(:rack_status_code, status) || Rack::Utils.status_code(status)
83
83
  }
84
84
  end
85
85
 
@@ -111,11 +111,16 @@ module Devise
111
111
  options[:scope] = "devise.failure"
112
112
  options[:default] = [message]
113
113
  auth_keys = scope_class.authentication_keys
114
- keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key| scope_class.human_attribute_name(key) }
115
- options[:authentication_keys] = keys.join(I18n.t(:"support.array.words_connector"))
114
+ human_keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key|
115
+ scope_class.human_attribute_name(key).downcase
116
+ }
117
+ options[:authentication_keys] = human_keys.join(I18n.t(:"support.array.words_connector"))
116
118
  options = i18n_options(options)
117
119
 
118
- I18n.t(:"#{scope}.#{message}", **options)
120
+ I18n.t(:"#{scope}.#{message}", **options).then { |msg|
121
+ # Ensure that auth keys at the start of the translated string are properly cased.
122
+ msg.start_with?(human_keys.first) ? msg.upcase_first : msg
123
+ }
119
124
  else
120
125
  message.to_s
121
126
  end
@@ -149,7 +154,7 @@ module Devise
149
154
  opts = {}
150
155
 
151
156
  # Initialize script_name with nil to prevent infinite loops in
152
- # authenticated mounted engines in rails 4.2 and 5.0
157
+ # authenticated mounted engines
153
158
  opts[:script_name] = nil
154
159
 
155
160
  route = route(scope)
@@ -161,13 +166,6 @@ module Devise
161
166
 
162
167
  if relative_url_root?
163
168
  opts[:script_name] = relative_url_root
164
-
165
- # We need to add the rootpath to `script_name` manually for applications that use a Rails
166
- # version lower than 5.1. Otherwise, it is going to generate a wrong path for Engines
167
- # that use Devise. Remove it when the support of Rails 5.0 is dropped.
168
- elsif root_path_defined?(context) && !rails_51_and_up?
169
- rootpath = context.routes.url_helpers.root_path
170
- opts[:script_name] = rootpath.chomp('/') if rootpath.length > 1
171
169
  end
172
170
 
173
171
  if context.respond_to?(route)
@@ -283,15 +281,5 @@ module Devise
283
281
  end
284
282
 
285
283
  ActiveSupport.run_load_hooks(:devise_failure_app, self)
286
-
287
- private
288
-
289
- def root_path_defined?(context)
290
- defined?(context.routes) && context.routes.url_helpers.respond_to?(:root_path)
291
- end
292
-
293
- def rails_51_and_up?
294
- Rails.gem_version >= Gem::Version.new("5.1")
295
- end
296
284
  end
297
285
  end
@@ -7,6 +7,6 @@ Warden::Manager.after_set_user do |record, warden, options|
7
7
  if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?
8
8
  scope = options[:scope]
9
9
  warden.logout(scope)
10
- throw :warden, scope: scope, message: record.inactive_message
10
+ throw :warden, scope: scope, message: record.inactive_message, locale: options.fetch(:locale, I18n.locale)
11
11
  end
12
12
  end
@@ -25,7 +25,7 @@ Warden::Manager.after_set_user do |record, warden, options|
25
25
  record.timedout?(last_request_at) &&
26
26
  !proxy.remember_me_is_active?(record)
27
27
  Devise.sign_out_all_scopes ? proxy.sign_out : proxy.sign_out(scope)
28
- throw :warden, scope: scope, message: :timeout
28
+ throw :warden, scope: scope, message: :timeout, locale: options.fetch(:locale, I18n.locale)
29
29
  end
30
30
 
31
31
  unless env['devise.skip_trackable']
@@ -33,28 +33,22 @@ module Devise
33
33
  subject: subject_for(action),
34
34
  to: resource.email,
35
35
  from: mailer_sender(devise_mapping),
36
- reply_to: mailer_reply_to(devise_mapping),
36
+ reply_to: mailer_sender(devise_mapping),
37
37
  template_path: template_paths,
38
38
  template_name: action
39
- }.merge(opts)
39
+ }
40
+ # Give priority to the mailer's default if they exists.
41
+ headers.delete(:from) if default_params[:from]
42
+ headers.delete(:reply_to) if default_params[:reply_to]
43
+
44
+ headers.merge!(opts)
40
45
 
41
46
  @email = headers[:to]
42
47
  headers
43
48
  end
44
49
 
45
- def mailer_reply_to(mapping)
46
- mailer_sender(mapping, :reply_to)
47
- end
48
-
49
- def mailer_from(mapping)
50
- mailer_sender(mapping, :from)
51
- end
52
-
53
- def mailer_sender(mapping, sender = :from)
54
- default_sender = default_params[sender]
55
- if default_sender.present?
56
- default_sender.respond_to?(:to_proc) ? instance_eval(&default_sender) : default_sender
57
- elsif Devise.mailer_sender.is_a?(Proc)
50
+ def mailer_sender(mapping)
51
+ if Devise.mailer_sender.is_a?(Proc)
58
52
  Devise.mailer_sender.call(mapping.name)
59
53
  else
60
54
  Devise.mailer_sender
@@ -30,7 +30,7 @@ module Devise
30
30
 
31
31
  alias :name :singular
32
32
 
33
- # Receives an object and find a scope for it. If a scope cannot be found,
33
+ # Receives an object and finds a scope for it. If a scope cannot be found,
34
34
  # raises an error. If a symbol is given, it's considered to be the scope.
35
35
  def self.find_scope!(obj)
36
36
  obj = obj.devise_scope if obj.respond_to?(:devise_scope)
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'devise/hooks/activatable'
4
4
  require 'devise/hooks/csrf_cleaner'
5
- require 'devise/rails/deprecated_constant_accessor'
6
5
 
7
6
  module Devise
8
7
  module Models
@@ -61,9 +60,6 @@ module Devise
61
60
  :last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
62
61
  :remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]
63
62
 
64
- include Devise::DeprecatedConstantAccessor
65
- deprecate_constant "BLACKLIST_FOR_SERIALIZATION", "Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION", deprecator: Devise.deprecator
66
-
67
63
  included do
68
64
  class_attribute :devise_modules, instance_writer: false
69
65
  self.devise_modules ||= []
@@ -187,11 +183,8 @@ module Devise
187
183
  # # Deliver later with Active Job's `deliver_later`
188
184
  # if message.respond_to?(:deliver_later)
189
185
  # message.deliver_later
190
- # # Remove once we move to Rails 4.2+ only, as `deliver` is deprecated.
191
- # elsif message.respond_to?(:deliver_now)
192
- # message.deliver_now
193
186
  # else
194
- # message.deliver
187
+ # message.deliver_now
195
188
  # end
196
189
  # end
197
190
  #
@@ -199,12 +192,7 @@ module Devise
199
192
  #
200
193
  def send_devise_notification(notification, *args)
201
194
  message = devise_mailer.send(notification, self, *args)
202
- # Remove once we move to Rails 4.2+ only.
203
- if message.respond_to?(:deliver_now)
204
- message.deliver_now
205
- else
206
- message.deliver
207
- end
195
+ message.deliver_now
208
196
  end
209
197
 
210
198
  def downcase_keys
@@ -84,16 +84,7 @@ module Devise
84
84
  # users to change relevant information like the e-mail without changing
85
85
  # their password). In case the password field is rejected, the confirmation
86
86
  # is also rejected as long as it is also blank.
87
- def update_with_password(params, *options)
88
- if options.present?
89
- Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
90
- [Devise] The second argument of `DatabaseAuthenticatable#update_with_password`
91
- (`options`) is deprecated and it will be removed in the next major version.
92
- It was added to support a feature deprecated in Rails 4, so you can safely remove it
93
- from your code.
94
- DEPRECATION
95
- end
96
-
87
+ def update_with_password(params)
97
88
  current_password = params.delete(:current_password)
98
89
 
99
90
  if params[:password].blank?
@@ -102,9 +93,9 @@ module Devise
102
93
  end
103
94
 
104
95
  result = if valid_password?(current_password)
105
- update(params, *options)
96
+ update(params)
106
97
  else
107
- assign_attributes(params, *options)
98
+ assign_attributes(params)
108
99
  valid?
109
100
  errors.add(:current_password, current_password.blank? ? :blank : :invalid)
110
101
  false
@@ -121,25 +112,16 @@ module Devise
121
112
  #
122
113
  # Example:
123
114
  #
124
- # def update_without_password(params, *options)
115
+ # def update_without_password(params)
125
116
  # params.delete(:email)
126
117
  # super(params)
127
118
  # end
128
119
  #
129
- def update_without_password(params, *options)
130
- if options.present?
131
- Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
132
- [Devise] The second argument of `DatabaseAuthenticatable#update_without_password`
133
- (`options`) is deprecated and it will be removed in the next major version.
134
- It was added to support a feature deprecated in Rails 4, so you can safely remove it
135
- from your code.
136
- DEPRECATION
137
- end
138
-
120
+ def update_without_password(params)
139
121
  params.delete(:password)
140
122
  params.delete(:password_confirmation)
141
123
 
142
- result = update(params, *options)
124
+ result = update(params)
143
125
  clean_up_passwords
144
126
  result
145
127
  end
@@ -84,7 +84,7 @@ module Devise
84
84
  if_access_locked { send_unlock_instructions }
85
85
  end
86
86
 
87
- # Overwrites active_for_authentication? from Devise::Models::Activatable for locking purposes
87
+ # Overwrites active_for_authentication? from Devise::Models::Authenticatable for locking purposes
88
88
  # by verifying whether a user is active to sign in or not based on locked?
89
89
  def active_for_authentication?
90
90
  super && !access_locked?
@@ -14,6 +14,8 @@ module Devise
14
14
  # * +email_regexp+: the regular expression used to validate e-mails;
15
15
  # * +password_length+: a range expressing password length. Defaults to 6..128.
16
16
  #
17
+ # Since +password_length+ is applied in a proc within `validates_length_of` it can be overridden
18
+ # at runtime.
17
19
  module Validatable
18
20
  # All validations used by this module.
19
21
  VALIDATIONS = [:validates_presence_of, :validates_uniqueness_of, :validates_format_of,
@@ -34,7 +36,7 @@ module Devise
34
36
 
35
37
  validates_presence_of :password, if: :password_required?
36
38
  validates_confirmation_of :password, if: :password_required?
37
- validates_length_of :password, within: password_length, allow_blank: true
39
+ validates_length_of :password, minimum: proc { password_length.min }, maximum: proc { password_length.max }, allow_blank: true
38
40
  end
39
41
  end
40
42
 
data/lib/devise/orm.rb CHANGED
@@ -1,22 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  module Orm # :nodoc:
3
5
  def self.active_record?(model)
4
6
  defined?(ActiveRecord) && model < ActiveRecord::Base
5
7
  end
6
8
 
7
- def self.active_record_51?(model)
8
- active_record?(model) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
9
- end
10
-
11
9
  def self.included(model)
12
- if Devise::Orm.active_record_51?(model)
13
- model.include DirtyTrackingNewMethods
10
+ if Devise::Orm.active_record?(model)
11
+ model.include DirtyTrackingActiveRecordMethods
14
12
  else
15
- model.include DirtyTrackingOldMethods
13
+ model.include DirtyTrackingMongoidMethods
16
14
  end
17
15
  end
18
16
 
19
- module DirtyTrackingNewMethods
17
+ module DirtyTrackingActiveRecordMethods
20
18
  def devise_email_before_last_save
21
19
  email_before_last_save
22
20
  end
@@ -42,9 +40,9 @@ module Devise
42
40
  end
43
41
  end
44
42
 
45
- module DirtyTrackingOldMethods
43
+ module DirtyTrackingMongoidMethods
46
44
  def devise_email_before_last_save
47
- email_was
45
+ respond_to?(:email_previously_was) ? email_previously_was : email_was
48
46
  end
49
47
 
50
48
  def devise_email_in_database
@@ -52,11 +50,11 @@ module Devise
52
50
  end
53
51
 
54
52
  def devise_saved_change_to_email?
55
- email_changed?
53
+ respond_to?(:email_previously_changed?) ? email_previously_changed? : email_changed?
56
54
  end
57
55
 
58
56
  def devise_saved_change_to_encrypted_password?
59
- encrypted_password_changed?
57
+ respond_to?(:encrypted_password_previously_changed?) ? encrypted_password_previously_changed? : encrypted_password_changed?
60
58
  end
61
59
 
62
60
  def devise_will_save_change_to_email?
@@ -130,8 +130,7 @@ module Devise
130
130
  #
131
131
  # Returns an +ActiveSupport::HashWithIndifferentAccess+.
132
132
  def cast_to_hash(params)
133
- # TODO: Remove the `with_indifferent_access` method call when we only support Rails 5+.
134
- params && params.to_h.with_indifferent_access
133
+ params && params.to_h
135
134
  end
136
135
 
137
136
  def default_params
@@ -235,7 +235,6 @@ module ActionDispatch::Routing
235
235
  options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {})
236
236
  options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {})
237
237
  options[:options] = @scope[:options] || {}
238
- options[:options][:format] = false if options[:format] == false
239
238
 
240
239
  resources.map!(&:to_sym)
241
240
 
@@ -413,7 +412,7 @@ module ActionDispatch::Routing
413
412
  controller: controllers[:registrations]
414
413
  }
415
414
 
416
- resource :registration, options do
415
+ resource :registration, **options do
417
416
  get :cancel
418
417
  end
419
418
  end
@@ -447,7 +446,7 @@ ERROR
447
446
  match "#{path_prefix}/#{provider}",
448
447
  to: "#{controllers[:omniauth_callbacks]}#passthru",
449
448
  as: "#{provider}_omniauth_authorize",
450
- via: [:get, :post]
449
+ via: OmniAuth.config.allowed_request_methods
451
450
 
452
451
  match "#{path_prefix}/#{provider}/callback",
453
452
  to: "#{controllers[:omniauth_callbacks]}##{provider}",
@@ -462,7 +461,7 @@ ERROR
462
461
  current_scope = @scope.dup
463
462
 
464
463
  exclusive = { as: new_as, path: new_path, module: nil }
465
- exclusive.merge!(options.slice(:constraints, :defaults, :options))
464
+ exclusive.merge!(options.slice(:constraints, :format, :defaults, :options))
466
465
 
467
466
  if @scope.respond_to? :new
468
467
  @scope = @scope.new exclusive
data/lib/devise/rails.rb CHANGED
@@ -38,7 +38,7 @@ module Devise
38
38
  end
39
39
 
40
40
  initializer "devise.secret_key" do |app|
41
- Devise.secret_key ||= Devise::SecretKeyFinder.new(app).find
41
+ Devise.secret_key ||= app.secret_key_base
42
42
 
43
43
  Devise.token_generator ||=
44
44
  if secret_key = Devise.secret_key
@@ -47,5 +47,11 @@ module Devise
47
47
  )
48
48
  end
49
49
  end
50
+
51
+ initializer "devise.configure_zeitwerk" do
52
+ if Rails.autoloaders.zeitwerk_enabled? && !defined?(ActionMailer)
53
+ Rails.autoloaders.main.ignore("#{root}/app/mailers/devise/mailer.rb")
54
+ end
55
+ end
50
56
  end
51
57
  end
@@ -64,17 +64,7 @@ module Devise
64
64
  #
65
65
  # sign_in users(:alice)
66
66
  # sign_in users(:alice), scope: :admin
67
- def sign_in(resource, deprecated = nil, scope: nil)
68
- if deprecated.present?
69
- scope = resource
70
- resource = deprecated
71
-
72
- Devise.deprecator.warn <<-DEPRECATION.strip_heredoc
73
- [Devise] sign_in(:#{scope}, resource) on controller tests is deprecated and will be removed from Devise.
74
- Please use sign_in(resource, scope: :#{scope}) instead.
75
- DEPRECATION
76
- end
77
-
67
+ def sign_in(resource, scope: nil)
78
68
  scope ||= Devise::Mapping.find_scope!(resource)
79
69
 
80
70
  warden.instance_variable_get(:@users).delete(scope)
@@ -141,7 +131,6 @@ module Devise
141
131
 
142
132
  status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
143
133
  @controller.response.headers.merge!(headers)
144
- @controller.response.content_type = headers["Content-Type"] unless Rails::VERSION::MAJOR >= 5
145
134
  @controller.status = status
146
135
  @controller.response_body = response.body
147
136
  nil # causes process return @response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devise
4
- VERSION = "4.9.4".freeze
4
+ VERSION = "5.0.0.rc".freeze
5
5
  end
data/lib/devise.rb CHANGED
@@ -16,10 +16,8 @@ module Devise
16
16
  autoload :Orm, 'devise/orm'
17
17
  autoload :ParameterFilter, 'devise/parameter_filter'
18
18
  autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
19
- autoload :TestHelpers, 'devise/test_helpers'
20
19
  autoload :TimeInflector, 'devise/time_inflector'
21
20
  autoload :TokenGenerator, 'devise/token_generator'
22
- autoload :SecretKeyFinder, 'devise/secret_key_finder'
23
21
 
24
22
  module Controllers
25
23
  autoload :Helpers, 'devise/controllers/helpers'
@@ -61,7 +59,7 @@ module Devise
61
59
  NO_INPUT = []
62
60
 
63
61
  # True values used to check params
64
- TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
62
+ TRUE_VALUES = [true, 1, '1', 'on', 'ON', 't', 'T', 'true', 'TRUE']
65
63
 
66
64
  # Secret key used by the key generator
67
65
  mattr_accessor :secret_key
@@ -275,8 +273,14 @@ module Devise
275
273
  # PRIVATE CONFIGURATION
276
274
 
277
275
  # Store scopes mappings.
278
- mattr_reader :mappings
279
276
  @@mappings = {}
277
+ def self.mappings
278
+ # Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.
279
+ # However, Devise's mappings are built during the routes loading phase.
280
+ # To ensure it works correctly, we need to load the routes first before accessing @@mappings.
281
+ Rails.application.try(:reload_routes_unless_loaded)
282
+ @@mappings
283
+ end
280
284
 
281
285
  # OmniAuth configurations.
282
286
  mattr_reader :omniauth_configs
@@ -441,9 +445,9 @@ module Devise
441
445
  # Devise.setup do |config|
442
446
  # config.allow_unconfirmed_access_for = 2.days
443
447
  #
444
- # config.warden do |manager|
448
+ # config.warden do |warden_config|
445
449
  # # Configure warden to use other strategies, like oauth.
446
- # manager.oauth(:twitter)
450
+ # warden_config.oauth(:twitter)
447
451
  # end
448
452
  # end
449
453
  def self.warden(&block)
@@ -513,25 +517,13 @@ module Devise
513
517
 
514
518
  # constant-time comparison algorithm to prevent timing attacks
515
519
  def self.secure_compare(a, b)
516
- return false if a.blank? || b.blank? || a.bytesize != b.bytesize
517
- l = a.unpack "C#{a.bytesize}"
518
-
519
- res = 0
520
- b.each_byte { |byte| res |= byte ^ l.shift }
521
- res == 0
520
+ return false if a.nil? || b.nil?
521
+ ActiveSupport::SecurityUtils.secure_compare(a, b)
522
522
  end
523
523
 
524
524
  def self.deprecator
525
525
  @deprecator ||= ActiveSupport::Deprecation.new("5.0", "Devise")
526
526
  end
527
-
528
- def self.activerecord51? # :nodoc:
529
- deprecator.warn <<-DEPRECATION.strip_heredoc
530
- [Devise] `Devise.activerecord51?` is deprecated and will be removed in the next major version.
531
- It is a non-public method that's no longer used internally, but that other libraries have been relying on.
532
- DEPRECATION
533
- defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
534
- end
535
527
  end
536
528
 
537
529
  require 'warden'
@@ -5,7 +5,7 @@ require 'generators/devise/orm_helpers'
5
5
 
6
6
  module ActiveRecord
7
7
  module Generators
8
- class DeviseGenerator < ActiveRecord::Generators::Base
8
+ class DeviseGenerator < Base
9
9
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
10
10
 
11
11
  class_option :primary_key_type, type: :string, desc: "The type for primary key"
@@ -82,10 +82,6 @@ RUBY
82
82
  postgresql?
83
83
  end
84
84
 
85
- def rails5_and_up?
86
- Rails::VERSION::MAJOR >= 5
87
- end
88
-
89
85
  def rails61_and_up?
90
86
  Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1)
91
87
  end
@@ -106,14 +102,12 @@ RUBY
106
102
  end
107
103
  end
108
104
 
109
- def migration_version
110
- if rails5_and_up?
111
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
112
- end
113
- end
105
+ def migration_version
106
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
107
+ end
114
108
 
115
109
  def primary_key_type
116
- primary_key_string if rails5_and_up?
110
+ primary_key_string
117
111
  end
118
112
 
119
113
  def primary_key_string
@@ -11,7 +11,7 @@ module Devise
11
11
  Create inherited Devise controllers in your app/controllers folder.
12
12
 
13
13
  Use -c to specify which controller you want to overwrite.
14
- If you do no specify a controller, all controllers will be created.
14
+ If you do not specify a controller, all controllers will be created.
15
15
  For example:
16
16
 
17
17
  rails generate devise:controllers users -c=sessions
@@ -157,6 +157,9 @@ Devise.setup do |config|
157
157
  # initial account confirmation) to be applied. Requires additional unconfirmed_email
158
158
  # db field (see migrations). Until confirmed, new email is stored in
159
159
  # unconfirmed_email column, and copied to email column on successful confirmation.
160
+ # Also, when used in conjunction with `send_email_changed_notification`,
161
+ # the notification is sent to the original email when the change is requested,
162
+ # not when the unconfirmed email is confirmed.
160
163
  config.reconfirmable = true
161
164
 
162
165
  # Defines which key will be used when confirming an account
@@ -277,9 +280,9 @@ Devise.setup do |config|
277
280
  # If you want to use other strategies, that are not supported by Devise, or
278
281
  # change the failure app, you can configure them inside the config.warden block.
279
282
  #
280
- # config.warden do |manager|
281
- # manager.intercept_401 = false
282
- # manager.default_strategies(scope: :user).unshift :some_external_strategy
283
+ # config.warden do |warden_config|
284
+ # warden_config.intercept_401 = false
285
+ # warden_config.default_strategies(scope: :user).unshift :some_external_strategy
283
286
  # end
284
287
 
285
288
  # ==> Mountable engine configurations
@@ -302,7 +305,7 @@ Devise.setup do |config|
302
305
  # apps is `200 OK` and `302 Found` respectively, but new apps are generated with
303
306
  # these new defaults that match Hotwire/Turbo behavior.
304
307
  # Note: These might become the new default in future versions of Devise.
305
- config.responder.error_status = :unprocessable_entity
308
+ config.responder.error_status = <%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>
306
309
  config.responder.redirect_status = :see_other
307
310
 
308
311
  # ==> Configuration for :registerable