devise 3.5.2 → 4.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +259 -1086
- data/MIT-LICENSE +1 -1
- data/README.md +254 -67
- data/app/controllers/devise/confirmations_controller.rb +3 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +8 -6
- data/app/controllers/devise/passwords_controller.rb +8 -4
- data/app/controllers/devise/registrations_controller.rb +39 -18
- data/app/controllers/devise/sessions_controller.rb +9 -7
- data/app/controllers/devise/unlocks_controller.rb +4 -2
- data/app/controllers/devise_controller.rb +23 -10
- data/app/helpers/devise_helper.rb +12 -19
- data/app/mailers/devise/mailer.rb +10 -0
- data/app/views/devise/confirmations/new.html.erb +2 -2
- 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/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +9 -5
- data/app/views/devise/registrations/new.html.erb +4 -4
- data/app/views/devise/sessions/new.html.erb +4 -4
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +8 -8
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +6 -1
- data/lib/devise/controllers/helpers.rb +35 -26
- data/lib/devise/controllers/rememberable.rb +11 -2
- data/lib/devise/controllers/scoped_views.rb +2 -0
- data/lib/devise/controllers/sign_in_out.rb +34 -11
- data/lib/devise/controllers/store_location.rb +25 -7
- data/lib/devise/controllers/url_helpers.rb +2 -0
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +6 -4
- data/lib/devise/failure_app.rb +84 -32
- data/lib/devise/hooks/activatable.rb +2 -0
- data/lib/devise/hooks/csrf_cleaner.rb +2 -0
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +6 -1
- data/lib/devise/hooks/proxy.rb +3 -1
- data/lib/devise/hooks/rememberable.rb +2 -0
- data/lib/devise/hooks/timeoutable.rb +7 -3
- data/lib/devise/hooks/trackable.rb +2 -0
- data/lib/devise/mailers/helpers.rb +7 -4
- data/lib/devise/mapping.rb +2 -0
- data/lib/devise/models/authenticatable.rb +51 -26
- data/lib/devise/models/confirmable.rb +89 -27
- data/lib/devise/models/database_authenticatable.rb +97 -20
- data/lib/devise/models/lockable.rb +15 -5
- data/lib/devise/models/omniauthable.rb +2 -0
- data/lib/devise/models/recoverable.rb +32 -24
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +42 -26
- data/lib/devise/models/timeoutable.rb +2 -6
- data/lib/devise/models/trackable.rb +15 -1
- data/lib/devise/models/validatable.rb +10 -3
- data/lib/devise/models.rb +3 -1
- data/lib/devise/modules.rb +2 -0
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/omniauth.rb +2 -0
- 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 +139 -65
- data/lib/devise/rails/routes.rb +59 -34
- data/lib/devise/rails/warden_compat.rb +3 -10
- data/lib/devise/rails.rb +7 -16
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +4 -2
- data/lib/devise/strategies/base.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +11 -4
- data/lib/devise/strategies/rememberable.rb +5 -6
- data/lib/devise/test/controller_helpers.rb +165 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -124
- data/lib/devise/time_inflector.rb +2 -0
- data/lib/devise/token_generator.rb +3 -41
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +72 -42
- data/lib/generators/active_record/devise_generator.rb +29 -10
- data/lib/generators/active_record/templates/migration.rb +4 -2
- data/lib/generators/active_record/templates/migration_existing.rb +4 -2
- data/lib/generators/devise/controllers_generator.rb +3 -1
- data/lib/generators/devise/devise_generator.rb +4 -2
- data/lib/generators/devise/install_generator.rb +17 -0
- data/lib/generators/devise/orm_helpers.rb +10 -21
- data/lib/generators/devise/views_generator.rb +21 -11
- data/lib/generators/mongoid/devise_generator.rb +7 -5
- data/lib/generators/templates/README +1 -8
- data/lib/generators/templates/controllers/confirmations_controller.rb +2 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +2 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +2 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +6 -4
- data/lib/generators/templates/controllers/sessions_controller.rb +4 -2
- data/lib/generators/templates/controllers/unlocks_controller.rb +2 -0
- data/lib/generators/templates/devise.rb +52 -19
- 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 +5 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
- metadata +27 -313
- data/.gitignore +0 -10
- data/.travis.yml +0 -45
- data/.yardopts +0 -9
- data/CONTRIBUTING.md +0 -14
- data/Gemfile +0 -29
- data/Gemfile.lock +0 -183
- data/Rakefile +0 -36
- data/devise.gemspec +0 -27
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +0 -29
- data/gemfiles/Gemfile.rails-3.2-stable.lock +0 -169
- data/gemfiles/Gemfile.rails-4.0-stable +0 -29
- data/gemfiles/Gemfile.rails-4.0-stable.lock +0 -163
- data/gemfiles/Gemfile.rails-4.1-stable +0 -29
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -169
- data/gemfiles/Gemfile.rails-4.2-stable +0 -29
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -191
- data/script/cached-bundle +0 -49
- data/script/s3-put +0 -71
- data/test/controllers/custom_registrations_controller_test.rb +0 -40
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helpers_test.rb +0 -316
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -51
- data/test/controllers/internal_helpers_test.rb +0 -129
- data/test/controllers/load_hooks_controller_test.rb +0 -19
- data/test/controllers/passwords_controller_test.rb +0 -31
- data/test/controllers/sessions_controller_test.rb +0 -103
- data/test/controllers/url_helpers_test.rb +0 -65
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -107
- data/test/failure_app_test.rb +0 -298
- data/test/generators/active_record_generator_test.rb +0 -109
- data/test/generators/controllers_generator_test.rb +0 -48
- 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 -96
- data/test/helpers/devise_helper_test.rb +0 -49
- data/test/integration/authenticatable_test.rb +0 -729
- data/test/integration/confirmable_test.rb +0 -324
- data/test/integration/database_authenticatable_test.rb +0 -95
- data/test/integration/http_authenticatable_test.rb +0 -105
- data/test/integration/lockable_test.rb +0 -239
- data/test/integration/omniauthable_test.rb +0 -133
- data/test/integration/recoverable_test.rb +0 -347
- data/test/integration/registerable_test.rb +0 -359
- data/test/integration/rememberable_test.rb +0 -176
- data/test/integration/timeoutable_test.rb +0 -172
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -115
- data/test/mailers/reset_password_instructions_test.rb +0 -96
- data/test/mailers/unlock_instructions_test.rb +0 -91
- data/test/mapping_test.rb +0 -134
- data/test/models/authenticatable_test.rb +0 -23
- data/test/models/confirmable_test.rb +0 -479
- data/test/models/database_authenticatable_test.rb +0 -249
- data/test/models/lockable_test.rb +0 -328
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -228
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -204
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -51
- data/test/models/trackable_test.rb +0 -41
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -144
- 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 -81
- 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/active_record/user_on_engine.rb +0 -7
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -7
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -6
- data/test/rails_app/app/controllers/application_controller.rb +0 -12
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -30
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -31
- 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/from_proc_mailer.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -3
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -4
- 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 -39
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -39
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -39
- 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 -14
- 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 -30
- data/test/rails_app/config/environments/production.rb +0 -84
- data/test/rails_app/config/environments/test.rb +0 -41
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -180
- 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 -120
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
- data/test/rails_app/db/schema.rb +0 -55
- data/test/rails_app/lib/shared_admin.rb +0 -17
- data/test/rails_app/lib/shared_user.rb +0 -29
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -13
- 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/rails_test.rb +0 -9
- data/test/routes_test.rb +0 -264
- data/test/support/action_controller/record_identifier.rb +0 -10
- data/test/support/assertions.rb +0 -39
- data/test/support/helpers.rb +0 -73
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -24
- data/test/test_helper.rb +0 -34
- data/test/test_helpers_test.rb +0 -178
- data/test/test_models.rb +0 -33
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Models
|
3
5
|
|
@@ -16,10 +18,6 @@ module Devise
|
|
16
18
|
# # resets the user password and save the record, true if valid passwords are given, otherwise false
|
17
19
|
# User.find(1).reset_password('password123', 'password123')
|
18
20
|
#
|
19
|
-
# # only resets the user password, without saving the record
|
20
|
-
# user = User.find(1)
|
21
|
-
# user.reset_password('password123', 'password123')
|
22
|
-
#
|
23
21
|
# # creates a new token and send it with instructions about how to reset the password
|
24
22
|
# User.find(1).send_reset_password_instructions
|
25
23
|
#
|
@@ -31,30 +29,20 @@ module Devise
|
|
31
29
|
end
|
32
30
|
|
33
31
|
included do
|
34
|
-
|
35
|
-
if email_changed? || encrypted_password_changed?
|
36
|
-
clear_reset_password_token
|
37
|
-
end
|
38
|
-
end
|
32
|
+
before_update :clear_reset_password_token, if: :clear_reset_password_token?
|
39
33
|
end
|
40
34
|
|
41
35
|
# Update password saving the record and clearing token. Returns true if
|
42
36
|
# the passwords are valid and the record was saved, false otherwise.
|
43
37
|
def reset_password(new_password, new_password_confirmation)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
38
|
+
if new_password.present?
|
39
|
+
self.password = new_password
|
40
|
+
self.password_confirmation = new_password_confirmation
|
41
|
+
save
|
42
|
+
else
|
43
|
+
errors.add(:password, :blank)
|
44
|
+
false
|
50
45
|
end
|
51
|
-
|
52
|
-
save
|
53
|
-
end
|
54
|
-
|
55
|
-
def reset_password!(new_password, new_password_confirmation)
|
56
|
-
ActiveSupport::Deprecation.warn "reset_password! is deprecated in favor of reset_password"
|
57
|
-
reset_password(new_password, new_password_confirmation)
|
58
46
|
end
|
59
47
|
|
60
48
|
# Resets reset password token and send reset password instructions by email.
|
@@ -87,7 +75,7 @@ module Devise
|
|
87
75
|
# reset_password_period_valid? # will always return false
|
88
76
|
#
|
89
77
|
def reset_password_period_valid?
|
90
|
-
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago
|
78
|
+
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago.utc
|
91
79
|
end
|
92
80
|
|
93
81
|
protected
|
@@ -103,7 +91,7 @@ module Devise
|
|
103
91
|
|
104
92
|
self.reset_password_token = enc
|
105
93
|
self.reset_password_sent_at = Time.now.utc
|
106
|
-
|
94
|
+
save(validate: false)
|
107
95
|
raw
|
108
96
|
end
|
109
97
|
|
@@ -111,6 +99,26 @@ module Devise
|
|
111
99
|
send_devise_notification(:reset_password_instructions, token, {})
|
112
100
|
end
|
113
101
|
|
102
|
+
if Devise.activerecord51?
|
103
|
+
def clear_reset_password_token?
|
104
|
+
encrypted_password_changed = respond_to?(:will_save_change_to_encrypted_password?) && will_save_change_to_encrypted_password?
|
105
|
+
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
|
106
|
+
respond_to?("will_save_change_to_#{attribute}?") && send("will_save_change_to_#{attribute}?")
|
107
|
+
end
|
108
|
+
|
109
|
+
authentication_keys_changed || encrypted_password_changed
|
110
|
+
end
|
111
|
+
else
|
112
|
+
def clear_reset_password_token?
|
113
|
+
encrypted_password_changed = respond_to?(:encrypted_password_changed?) && encrypted_password_changed?
|
114
|
+
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
|
115
|
+
respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?")
|
116
|
+
end
|
117
|
+
|
118
|
+
authentication_keys_changed || encrypted_password_changed
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
114
122
|
module ClassMethods
|
115
123
|
# Attempt to find a user by password reset token. If a user is found, return it
|
116
124
|
# If a user is not found, return nil
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Models
|
3
5
|
# Registerable is responsible for everything related to registering a new
|
@@ -19,6 +21,8 @@ module Devise
|
|
19
21
|
def new_with_session(params, session)
|
20
22
|
new(params)
|
21
23
|
end
|
24
|
+
|
25
|
+
Devise::Models.config(self, :sign_in_after_change_password)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'devise/strategies/rememberable'
|
2
4
|
require 'devise/hooks/rememberable'
|
3
5
|
require 'devise/hooks/forgetable'
|
4
6
|
|
5
7
|
module Devise
|
6
8
|
module Models
|
7
|
-
# Rememberable manages generating and clearing token for
|
9
|
+
# Rememberable manages generating and clearing token for remembering the user
|
8
10
|
# from a saved cookie. Rememberable also has utility methods for dealing
|
9
11
|
# with serializing the user into the cookie and back from the cookie, trying
|
10
12
|
# to lookup the record based on the saved information.
|
@@ -39,17 +41,15 @@ module Devise
|
|
39
41
|
module Rememberable
|
40
42
|
extend ActiveSupport::Concern
|
41
43
|
|
42
|
-
attr_accessor :remember_me
|
44
|
+
attr_accessor :remember_me
|
43
45
|
|
44
46
|
def self.required_fields(klass)
|
45
47
|
[:remember_created_at]
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
self.remember_token = self.class.remember_token if generate_remember_token?
|
52
|
-
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
|
50
|
+
def remember_me!
|
51
|
+
self.remember_token ||= self.class.remember_token if respond_to?(:remember_token)
|
52
|
+
self.remember_created_at ||= Time.now.utc
|
53
53
|
save(validate: false) if self.changed?
|
54
54
|
end
|
55
55
|
|
@@ -57,19 +57,17 @@ module Devise
|
|
57
57
|
# it exists), and save the record without validations.
|
58
58
|
def forget_me!
|
59
59
|
return unless persisted?
|
60
|
-
self.remember_token = nil if respond_to?(:remember_token
|
60
|
+
self.remember_token = nil if respond_to?(:remember_token)
|
61
61
|
self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out
|
62
62
|
save(validate: false)
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
remember_created_at.nil? || (remember_expires_at <= Time.now.utc)
|
65
|
+
def remember_expires_at
|
66
|
+
self.class.remember_for.from_now
|
68
67
|
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
remember_created_at + self.class.remember_for
|
69
|
+
def extend_remember_period
|
70
|
+
self.class.extend_remember_period
|
73
71
|
end
|
74
72
|
|
75
73
|
def rememberable_value
|
@@ -78,7 +76,7 @@ module Devise
|
|
78
76
|
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt.presence)
|
79
77
|
salt
|
80
78
|
else
|
81
|
-
raise "
|
79
|
+
raise "authenticatable_salt returned nil for the #{self.class.name} model. " \
|
82
80
|
"In order to use rememberable, you must ensure a password is always set " \
|
83
81
|
"or have a remember_token column in your model or implement your own " \
|
84
82
|
"rememberable_value in the model with custom logic."
|
@@ -102,29 +100,47 @@ module Devise
|
|
102
100
|
def after_remembered
|
103
101
|
end
|
104
102
|
|
105
|
-
|
103
|
+
def remember_me?(token, generated_at)
|
104
|
+
# TODO: Normalize the JSON type coercion along with the Timeoutable hook
|
105
|
+
# in a single place https://github.com/plataformatec/devise/blob/ffe9d6d406e79108cf32a2c6a1d0b3828849c40b/lib/devise/hooks/timeoutable.rb#L14-L18
|
106
|
+
if generated_at.is_a?(String)
|
107
|
+
generated_at = time_from_json(generated_at)
|
108
|
+
end
|
106
109
|
|
107
|
-
|
108
|
-
|
110
|
+
# The token is only valid if:
|
111
|
+
# 1. we have a date
|
112
|
+
# 2. the current time does not pass the expiry period
|
113
|
+
# 3. the record has a remember_created_at date
|
114
|
+
# 4. the token date is bigger than the remember_created_at
|
115
|
+
# 5. the token matches
|
116
|
+
generated_at.is_a?(Time) &&
|
117
|
+
(self.class.remember_for.ago < generated_at) &&
|
118
|
+
(generated_at > (remember_created_at || Time.now).utc) &&
|
119
|
+
Devise.secure_compare(rememberable_value, token)
|
109
120
|
end
|
110
121
|
|
111
|
-
|
112
|
-
|
113
|
-
def
|
114
|
-
|
122
|
+
private
|
123
|
+
|
124
|
+
def time_from_json(value)
|
125
|
+
if value =~ /\A\d+\.\d+\Z/
|
126
|
+
Time.at(value.to_f)
|
127
|
+
else
|
128
|
+
Time.parse(value) rescue nil
|
129
|
+
end
|
115
130
|
end
|
116
131
|
|
117
132
|
module ClassMethods
|
118
133
|
# Create the cookie key using the record id and remember_token
|
119
134
|
def serialize_into_cookie(record)
|
120
|
-
[record.to_key, record.rememberable_value]
|
135
|
+
[record.to_key, record.rememberable_value, Time.now.utc.to_f.to_s]
|
121
136
|
end
|
122
137
|
|
123
138
|
# Recreate the user based on the stored cookie
|
124
|
-
def serialize_from_cookie(
|
139
|
+
def serialize_from_cookie(*args)
|
140
|
+
id, token, generated_at = *args
|
141
|
+
|
125
142
|
record = to_adapter.get(id)
|
126
|
-
record if record &&
|
127
|
-
Devise.secure_compare(record.rememberable_value, remember_token)
|
143
|
+
record if record && record.remember_me?(token, generated_at)
|
128
144
|
end
|
129
145
|
|
130
146
|
# Generate a token checking if one does not already exist in the database.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'devise/hooks/timeoutable'
|
2
4
|
|
3
5
|
module Devise
|
@@ -26,7 +28,6 @@ module Devise
|
|
26
28
|
|
27
29
|
# Checks whether the user session has expired based on configured time.
|
28
30
|
def timedout?(last_access)
|
29
|
-
return false if remember_exists_and_not_expired?
|
30
31
|
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
31
32
|
end
|
32
33
|
|
@@ -36,11 +37,6 @@ module Devise
|
|
36
37
|
|
37
38
|
private
|
38
39
|
|
39
|
-
def remember_exists_and_not_expired?
|
40
|
-
return false unless respond_to?(:remember_created_at) && respond_to?(:remember_expired?)
|
41
|
-
remember_created_at && !remember_expired?
|
42
|
-
end
|
43
|
-
|
44
40
|
module ClassMethods
|
45
41
|
Devise::Models.config(self, :timeout_in)
|
46
42
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'devise/hooks/trackable'
|
2
4
|
|
3
5
|
module Devise
|
@@ -20,7 +22,7 @@ module Devise
|
|
20
22
|
self.last_sign_in_at = old_current || new_current
|
21
23
|
self.current_sign_in_at = new_current
|
22
24
|
|
23
|
-
old_current, new_current = self.current_sign_in_ip, request
|
25
|
+
old_current, new_current = self.current_sign_in_ip, extract_ip_from(request)
|
24
26
|
self.last_sign_in_ip = old_current || new_current
|
25
27
|
self.current_sign_in_ip = new_current
|
26
28
|
|
@@ -29,9 +31,21 @@ module Devise
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def update_tracked_fields!(request)
|
34
|
+
# We have to check if the user is already persisted before running
|
35
|
+
# `save` here because invalid users can be saved if we don't.
|
36
|
+
# See https://github.com/plataformatec/devise/issues/4673 for more details.
|
37
|
+
return if new_record?
|
38
|
+
|
32
39
|
update_tracked_fields(request)
|
33
40
|
save(validate: false)
|
34
41
|
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def extract_ip_from(request)
|
46
|
+
request.remote_ip
|
47
|
+
end
|
48
|
+
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Models
|
3
5
|
# Validatable creates all needed validations for a user email and password.
|
@@ -10,7 +12,7 @@ module Devise
|
|
10
12
|
# Validatable adds the following options to devise_for:
|
11
13
|
#
|
12
14
|
# * +email_regexp+: the regular expression used to validate e-mails;
|
13
|
-
# * +password_length+: a range expressing password length. Defaults to
|
15
|
+
# * +password_length+: a range expressing password length. Defaults to 6..128.
|
14
16
|
#
|
15
17
|
module Validatable
|
16
18
|
# All validations used by this module.
|
@@ -27,8 +29,13 @@ module Devise
|
|
27
29
|
|
28
30
|
base.class_eval do
|
29
31
|
validates_presence_of :email, if: :email_required?
|
30
|
-
|
31
|
-
|
32
|
+
if Devise.activerecord51?
|
33
|
+
validates_uniqueness_of :email, allow_blank: true, case_sensitive: true, if: :will_save_change_to_email?
|
34
|
+
validates_format_of :email, with: email_regexp, allow_blank: true, if: :will_save_change_to_email?
|
35
|
+
else
|
36
|
+
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
|
37
|
+
validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
|
38
|
+
end
|
32
39
|
|
33
40
|
validates_presence_of :password, if: :password_required?
|
34
41
|
validates_confirmation_of :password, if: :password_required?
|
data/lib/devise/models.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Models
|
3
5
|
class MissingAttribute < StandardError
|
@@ -12,7 +14,7 @@ module Devise
|
|
12
14
|
|
13
15
|
# Creates configuration values for Devise and for the given module.
|
14
16
|
#
|
15
|
-
# Devise::Models.config(Devise::
|
17
|
+
# Devise::Models.config(Devise::Models::DatabaseAuthenticatable, :stretches)
|
16
18
|
#
|
17
19
|
# The line above creates:
|
18
20
|
#
|
data/lib/devise/modules.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module OmniAuth
|
3
5
|
module UrlHelpers
|
4
|
-
def
|
6
|
+
def omniauth_authorize_path(resource_or_scope, provider, *args)
|
7
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
8
|
+
_devise_route_context.send("#{scope}_#{provider}_omniauth_authorize_path", *args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def omniauth_authorize_url(resource_or_scope, provider, *args)
|
12
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
13
|
+
_devise_route_context.send("#{scope}_#{provider}_omniauth_authorize_url", *args)
|
5
14
|
end
|
6
15
|
|
7
|
-
def
|
16
|
+
def omniauth_callback_path(resource_or_scope, provider, *args)
|
8
17
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
9
|
-
_devise_route_context.send("#{scope}
|
18
|
+
_devise_route_context.send("#{scope}_#{provider}_omniauth_callback_path", *args)
|
10
19
|
end
|
11
20
|
|
12
|
-
def
|
21
|
+
def omniauth_callback_url(resource_or_scope, provider, *args)
|
13
22
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
14
|
-
_devise_route_context.send("#{scope}
|
23
|
+
_devise_route_context.send("#{scope}_#{provider}_omniauth_callback_url", *args)
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
data/lib/devise/omniauth.rb
CHANGED
data/lib/devise/orm/mongoid.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
ActiveSupport.on_load(:mongoid) do
|
4
|
+
require 'orm_adapter/adapters/mongoid'
|
5
|
+
|
6
|
+
Mongoid::Document::ClassMethods.send :include, Devise::Models
|
7
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
class ParameterFilter
|
3
5
|
def initialize(case_insensitive_keys, strip_whitespace_keys)
|
@@ -16,6 +18,8 @@ module Devise
|
|
16
18
|
|
17
19
|
def filtered_hash_by_method_for_given_keys(conditions, method, condition_keys)
|
18
20
|
condition_keys.each do |k|
|
21
|
+
next unless conditions.key?(k)
|
22
|
+
|
19
23
|
value = conditions[k]
|
20
24
|
conditions[k] = value.send(method) if value.respond_to?(method)
|
21
25
|
end
|