devise 3.0.0 → 4.8.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +351 -0
- data/MIT-LICENSE +2 -1
- data/README.md +422 -130
- data/app/controllers/devise/confirmations_controller.rb +17 -6
- data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
- data/app/controllers/devise/passwords_controller.rb +23 -8
- data/app/controllers/devise/registrations_controller.rb +70 -28
- data/app/controllers/devise/sessions_controller.rb +49 -17
- data/app/controllers/devise/unlocks_controller.rb +11 -4
- data/app/controllers/devise_controller.rb +74 -34
- data/app/helpers/devise_helper.rb +23 -18
- data/app/mailers/devise/mailer.rb +25 -10
- data/app/views/devise/confirmations/new.html.erb +9 -5
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +16 -7
- data/app/views/devise/passwords/new.html.erb +9 -5
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +20 -9
- data/app/views/devise/sessions/new.html.erb +19 -10
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +10 -10
- data/app/views/devise/unlocks/new.html.erb +9 -5
- data/config/locales/en.yml +26 -20
- data/lib/devise/controllers/helpers.rb +122 -125
- data/lib/devise/controllers/rememberable.rb +14 -14
- data/lib/devise/controllers/scoped_views.rb +3 -1
- data/lib/devise/controllers/sign_in_out.rb +121 -0
- data/lib/devise/controllers/store_location.rb +76 -0
- data/lib/devise/controllers/url_helpers.rb +10 -8
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +24 -0
- data/lib/devise/failure_app.rb +132 -42
- data/lib/devise/hooks/activatable.rb +7 -6
- data/lib/devise/hooks/csrf_cleaner.rb +9 -0
- data/lib/devise/hooks/forgetable.rb +3 -1
- data/lib/devise/hooks/lockable.rb +5 -3
- data/lib/devise/hooks/proxy.rb +23 -0
- data/lib/devise/hooks/rememberable.rb +7 -4
- data/lib/devise/hooks/timeoutable.rb +18 -8
- data/lib/devise/hooks/trackable.rb +3 -1
- data/lib/devise/mailers/helpers.rb +15 -18
- data/lib/devise/mapping.rb +9 -3
- data/lib/devise/models/authenticatable.rb +102 -80
- data/lib/devise/models/confirmable.rb +154 -72
- data/lib/devise/models/database_authenticatable.rb +125 -25
- data/lib/devise/models/lockable.rb +50 -29
- data/lib/devise/models/omniauthable.rb +3 -1
- data/lib/devise/models/recoverable.rb +72 -50
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +65 -32
- data/lib/devise/models/timeoutable.rb +4 -8
- data/lib/devise/models/trackable.rb +20 -4
- data/lib/devise/models/validatable.rb +16 -9
- data/lib/devise/models.rb +6 -13
- data/lib/devise/modules.rb +12 -11
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/omniauth.rb +4 -5
- data/lib/devise/orm/active_record.rb +5 -1
- data/lib/devise/orm/mongoid.rb +6 -2
- data/lib/devise/parameter_filter.rb +4 -0
- data/lib/devise/parameter_sanitizer.rb +144 -34
- data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
- data/lib/devise/rails/routes.rb +191 -127
- data/lib/devise/rails/warden_compat.rb +2 -1
- data/lib/devise/rails.rb +13 -20
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +21 -22
- data/lib/devise/strategies/base.rb +3 -1
- data/lib/devise/strategies/database_authenticatable.rb +15 -4
- data/lib/devise/strategies/rememberable.rb +15 -3
- data/lib/devise/test/controller_helpers.rb +167 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -123
- data/lib/devise/time_inflector.rb +4 -2
- data/lib/devise/token_generator.rb +32 -0
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +124 -78
- data/lib/generators/active_record/devise_generator.rb +64 -15
- data/lib/generators/active_record/templates/migration.rb +9 -8
- data/lib/generators/active_record/templates/migration_existing.rb +9 -8
- data/lib/generators/devise/controllers_generator.rb +46 -0
- data/lib/generators/devise/devise_generator.rb +10 -6
- data/lib/generators/devise/install_generator.rb +19 -1
- data/lib/generators/devise/orm_helpers.rb +17 -9
- data/lib/generators/devise/views_generator.rb +51 -28
- data/lib/generators/mongoid/devise_generator.rb +24 -24
- data/lib/generators/templates/README +13 -12
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
- data/lib/generators/templates/devise.rb +118 -53
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +6 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +12 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +5 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +14 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +12 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +5 -2
- metadata +73 -294
- data/.gitignore +0 -10
- data/.travis.yml +0 -20
- data/.yardopts +0 -9
- data/CHANGELOG.rdoc +0 -941
- data/CONTRIBUTING.md +0 -14
- data/Gemfile +0 -31
- data/Gemfile.lock +0 -159
- data/Rakefile +0 -35
- data/app/views/devise/_links.erb +0 -3
- data/devise.gemspec +0 -26
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2.x +0 -31
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -156
- data/lib/devise/models/token_authenticatable.rb +0 -89
- data/lib/devise/strategies/token_authenticatable.rb +0 -91
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helpers_test.rb +0 -253
- data/test/controllers/internal_helpers_test.rb +0 -120
- data/test/controllers/passwords_controller_test.rb +0 -32
- data/test/controllers/sessions_controller_test.rb +0 -99
- data/test/controllers/url_helpers_test.rb +0 -59
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -83
- data/test/failure_app_test.rb +0 -221
- data/test/generators/active_record_generator_test.rb +0 -73
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -13
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -67
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -699
- data/test/integration/confirmable_test.rb +0 -299
- data/test/integration/database_authenticatable_test.rb +0 -84
- data/test/integration/http_authenticatable_test.rb +0 -115
- data/test/integration/lockable_test.rb +0 -242
- data/test/integration/omniauthable_test.rb +0 -133
- data/test/integration/recoverable_test.rb +0 -335
- data/test/integration/registerable_test.rb +0 -349
- data/test/integration/rememberable_test.rb +0 -165
- data/test/integration/timeoutable_test.rb +0 -150
- data/test/integration/token_authenticatable_test.rb +0 -205
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -111
- data/test/mailers/reset_password_instructions_test.rb +0 -92
- data/test/mailers/unlock_instructions_test.rb +0 -87
- data/test/mapping_test.rb +0 -127
- data/test/models/authenticatable_test.rb +0 -13
- data/test/models/confirmable_test.rb +0 -452
- data/test/models/database_authenticatable_test.rb +0 -226
- data/test/models/lockable_test.rb +0 -282
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -222
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -175
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -46
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/models/trackable_test.rb +0 -13
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -163
- data/test/omniauth/config_test.rb +0 -57
- data/test/omniauth/url_helpers_test.rb +0 -54
- data/test/orm/active_record.rb +0 -10
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -58
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -6
- data/test/rails_app/app/active_record/shim.rb +0 -2
- data/test/rails_app/app/active_record/user.rb +0 -6
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -11
- data/test/rails_app/app/controllers/application_controller.rb +0 -9
- data/test/rails_app/app/controllers/home_controller.rb +0 -25
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
- data/test/rails_app/app/controllers/users_controller.rb +0 -31
- data/test/rails_app/app/helpers/application_helper.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -12
- data/test/rails_app/app/mongoid/admin.rb +0 -29
- data/test/rails_app/app/mongoid/shim.rb +0 -23
- data/test/rails_app/app/mongoid/user.rb +0 -42
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config/application.rb +0 -40
- data/test/rails_app/config/boot.rb +0 -8
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -34
- data/test/rails_app/config/environments/production.rb +0 -84
- data/test/rails_app/config/environments/test.rb +0 -36
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -178
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -8
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -104
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -74
- data/test/rails_app/db/schema.rb +0 -52
- data/test/rails_app/lib/shared_admin.rb +0 -14
- data/test/rails_app/lib/shared_user.rb +0 -25
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/routes_test.rb +0 -250
- data/test/support/assertions.rb +0 -40
- data/test/support/helpers.rb +0 -91
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -4
- data/test/support/webrat/integrations/rails.rb +0 -24
- data/test/test_helper.rb +0 -34
- data/test/test_helpers_test.rb +0 -151
- data/test/test_models.rb +0 -26
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'devise/hooks/activatable'
|
|
4
|
+
require 'devise/hooks/csrf_cleaner'
|
|
5
|
+
require 'devise/rails/deprecated_constant_accessor'
|
|
2
6
|
|
|
3
7
|
module Devise
|
|
4
8
|
module Models
|
|
@@ -28,9 +32,7 @@ module Devise
|
|
|
28
32
|
# It also accepts an array specifying the strategies that should allow params authentication.
|
|
29
33
|
#
|
|
30
34
|
# * +skip_session_storage+: By default Devise will store the user in session.
|
|
31
|
-
#
|
|
32
|
-
# :skip_session_storage => [:token_auth] or :skip_session_storage => [:http_auth, :token_auth],
|
|
33
|
-
# by default is set to :skip_session_storage => [:http_auth].
|
|
35
|
+
# By default is set to skip_session_storage: [:http_auth].
|
|
34
36
|
#
|
|
35
37
|
# == active_for_authentication?
|
|
36
38
|
#
|
|
@@ -38,7 +40,7 @@ module Devise
|
|
|
38
40
|
# calling model.active_for_authentication?. This method is overwritten by other devise modules. For instance,
|
|
39
41
|
# :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
|
|
40
42
|
#
|
|
41
|
-
# You overwrite this method yourself, but if you do, don't forget to call super:
|
|
43
|
+
# You can overwrite this method yourself, but if you do, don't forget to call super:
|
|
42
44
|
#
|
|
43
45
|
# def active_for_authentication?
|
|
44
46
|
# super && special_condition_is_valid?
|
|
@@ -54,13 +56,16 @@ module Devise
|
|
|
54
56
|
module Authenticatable
|
|
55
57
|
extend ActiveSupport::Concern
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
UNSAFE_ATTRIBUTES_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,
|
|
58
60
|
:remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,
|
|
59
61
|
:last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
|
|
60
|
-
:remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at
|
|
62
|
+
:remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]
|
|
63
|
+
|
|
64
|
+
include Devise::DeprecatedConstantAccessor
|
|
65
|
+
deprecate_constant "BLACKLIST_FOR_SERIALIZATION", "Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION"
|
|
61
66
|
|
|
62
67
|
included do
|
|
63
|
-
class_attribute :devise_modules, :
|
|
68
|
+
class_attribute :devise_modules, instance_writer: false
|
|
64
69
|
self.devise_modules ||= []
|
|
65
70
|
|
|
66
71
|
before_validation :downcase_keys
|
|
@@ -96,29 +101,31 @@ module Devise
|
|
|
96
101
|
def authenticatable_salt
|
|
97
102
|
end
|
|
98
103
|
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
104
|
+
# Redefine serializable_hash in models for more secure defaults.
|
|
105
|
+
# By default, it removes from the serializable model all attributes that
|
|
106
|
+
# are *not* accessible. You can remove this default by using :force_except
|
|
107
|
+
# and passing a new list of attributes you want to exempt. All attributes
|
|
108
|
+
# given to :except will simply add names to exempt to Devise internal list.
|
|
109
|
+
def serializable_hash(options = nil)
|
|
110
|
+
options = options.try(:dup) || {}
|
|
111
|
+
options[:except] = Array(options[:except]).dup
|
|
112
|
+
|
|
113
|
+
if options[:force_except]
|
|
114
|
+
options[:except].concat Array(options[:force_except])
|
|
115
|
+
else
|
|
116
|
+
options[:except].concat UNSAFE_ATTRIBUTES_FOR_SERIALIZATION
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
super(options)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Redefine inspect using serializable_hash, to ensure we don't accidentally
|
|
123
|
+
# leak passwords into exceptions.
|
|
124
|
+
def inspect
|
|
125
|
+
inspection = serializable_hash.collect do |k,v|
|
|
126
|
+
"#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
|
|
127
|
+
end
|
|
128
|
+
"#<#{self.class} #{inspection.join(", ")}>"
|
|
122
129
|
end
|
|
123
130
|
|
|
124
131
|
protected
|
|
@@ -128,70 +135,97 @@ module Devise
|
|
|
128
135
|
end
|
|
129
136
|
|
|
130
137
|
# This is an internal method called every time Devise needs
|
|
131
|
-
# to send a notification/mail. This can be
|
|
138
|
+
# to send a notification/mail. This can be overridden if you
|
|
132
139
|
# need to customize the e-mail delivery logic. For instance,
|
|
133
|
-
# if you are using a queue to deliver e-mails (
|
|
134
|
-
# sidekiq, resque, etc), you must add the delivery to the queue
|
|
140
|
+
# if you are using a queue to deliver e-mails (active job, delayed
|
|
141
|
+
# job, sidekiq, resque, etc), you must add the delivery to the queue
|
|
135
142
|
# just after the transaction was committed. To achieve this,
|
|
136
143
|
# you can override send_devise_notification to store the
|
|
137
|
-
# deliveries until the after_commit callback is triggered
|
|
144
|
+
# deliveries until the after_commit callback is triggered.
|
|
145
|
+
#
|
|
146
|
+
# The following example uses Active Job's `deliver_later` :
|
|
138
147
|
#
|
|
139
148
|
# class User
|
|
140
149
|
# devise :database_authenticatable, :confirmable
|
|
141
150
|
#
|
|
142
|
-
# after_commit :
|
|
151
|
+
# after_commit :send_pending_devise_notifications
|
|
143
152
|
#
|
|
144
153
|
# protected
|
|
145
154
|
#
|
|
146
|
-
# def send_devise_notification(notification,
|
|
147
|
-
# #
|
|
155
|
+
# def send_devise_notification(notification, *args)
|
|
156
|
+
# # If the record is new or changed then delay the
|
|
148
157
|
# # delivery until the after_commit callback otherwise
|
|
149
158
|
# # send now because after_commit will not be called.
|
|
150
|
-
#
|
|
151
|
-
#
|
|
159
|
+
# # For Rails < 6 use `changed?` instead of `saved_changes?`.
|
|
160
|
+
# if new_record? || saved_changes?
|
|
161
|
+
# pending_devise_notifications << [notification, args]
|
|
152
162
|
# else
|
|
153
|
-
#
|
|
163
|
+
# render_and_send_devise_message(notification, *args)
|
|
154
164
|
# end
|
|
155
165
|
# end
|
|
156
166
|
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
#
|
|
167
|
+
# private
|
|
168
|
+
#
|
|
169
|
+
# def send_pending_devise_notifications
|
|
170
|
+
# pending_devise_notifications.each do |notification, args|
|
|
171
|
+
# render_and_send_devise_message(notification, *args)
|
|
160
172
|
# end
|
|
161
173
|
#
|
|
162
174
|
# # Empty the pending notifications array because the
|
|
163
175
|
# # after_commit hook can be called multiple times which
|
|
164
176
|
# # could cause multiple emails to be sent.
|
|
165
|
-
#
|
|
177
|
+
# pending_devise_notifications.clear
|
|
166
178
|
# end
|
|
167
179
|
#
|
|
168
|
-
# def
|
|
169
|
-
# @
|
|
180
|
+
# def pending_devise_notifications
|
|
181
|
+
# @pending_devise_notifications ||= []
|
|
170
182
|
# end
|
|
183
|
+
#
|
|
184
|
+
# def render_and_send_devise_message(notification, *args)
|
|
185
|
+
# message = devise_mailer.send(notification, self, *args)
|
|
186
|
+
#
|
|
187
|
+
# # Deliver later with Active Job's `deliver_later`
|
|
188
|
+
# if message.respond_to?(:deliver_later)
|
|
189
|
+
# 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
|
+
# else
|
|
194
|
+
# message.deliver
|
|
195
|
+
# end
|
|
196
|
+
# end
|
|
197
|
+
#
|
|
171
198
|
# end
|
|
172
199
|
#
|
|
173
|
-
def send_devise_notification(notification,
|
|
174
|
-
devise_mailer.send(notification, self,
|
|
200
|
+
def send_devise_notification(notification, *args)
|
|
201
|
+
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
|
|
175
208
|
end
|
|
176
209
|
|
|
177
210
|
def downcase_keys
|
|
178
|
-
self.class.case_insensitive_keys.each { |k| apply_to_attribute_or_variable(k, :downcase
|
|
211
|
+
self.class.case_insensitive_keys.each { |k| apply_to_attribute_or_variable(k, :downcase) }
|
|
179
212
|
end
|
|
180
213
|
|
|
181
214
|
def strip_whitespace
|
|
182
|
-
self.class.strip_whitespace_keys.each { |k| apply_to_attribute_or_variable(k, :strip
|
|
215
|
+
self.class.strip_whitespace_keys.each { |k| apply_to_attribute_or_variable(k, :strip) }
|
|
183
216
|
end
|
|
184
217
|
|
|
185
218
|
def apply_to_attribute_or_variable(attr, method)
|
|
186
219
|
if self[attr]
|
|
187
|
-
self[attr].try(method)
|
|
220
|
+
self[attr] = self[attr].try(method)
|
|
188
221
|
|
|
189
222
|
# Use respond_to? here to avoid a regression where globally
|
|
190
223
|
# configured strip_whitespace_keys or case_insensitive_keys were
|
|
191
|
-
# attempting to strip
|
|
224
|
+
# attempting to strip or downcase when a model didn't have the
|
|
192
225
|
# globally configured key.
|
|
193
|
-
elsif respond_to?(attr)
|
|
194
|
-
send(attr).try(method)
|
|
226
|
+
elsif respond_to?(attr) && respond_to?("#{attr}=")
|
|
227
|
+
new_value = send(attr).try(method)
|
|
228
|
+
send("#{attr}=", new_value)
|
|
195
229
|
end
|
|
196
230
|
end
|
|
197
231
|
|
|
@@ -231,46 +265,42 @@ module Devise
|
|
|
231
265
|
# Example:
|
|
232
266
|
#
|
|
233
267
|
# def self.find_for_authentication(tainted_conditions)
|
|
234
|
-
# find_first_by_auth_conditions(tainted_conditions, :
|
|
268
|
+
# find_first_by_auth_conditions(tainted_conditions, active: true)
|
|
235
269
|
# end
|
|
236
270
|
#
|
|
237
271
|
# Finally, notice that Devise also queries for users in other scenarios
|
|
238
|
-
# besides authentication, for example when retrieving
|
|
272
|
+
# besides authentication, for example when retrieving a user to send
|
|
239
273
|
# an e-mail for password reset. In such cases, find_for_authentication
|
|
240
274
|
# is not called.
|
|
241
275
|
def find_for_authentication(tainted_conditions)
|
|
242
276
|
find_first_by_auth_conditions(tainted_conditions)
|
|
243
277
|
end
|
|
244
278
|
|
|
245
|
-
def find_first_by_auth_conditions(tainted_conditions, opts={})
|
|
279
|
+
def find_first_by_auth_conditions(tainted_conditions, opts = {})
|
|
246
280
|
to_adapter.find_first(devise_parameter_filter.filter(tainted_conditions).merge(opts))
|
|
247
281
|
end
|
|
248
282
|
|
|
249
|
-
# Find
|
|
250
|
-
def find_or_initialize_with_error_by(attribute, value, error
|
|
283
|
+
# Find or initialize a record setting an error if it can't be found.
|
|
284
|
+
def find_or_initialize_with_error_by(attribute, value, error = :invalid) #:nodoc:
|
|
251
285
|
find_or_initialize_with_errors([attribute], { attribute => value }, error)
|
|
252
286
|
end
|
|
253
287
|
|
|
254
|
-
# Find
|
|
255
|
-
def find_or_initialize_with_errors(required_attributes, attributes, error
|
|
256
|
-
attributes
|
|
257
|
-
attributes
|
|
288
|
+
# Find or initialize a record with group of attributes based on a list of required attributes.
|
|
289
|
+
def find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) #:nodoc:
|
|
290
|
+
attributes.try(:permit!)
|
|
291
|
+
attributes = attributes.to_h.with_indifferent_access
|
|
292
|
+
.slice(*required_attributes)
|
|
293
|
+
.delete_if { |key, value| value.blank? }
|
|
258
294
|
|
|
259
295
|
if attributes.size == required_attributes.size
|
|
260
|
-
record = find_first_by_auth_conditions(attributes)
|
|
296
|
+
record = find_first_by_auth_conditions(attributes) and return record
|
|
261
297
|
end
|
|
262
298
|
|
|
263
|
-
|
|
264
|
-
record = new
|
|
265
|
-
|
|
299
|
+
new(devise_parameter_filter.filter(attributes)).tap do |record|
|
|
266
300
|
required_attributes.each do |key|
|
|
267
|
-
|
|
268
|
-
record.send("#{key}=", value)
|
|
269
|
-
record.errors.add(key, value.present? ? error : :blank)
|
|
301
|
+
record.errors.add(key, attributes[key].blank? ? :blank : error)
|
|
270
302
|
end
|
|
271
303
|
end
|
|
272
|
-
|
|
273
|
-
record
|
|
274
304
|
end
|
|
275
305
|
|
|
276
306
|
protected
|
|
@@ -278,14 +308,6 @@ module Devise
|
|
|
278
308
|
def devise_parameter_filter
|
|
279
309
|
@devise_parameter_filter ||= Devise::ParameterFilter.new(case_insensitive_keys, strip_whitespace_keys)
|
|
280
310
|
end
|
|
281
|
-
|
|
282
|
-
# Generate a token by looping and ensuring does not already exist.
|
|
283
|
-
def generate_token(column)
|
|
284
|
-
loop do
|
|
285
|
-
token = Devise.friendly_token
|
|
286
|
-
break token unless to_adapter.find_first({ column => token })
|
|
287
|
-
end
|
|
288
|
-
end
|
|
289
311
|
end
|
|
290
312
|
end
|
|
291
313
|
end
|