devise 1.5.4 → 2.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/.gitignore +0 -2
- data/CHANGELOG.rdoc +18 -7
- data/Gemfile.lock +168 -0
- data/README.rdoc +2 -0
- data/app/controllers/devise/registrations_controller.rb +6 -1
- data/app/controllers/devise/unlocks_controller.rb +1 -2
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/lib/devise.rb +41 -22
- data/lib/devise/controllers/internal_helpers.rb +9 -2
- data/lib/devise/models/authenticatable.rb +30 -12
- data/lib/devise/models/confirmable.rb +73 -18
- data/lib/devise/models/database_authenticatable.rb +0 -11
- data/lib/devise/models/recoverable.rb +5 -5
- data/lib/devise/models/rememberable.rb +5 -20
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +1 -4
- data/lib/devise/models/validatable.rb +1 -1
- data/lib/devise/orm/active_record.rb +6 -0
- data/lib/devise/param_filter.rb +2 -1
- data/lib/devise/rails.rb +31 -0
- data/lib/devise/schema.rb +5 -0
- data/lib/devise/strategies/authenticatable.rb +12 -8
- data/lib/devise/strategies/token_authenticatable.rb +3 -3
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +40 -2
- data/lib/generators/active_record/templates/migration.rb +1 -9
- data/lib/generators/active_record/templates/migration_existing.rb +1 -9
- data/lib/generators/mongoid/devise_generator.rb +43 -0
- data/lib/generators/templates/devise.rb +15 -9
- data/test/controllers/internal_helpers_test.rb +4 -2
- data/test/devise_test.rb +2 -2
- data/test/integration/confirmable_test.rb +55 -3
- data/test/integration/http_authenticatable_test.rb +16 -1
- data/test/integration/lockable_test.rb +3 -3
- data/test/integration/registerable_test.rb +32 -1
- data/test/integration/rememberable_test.rb +0 -50
- data/test/integration/token_authenticatable_test.rb +2 -2
- data/test/integration/trackable_test.rb +1 -1
- data/test/mapping_test.rb +2 -3
- data/test/models/confirmable_test.rb +86 -8
- data/test/models/database_authenticatable_test.rb +6 -6
- data/test/models/encryptable_test.rb +1 -1
- data/test/models/recoverable_test.rb +0 -27
- data/test/models/rememberable_test.rb +41 -160
- data/test/models/serializable_test.rb +1 -1
- data/test/models_test.rb +7 -7
- data/test/rails_app/app/mongoid/admin.rb +22 -1
- data/test/rails_app/app/mongoid/user.rb +35 -0
- data/test/rails_app/config/initializers/devise.rb +6 -7
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
- data/test/rails_app/lib/shared_admin.rb +5 -2
- data/test/support/assertions.rb +4 -1
- data/test/support/integration.rb +3 -1
- data/test/test_helpers_test.rb +2 -2
- metadata +21 -39
- data/test/models/authenticatable_test.rb +0 -9
- data/test/schema_test.rb +0 -33
@@ -9,11 +9,16 @@ module Devise
|
|
9
9
|
#
|
10
10
|
# Confirmable adds the following options to devise_for:
|
11
11
|
#
|
12
|
-
# * +
|
12
|
+
# * +allow_unconfirmed_access_for+: the time you want to allow the user to access his account
|
13
13
|
# before confirming it. After this period, the user access is denied. You can
|
14
14
|
# use this to let your user access some features of your application without
|
15
15
|
# confirming the account, but blocking it after a certain period (ie 7 days).
|
16
|
-
# By default
|
16
|
+
# By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.
|
17
|
+
# * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as
|
18
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
19
|
+
# db field to be setup (t.reconfirmable in migrations). Until confirmed new email is
|
20
|
+
# stored in unconfirmed email column, and copied to email column on successful
|
21
|
+
# confirmation.
|
17
22
|
#
|
18
23
|
# == Examples
|
19
24
|
#
|
@@ -27,15 +32,26 @@ module Devise
|
|
27
32
|
included do
|
28
33
|
before_create :generate_confirmation_token, :if => :confirmation_required?
|
29
34
|
after_create :send_confirmation_instructions, :if => :confirmation_required?
|
35
|
+
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
|
36
|
+
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
|
30
37
|
end
|
31
38
|
|
32
|
-
# Confirm a user by setting
|
33
|
-
# is already confirmed, add
|
39
|
+
# Confirm a user by setting it's confirmed_at to actual time. If the user
|
40
|
+
# is already confirmed, add an error to email field. If the user is invalid
|
41
|
+
# add errors
|
34
42
|
def confirm!
|
35
43
|
unless_confirmed do
|
36
44
|
self.confirmation_token = nil
|
37
45
|
self.confirmed_at = Time.now.utc
|
38
|
-
|
46
|
+
|
47
|
+
if self.class.reconfirmable
|
48
|
+
@bypass_postpone = true
|
49
|
+
self.email = unconfirmed_email if unconfirmed_email.present?
|
50
|
+
self.unconfirmed_email = nil
|
51
|
+
save
|
52
|
+
else
|
53
|
+
save(:validate => false)
|
54
|
+
end
|
39
55
|
end
|
40
56
|
end
|
41
57
|
|
@@ -44,9 +60,14 @@ module Devise
|
|
44
60
|
!!confirmed_at
|
45
61
|
end
|
46
62
|
|
63
|
+
def pending_reconfirmation?
|
64
|
+
self.class.reconfirmable && unconfirmed_email.present?
|
65
|
+
end
|
66
|
+
|
47
67
|
# Send confirmation instructions by email
|
48
68
|
def send_confirmation_instructions
|
49
|
-
|
69
|
+
@reconfirmation_required = false
|
70
|
+
generate_confirmation_token! if self.confirmation_token.blank?
|
50
71
|
self.devise_mailer.confirmation_instructions(self).deliver
|
51
72
|
end
|
52
73
|
|
@@ -74,6 +95,14 @@ module Devise
|
|
74
95
|
self.confirmed_at = Time.now.utc
|
75
96
|
end
|
76
97
|
|
98
|
+
def headers_for(action)
|
99
|
+
headers = super
|
100
|
+
if action == :confirmation_instructions && pending_reconfirmation?
|
101
|
+
headers[:to] = unconfirmed_email
|
102
|
+
end
|
103
|
+
headers
|
104
|
+
end
|
105
|
+
|
77
106
|
protected
|
78
107
|
|
79
108
|
# Callback to overwrite if confirmation is required or not.
|
@@ -88,26 +117,26 @@ module Devise
|
|
88
117
|
#
|
89
118
|
# Example:
|
90
119
|
#
|
91
|
-
# #
|
120
|
+
# # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
|
92
121
|
# confirmation_period_valid? # returns true
|
93
122
|
#
|
94
|
-
# #
|
123
|
+
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
|
95
124
|
# confirmation_period_valid? # returns true
|
96
125
|
#
|
97
|
-
# #
|
126
|
+
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
|
98
127
|
# confirmation_period_valid? # returns false
|
99
128
|
#
|
100
|
-
# #
|
129
|
+
# # allow_unconfirmed_access_for = 0.days
|
101
130
|
# confirmation_period_valid? # will always return false
|
102
131
|
#
|
103
132
|
def confirmation_period_valid?
|
104
|
-
confirmation_sent_at && confirmation_sent_at.utc >= self.class.
|
133
|
+
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
|
105
134
|
end
|
106
135
|
|
107
|
-
# Checks whether the record is confirmed or not, yielding to the block
|
136
|
+
# Checks whether the record is confirmed or not or a new email has been added, yielding to the block
|
108
137
|
# if it's already confirmed, otherwise adds an error to email.
|
109
138
|
def unless_confirmed
|
110
|
-
unless confirmed?
|
139
|
+
unless confirmed? && !pending_reconfirmation?
|
111
140
|
yield
|
112
141
|
else
|
113
142
|
self.errors.add(:email, :already_confirmed)
|
@@ -118,7 +147,6 @@ module Devise
|
|
118
147
|
# Generates a new random token for confirmation, and stores the time
|
119
148
|
# this token is being generated
|
120
149
|
def generate_confirmation_token
|
121
|
-
self.confirmed_at = nil
|
122
150
|
self.confirmation_token = self.class.confirmation_token
|
123
151
|
self.confirmation_sent_at = Time.now.utc
|
124
152
|
end
|
@@ -132,13 +160,32 @@ module Devise
|
|
132
160
|
confirm! unless confirmed?
|
133
161
|
end
|
134
162
|
|
163
|
+
def postpone_email_change_until_confirmation
|
164
|
+
@reconfirmation_required = true
|
165
|
+
self.unconfirmed_email = self.email
|
166
|
+
self.email = self.email_was
|
167
|
+
end
|
168
|
+
|
169
|
+
def postpone_email_change?
|
170
|
+
postpone = self.class.reconfirmable && email_changed? && !@bypass_postpone
|
171
|
+
@bypass_postpone = nil
|
172
|
+
postpone
|
173
|
+
end
|
174
|
+
|
175
|
+
def reconfirmation_required?
|
176
|
+
self.class.reconfirmable && @reconfirmation_required
|
177
|
+
end
|
178
|
+
|
135
179
|
module ClassMethods
|
136
180
|
# Attempt to find a user by its email. If a record is found, send new
|
137
|
-
# confirmation instructions to it. If not
|
138
|
-
# with an email not found error.
|
181
|
+
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
182
|
+
# field. If no user is found, returns a new user with an email not found error.
|
139
183
|
# Options must contain the user email
|
140
184
|
def send_confirmation_instructions(attributes={})
|
141
|
-
confirmable =
|
185
|
+
confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
|
186
|
+
unless confirmable.try(:persisted?)
|
187
|
+
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
|
188
|
+
end
|
142
189
|
confirmable.resend_confirmation_token if confirmable.persisted?
|
143
190
|
confirmable
|
144
191
|
end
|
@@ -158,7 +205,15 @@ module Devise
|
|
158
205
|
generate_token(:confirmation_token)
|
159
206
|
end
|
160
207
|
|
161
|
-
|
208
|
+
# Find a record for confirmation by unconfirmed email field
|
209
|
+
def find_by_unconfirmed_email_with_errors(attributes = {})
|
210
|
+
unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }
|
211
|
+
unconfirmed_attributes = attributes.symbolize_keys
|
212
|
+
unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)
|
213
|
+
find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
|
214
|
+
end
|
215
|
+
|
216
|
+
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable)
|
162
217
|
end
|
163
218
|
end
|
164
219
|
end
|
@@ -25,8 +25,6 @@ module Devise
|
|
25
25
|
included do
|
26
26
|
attr_reader :password, :current_password
|
27
27
|
attr_accessor :password_confirmation
|
28
|
-
before_validation :downcase_keys
|
29
|
-
before_validation :strip_whitespace
|
30
28
|
end
|
31
29
|
|
32
30
|
# Generates password encryption based on the given value.
|
@@ -103,15 +101,6 @@ module Devise
|
|
103
101
|
|
104
102
|
protected
|
105
103
|
|
106
|
-
# Downcase case-insensitive keys
|
107
|
-
def downcase_keys
|
108
|
-
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
|
109
|
-
end
|
110
|
-
|
111
|
-
def strip_whitespace
|
112
|
-
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
|
113
|
-
end
|
114
|
-
|
115
104
|
# Digests the password using bcrypt.
|
116
105
|
def password_digest(password)
|
117
106
|
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
|
@@ -29,6 +29,7 @@ module Devise
|
|
29
29
|
def reset_password!(new_password, new_password_confirmation)
|
30
30
|
self.password = new_password
|
31
31
|
self.password_confirmation = new_password_confirmation
|
32
|
+
|
32
33
|
if valid?
|
33
34
|
clear_reset_password_token
|
34
35
|
after_password_reset
|
@@ -39,7 +40,7 @@ module Devise
|
|
39
40
|
|
40
41
|
# Resets reset password token and send reset password instructions by email
|
41
42
|
def send_reset_password_instructions
|
42
|
-
generate_reset_password_token! if
|
43
|
+
generate_reset_password_token! if should_generate_reset_token?
|
43
44
|
self.devise_mailer.reset_password_instructions(self).deliver
|
44
45
|
end
|
45
46
|
|
@@ -64,20 +65,19 @@ module Devise
|
|
64
65
|
# reset_password_period_valid? # will always return false
|
65
66
|
#
|
66
67
|
def reset_password_period_valid?
|
67
|
-
return true unless respond_to?(:reset_password_sent_at)
|
68
68
|
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago
|
69
69
|
end
|
70
70
|
|
71
71
|
protected
|
72
72
|
|
73
|
-
def
|
73
|
+
def should_generate_reset_token?
|
74
74
|
reset_password_token.nil? || !reset_password_period_valid?
|
75
75
|
end
|
76
76
|
|
77
77
|
# Generates a new random token for reset password
|
78
78
|
def generate_reset_password_token
|
79
79
|
self.reset_password_token = self.class.reset_password_token
|
80
|
-
self.reset_password_sent_at = Time.now.utc
|
80
|
+
self.reset_password_sent_at = Time.now.utc
|
81
81
|
self.reset_password_token
|
82
82
|
end
|
83
83
|
|
@@ -90,7 +90,7 @@ module Devise
|
|
90
90
|
# Removes reset_password token
|
91
91
|
def clear_reset_password_token
|
92
92
|
self.reset_password_token = nil
|
93
|
-
self.reset_password_sent_at = nil
|
93
|
+
self.reset_password_sent_at = nil
|
94
94
|
end
|
95
95
|
|
96
96
|
def after_password_reset
|
@@ -21,11 +21,6 @@ module Devise
|
|
21
21
|
# used to calculate the expires time for the cookie created to remember
|
22
22
|
# the user. By default remember_for is 2.weeks.
|
23
23
|
#
|
24
|
-
# * +remember_across_browsers+: if a valid remember token can be re-used
|
25
|
-
# between multiple browsers. By default remember_across_browsers is true
|
26
|
-
# and cannot be turned off if you are using password salt instead of remember
|
27
|
-
# token.
|
28
|
-
#
|
29
24
|
# * +extend_remember_period+: if true, extends the user's remember period
|
30
25
|
# when remembered via cookie. False by default.
|
31
26
|
#
|
@@ -49,7 +44,6 @@ module Devise
|
|
49
44
|
# Generate a new remember token and save the record without validations
|
50
45
|
# unless remember_across_browsers is true and the user already has a valid token.
|
51
46
|
def remember_me!(extend_period=false)
|
52
|
-
self.remember_token = self.class.remember_token if respond_to?(:remember_token) && generate_remember_token?
|
53
47
|
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
|
54
48
|
save(:validate => false)
|
55
49
|
end
|
@@ -75,14 +69,12 @@ module Devise
|
|
75
69
|
end
|
76
70
|
|
77
71
|
def rememberable_value
|
78
|
-
if
|
79
|
-
remember_token
|
80
|
-
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt)
|
72
|
+
if salt = authenticatable_salt
|
81
73
|
salt
|
82
74
|
else
|
83
|
-
raise "
|
84
|
-
"
|
85
|
-
"
|
75
|
+
raise "authenticable_salt returned nil for the #{self.class.name} model. " \
|
76
|
+
"In order to use rememberable, you must ensure a password is always set " \
|
77
|
+
"or implement rememberable_value in your model with your own logic."
|
86
78
|
end
|
87
79
|
end
|
88
80
|
|
@@ -92,12 +84,6 @@ module Devise
|
|
92
84
|
|
93
85
|
protected
|
94
86
|
|
95
|
-
# Generate a token unless remember_across_browsers is true and there is
|
96
|
-
# an existing remember_token or the existing remember_token has expried.
|
97
|
-
def generate_remember_token? #:nodoc:
|
98
|
-
!(self.class.remember_across_browsers && remember_token) || remember_expired?
|
99
|
-
end
|
100
|
-
|
101
87
|
# Generate a timestamp if extend_remember_period is true, if no remember_token
|
102
88
|
# exists, or if an existing remember token has expired.
|
103
89
|
def generate_remember_timestamp?(extend_period) #:nodoc:
|
@@ -121,8 +107,7 @@ module Devise
|
|
121
107
|
generate_token(:remember_token)
|
122
108
|
end
|
123
109
|
|
124
|
-
Devise::Models.config(self, :remember_for, :
|
125
|
-
:extend_remember_period, :cookie_options)
|
110
|
+
Devise::Models.config(self, :remember_for, :extend_remember_period, :cookie_options)
|
126
111
|
end
|
127
112
|
end
|
128
113
|
end
|
@@ -23,7 +23,6 @@ module Devise
|
|
23
23
|
# Checks whether the user session has expired based on configured time.
|
24
24
|
def timedout?(last_access)
|
25
25
|
return false if remember_exists_and_not_expired?
|
26
|
-
|
27
26
|
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
28
27
|
end
|
29
28
|
|
@@ -34,8 +33,7 @@ module Devise
|
|
34
33
|
private
|
35
34
|
|
36
35
|
def remember_exists_and_not_expired?
|
37
|
-
return false unless respond_to?(:
|
38
|
-
|
36
|
+
return false unless respond_to?(:remember_created_at)
|
39
37
|
remember_created_at && !remember_expired?
|
40
38
|
end
|
41
39
|
|
@@ -24,9 +24,6 @@ module Devise
|
|
24
24
|
#
|
25
25
|
# * +token_authentication_key+: Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
|
26
26
|
#
|
27
|
-
# * +stateless_token+: By default, when you sign up with a token, Devise will store the user in session
|
28
|
-
# as any other authentication strategy. You can set stateless_token to true to avoid this.
|
29
|
-
#
|
30
27
|
module TokenAuthenticatable
|
31
28
|
extend ActiveSupport::Concern
|
32
29
|
|
@@ -65,7 +62,7 @@ module Devise
|
|
65
62
|
generate_token(:authentication_token)
|
66
63
|
end
|
67
64
|
|
68
|
-
::Devise::Models.config(self, :token_authentication_key
|
65
|
+
::Devise::Models.config(self, :token_authentication_key)
|
69
66
|
end
|
70
67
|
end
|
71
68
|
end
|
@@ -23,7 +23,7 @@ module Devise
|
|
23
23
|
|
24
24
|
base.class_eval do
|
25
25
|
validates_presence_of :email, :if => :email_required?
|
26
|
-
validates_uniqueness_of :email, :
|
26
|
+
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
|
27
27
|
validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed?
|
28
28
|
|
29
29
|
validates_presence_of :password, :if => :password_required?
|
@@ -26,6 +26,12 @@ module Devise
|
|
26
26
|
|
27
27
|
# Tell how to apply schema methods.
|
28
28
|
def apply_devise_schema(name, type, options={})
|
29
|
+
@__devise_warning_raised ||= begin
|
30
|
+
$stderr.puts "\n[DEVISE] You are using t.database_authenticatable and others in your migration " \
|
31
|
+
"and this feature is deprecated. Please simply use Rails helpers instead as mentioned here:\n" \
|
32
|
+
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n\n"
|
33
|
+
true
|
34
|
+
end
|
29
35
|
column name, type.to_s.downcase.to_sym, options
|
30
36
|
end
|
31
37
|
end
|
data/lib/devise/param_filter.rb
CHANGED
@@ -33,8 +33,9 @@ module Devise
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
# Determine which values should be transformed to string or passed as-is to the query builder underneath
|
36
37
|
def param_requires_string_conversion?(value)
|
37
|
-
true
|
38
|
+
true unless value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(Fixnum)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/devise/rails.rb
CHANGED
@@ -41,5 +41,36 @@ module Devise
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
initializer "devise.deprecations" do
|
46
|
+
unless defined?(Rails::Generators)
|
47
|
+
if Devise.case_insensitive_keys == false
|
48
|
+
warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \
|
49
|
+
"supported. If you want to continue running on this mode, please ensure " \
|
50
|
+
"you are not using validatable (you can copy the validations directly to your model) " \
|
51
|
+
"and set case_insensitive_keys to an empty array.\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
if Devise.apply_schema && defined?(Mongoid)
|
55
|
+
warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
|
56
|
+
"automatically configuring your DB. This no longer happens. You should " \
|
57
|
+
"set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \
|
58
|
+
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
# TODO: Deprecate the true value of this option as well
|
62
|
+
if Devise.use_salt_as_remember_token == false
|
63
|
+
warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \
|
64
|
+
"supported. Devise now only uses the salt as remember token and the remember_token " \
|
65
|
+
"column can be removed from your models.\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
if Devise.reset_password_within.nil?
|
69
|
+
warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \
|
70
|
+
"an interval (for example, 6.hours) and add a reset_password_sent_at field to " \
|
71
|
+
"your Devise models (if they don't have one already).\n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
44
75
|
end
|
45
76
|
end
|
data/lib/devise/schema.rb
CHANGED
@@ -40,6 +40,11 @@ module Devise
|
|
40
40
|
apply_devise_schema :confirmation_sent_at, DateTime
|
41
41
|
end
|
42
42
|
|
43
|
+
# Creates unconfirmed_email
|
44
|
+
def reconfirmable
|
45
|
+
apply_devise_schema :unconfirmed_email, String
|
46
|
+
end
|
47
|
+
|
43
48
|
# Creates reset_password_token and reset_password_sent_at.
|
44
49
|
#
|
45
50
|
# == Options
|
@@ -6,7 +6,11 @@ module Devise
|
|
6
6
|
# parameters both from params or from http authorization headers. See database_authenticatable
|
7
7
|
# for an example.
|
8
8
|
class Authenticatable < Base
|
9
|
-
attr_accessor :authentication_hash, :password
|
9
|
+
attr_accessor :authentication_hash, :authentication_type, :password
|
10
|
+
|
11
|
+
def store?
|
12
|
+
!mapping.to.skip_session_storage.include?(authentication_type)
|
13
|
+
end
|
10
14
|
|
11
15
|
def valid?
|
12
16
|
valid_for_params_auth? || valid_for_http_auth?
|
@@ -47,7 +51,7 @@ module Devise
|
|
47
51
|
# * If all authentication keys are present;
|
48
52
|
#
|
49
53
|
def valid_for_http_auth?
|
50
|
-
http_authenticatable? && request.authorization && with_authentication_hash(http_auth_hash)
|
54
|
+
http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
|
51
55
|
end
|
52
56
|
|
53
57
|
# Check if this is strategy is valid for params authentication by:
|
@@ -58,8 +62,8 @@ module Devise
|
|
58
62
|
# * If all authentication keys are present;
|
59
63
|
#
|
60
64
|
def valid_for_params_auth?
|
61
|
-
params_authenticatable? &&
|
62
|
-
valid_params? && with_authentication_hash(params_auth_hash)
|
65
|
+
params_authenticatable? && valid_params_request? &&
|
66
|
+
valid_params? && with_authentication_hash(:params_auth, params_auth_hash)
|
63
67
|
end
|
64
68
|
|
65
69
|
# Check if the model accepts this strategy as http authenticatable.
|
@@ -83,8 +87,8 @@ module Devise
|
|
83
87
|
Hash[*keys.zip(decode_credentials).flatten]
|
84
88
|
end
|
85
89
|
|
86
|
-
# By default, a request is valid
|
87
|
-
def
|
90
|
+
# By default, a request is valid if the controller set the proper env variable.
|
91
|
+
def valid_params_request?
|
88
92
|
!!env["devise.allow_params_authentication"]
|
89
93
|
end
|
90
94
|
|
@@ -105,8 +109,8 @@ module Devise
|
|
105
109
|
end
|
106
110
|
|
107
111
|
# Sets the authentication hash and the password from params_auth_hash or http_auth_hash.
|
108
|
-
def with_authentication_hash(auth_values)
|
109
|
-
self.authentication_hash = {}
|
112
|
+
def with_authentication_hash(auth_type, auth_values)
|
113
|
+
self.authentication_hash, self.authentication_type = {}, auth_type
|
110
114
|
self.password = auth_values[:password]
|
111
115
|
|
112
116
|
parse_authentication_key_values(auth_values, authentication_keys) &&
|