devise 1.5.3 → 2.0.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.
- data/CHANGELOG.rdoc +98 -71
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -2
- data/app/controllers/devise/confirmations_controller.rb +3 -6
- data/app/controllers/devise/omniauth_callbacks_controller.rb +1 -3
- data/app/controllers/devise/passwords_controller.rb +3 -6
- data/app/controllers/devise/registrations_controller.rb +40 -42
- data/app/controllers/devise/sessions_controller.rb +2 -3
- data/app/controllers/devise/unlocks_controller.rb +4 -7
- data/app/controllers/devise_controller.rb +169 -0
- data/app/views/devise/_links.erb +25 -0
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +1 -1
- data/app/views/devise/shared/_links.erb +3 -25
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +5 -6
- data/lib/devise/controllers/helpers.rb +8 -2
- data/lib/devise/controllers/scoped_views.rb +0 -16
- data/lib/devise/controllers/url_helpers.rb +16 -2
- data/lib/devise/failure_app.rb +43 -8
- data/lib/devise/models/authenticatable.rb +22 -1
- data/lib/devise/models/confirmable.rb +80 -22
- data/lib/devise/models/database_authenticatable.rb +0 -11
- data/lib/devise/models/lockable.rb +1 -1
- data/lib/devise/models/recoverable.rb +5 -5
- data/lib/devise/models/rememberable.rb +5 -20
- data/lib/devise/models/serializable.rb +5 -2
- 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/models.rb +1 -1
- data/lib/devise/modules.rb +2 -2
- data/lib/devise/orm/active_record.rb +6 -0
- data/lib/devise/param_filter.rb +1 -1
- data/lib/devise/path_checker.rb +5 -1
- data/lib/devise/rails/routes.rb +16 -10
- data/lib/devise/rails/warden_compat.rb +0 -83
- data/lib/devise/rails.rb +61 -0
- data/lib/devise/schema.rb +5 -0
- data/lib/devise/strategies/authenticatable.rb +14 -10
- data/lib/devise/strategies/token_authenticatable.rb +3 -3
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +56 -33
- data/lib/generators/active_record/devise_generator.rb +40 -2
- data/lib/generators/active_record/templates/migration.rb +1 -19
- data/lib/generators/active_record/templates/migration_existing.rb +1 -9
- data/lib/generators/devise/views_generator.rb +6 -14
- data/lib/generators/mongoid/devise_generator.rb +43 -0
- data/lib/generators/templates/devise.rb +26 -12
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -1
- data/test/controllers/internal_helpers_test.rb +5 -4
- data/test/devise_test.rb +2 -2
- data/test/failure_app_test.rb +24 -20
- data/test/generators/active_record_generator_test.rb +3 -13
- data/test/generators/views_generator_test.rb +1 -1
- data/test/integration/authenticatable_test.rb +4 -7
- data/test/integration/confirmable_test.rb +55 -3
- data/test/integration/http_authenticatable_test.rb +20 -5
- data/test/integration/lockable_test.rb +26 -14
- data/test/integration/registerable_test.rb +33 -2
- data/test/integration/rememberable_test.rb +0 -50
- data/test/integration/timeoutable_test.rb +18 -4
- data/test/integration/token_authenticatable_test.rb +5 -5
- data/test/integration/trackable_test.rb +6 -6
- data/test/mapping_test.rb +2 -3
- data/test/models/confirmable_test.rb +101 -8
- data/test/models/database_authenticatable_test.rb +6 -0
- data/test/models/encryptable_test.rb +1 -1
- data/test/models/lockable_test.rb +13 -0
- 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/config/routes.rb +3 -5
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
- data/test/rails_app/lib/shared_admin.rb +6 -2
- data/test/rails_app/log/development.log +13 -0
- data/test/rails_app/log/test.log +319550 -0
- data/test/support/assertions.rb +4 -1
- data/test/support/helpers.rb +0 -17
- data/test/support/integration.rb +3 -1
- data/test/test_helpers_test.rb +2 -2
- data/test/tmp/app/views/devise/_links.erb +25 -0
- data/test/tmp/app/views/devise/confirmations/new.html.erb +15 -0
- data/test/tmp/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/test/tmp/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/test/tmp/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/test/tmp/app/views/devise/passwords/edit.html.erb +19 -0
- data/test/tmp/app/views/devise/passwords/new.html.erb +15 -0
- data/test/tmp/app/views/devise/registrations/edit.html.erb +22 -0
- data/test/tmp/app/views/devise/registrations/new.html.erb +17 -0
- data/test/tmp/app/views/devise/sessions/new.html.erb +15 -0
- data/test/tmp/app/views/devise/unlocks/new.html.erb +15 -0
- data/test/tmp/app/views/users/_links.erb +25 -0
- data/test/tmp/app/views/users/confirmations/new.html.erb +15 -0
- data/test/tmp/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
- data/test/tmp/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
- data/test/tmp/app/views/users/mailer/unlock_instructions.html.erb +7 -0
- data/test/tmp/app/views/users/passwords/edit.html.erb +19 -0
- data/test/tmp/app/views/users/passwords/new.html.erb +15 -0
- data/test/tmp/app/views/users/registrations/edit.html.erb +22 -0
- data/test/tmp/app/views/users/registrations/new.html.erb +17 -0
- data/test/tmp/app/views/users/sessions/new.html.erb +15 -0
- data/test/tmp/app/views/users/unlocks/new.html.erb +15 -0
- metadata +78 -26
- data/.gitignore +0 -12
- data/.travis.yml +0 -13
- data/Gemfile +0 -35
- data/Rakefile +0 -34
- data/devise.gemspec +0 -25
- data/lib/devise/controllers/internal_helpers.rb +0 -154
- data/lib/devise/controllers/shared_helpers.rb +0 -26
- 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,28 @@ 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
|
+
pending_any_confirmation do
|
|
36
44
|
self.confirmation_token = nil
|
|
37
45
|
self.confirmed_at = Time.now.utc
|
|
38
|
-
|
|
46
|
+
|
|
47
|
+
if self.class.reconfirmable && unconfirmed_email.present?
|
|
48
|
+
@bypass_postpone = true
|
|
49
|
+
self.email = unconfirmed_email
|
|
50
|
+
self.unconfirmed_email = nil
|
|
51
|
+
|
|
52
|
+
# We need to validate in such cases to enforce e-mail uniqueness
|
|
53
|
+
save(:validate => true)
|
|
54
|
+
else
|
|
55
|
+
save(:validate => false)
|
|
56
|
+
end
|
|
39
57
|
end
|
|
40
58
|
end
|
|
41
59
|
|
|
@@ -44,15 +62,22 @@ module Devise
|
|
|
44
62
|
!!confirmed_at
|
|
45
63
|
end
|
|
46
64
|
|
|
65
|
+
def pending_reconfirmation?
|
|
66
|
+
self.class.reconfirmable && unconfirmed_email.present?
|
|
67
|
+
end
|
|
68
|
+
|
|
47
69
|
# Send confirmation instructions by email
|
|
48
70
|
def send_confirmation_instructions
|
|
49
|
-
|
|
71
|
+
self.confirmation_token = nil if reconfirmation_required?
|
|
72
|
+
@reconfirmation_required = false
|
|
73
|
+
|
|
74
|
+
generate_confirmation_token! if self.confirmation_token.blank?
|
|
50
75
|
self.devise_mailer.confirmation_instructions(self).deliver
|
|
51
76
|
end
|
|
52
77
|
|
|
53
78
|
# Resend confirmation token. This method does not need to generate a new token.
|
|
54
79
|
def resend_confirmation_token
|
|
55
|
-
|
|
80
|
+
pending_any_confirmation { send_confirmation_instructions }
|
|
56
81
|
end
|
|
57
82
|
|
|
58
83
|
# Overwrites active_for_authentication? for confirmation
|
|
@@ -74,6 +99,14 @@ module Devise
|
|
|
74
99
|
self.confirmed_at = Time.now.utc
|
|
75
100
|
end
|
|
76
101
|
|
|
102
|
+
def headers_for(action)
|
|
103
|
+
headers = super
|
|
104
|
+
if action == :confirmation_instructions && pending_reconfirmation?
|
|
105
|
+
headers[:to] = unconfirmed_email
|
|
106
|
+
end
|
|
107
|
+
headers
|
|
108
|
+
end
|
|
109
|
+
|
|
77
110
|
protected
|
|
78
111
|
|
|
79
112
|
# Callback to overwrite if confirmation is required or not.
|
|
@@ -88,26 +121,25 @@ module Devise
|
|
|
88
121
|
#
|
|
89
122
|
# Example:
|
|
90
123
|
#
|
|
91
|
-
# #
|
|
124
|
+
# # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
|
|
92
125
|
# confirmation_period_valid? # returns true
|
|
93
126
|
#
|
|
94
|
-
# #
|
|
127
|
+
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
|
|
95
128
|
# confirmation_period_valid? # returns true
|
|
96
129
|
#
|
|
97
|
-
# #
|
|
130
|
+
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
|
|
98
131
|
# confirmation_period_valid? # returns false
|
|
99
132
|
#
|
|
100
|
-
# #
|
|
133
|
+
# # allow_unconfirmed_access_for = 0.days
|
|
101
134
|
# confirmation_period_valid? # will always return false
|
|
102
135
|
#
|
|
103
136
|
def confirmation_period_valid?
|
|
104
|
-
confirmation_sent_at && confirmation_sent_at.utc >= self.class.
|
|
137
|
+
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
|
|
105
138
|
end
|
|
106
139
|
|
|
107
|
-
# Checks whether the record
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
unless confirmed?
|
|
140
|
+
# Checks whether the record requires any confirmation.
|
|
141
|
+
def pending_any_confirmation
|
|
142
|
+
if !confirmed? || pending_reconfirmation?
|
|
111
143
|
yield
|
|
112
144
|
else
|
|
113
145
|
self.errors.add(:email, :already_confirmed)
|
|
@@ -118,7 +150,6 @@ module Devise
|
|
|
118
150
|
# Generates a new random token for confirmation, and stores the time
|
|
119
151
|
# this token is being generated
|
|
120
152
|
def generate_confirmation_token
|
|
121
|
-
self.confirmed_at = nil
|
|
122
153
|
self.confirmation_token = self.class.confirmation_token
|
|
123
154
|
self.confirmation_sent_at = Time.now.utc
|
|
124
155
|
end
|
|
@@ -132,13 +163,32 @@ module Devise
|
|
|
132
163
|
confirm! unless confirmed?
|
|
133
164
|
end
|
|
134
165
|
|
|
166
|
+
def postpone_email_change_until_confirmation
|
|
167
|
+
@reconfirmation_required = true
|
|
168
|
+
self.unconfirmed_email = self.email
|
|
169
|
+
self.email = self.email_was
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def postpone_email_change?
|
|
173
|
+
postpone = self.class.reconfirmable && email_changed? && !@bypass_postpone
|
|
174
|
+
@bypass_postpone = nil
|
|
175
|
+
postpone
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def reconfirmation_required?
|
|
179
|
+
self.class.reconfirmable && @reconfirmation_required
|
|
180
|
+
end
|
|
181
|
+
|
|
135
182
|
module ClassMethods
|
|
136
183
|
# 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.
|
|
184
|
+
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
|
185
|
+
# field. If no user is found, returns a new user with an email not found error.
|
|
139
186
|
# Options must contain the user email
|
|
140
187
|
def send_confirmation_instructions(attributes={})
|
|
141
|
-
confirmable =
|
|
188
|
+
confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
|
|
189
|
+
unless confirmable.try(:persisted?)
|
|
190
|
+
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
|
|
191
|
+
end
|
|
142
192
|
confirmable.resend_confirmation_token if confirmable.persisted?
|
|
143
193
|
confirmable
|
|
144
194
|
end
|
|
@@ -158,7 +208,15 @@ module Devise
|
|
|
158
208
|
generate_token(:confirmation_token)
|
|
159
209
|
end
|
|
160
210
|
|
|
161
|
-
|
|
211
|
+
# Find a record for confirmation by unconfirmed email field
|
|
212
|
+
def find_by_unconfirmed_email_with_errors(attributes = {})
|
|
213
|
+
unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }
|
|
214
|
+
unconfirmed_attributes = attributes.symbolize_keys
|
|
215
|
+
unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)
|
|
216
|
+
find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable)
|
|
162
220
|
end
|
|
163
221
|
end
|
|
164
222
|
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
|
|
@@ -9,8 +9,11 @@ module Devise
|
|
|
9
9
|
module Serializable
|
|
10
10
|
extend ActiveSupport::Concern
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
array = %w(serializable_hash)
|
|
13
|
+
# to_xml does not call serializable_hash on 3.1
|
|
14
|
+
array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
|
|
15
|
+
|
|
16
|
+
array.each do |method|
|
|
14
17
|
class_eval <<-RUBY, __FILE__, __LINE__
|
|
15
18
|
def #{method}(options=nil)
|
|
16
19
|
options ||= {}
|
|
@@ -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?
|
data/lib/devise/models.rb
CHANGED
|
@@ -48,7 +48,6 @@ module Devise
|
|
|
48
48
|
# for a complete description on those values.
|
|
49
49
|
#
|
|
50
50
|
def devise(*modules)
|
|
51
|
-
include Devise::Models::Authenticatable
|
|
52
51
|
options = modules.extract_options!.dup
|
|
53
52
|
|
|
54
53
|
selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
|
|
@@ -56,6 +55,7 @@ module Devise
|
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
devise_modules_hook! do
|
|
58
|
+
include Devise::Models::Authenticatable
|
|
59
59
|
selected_modules.each do |m|
|
|
60
60
|
mod = Devise::Models.const_get(m.to_s.classify)
|
|
61
61
|
|
data/lib/devise/modules.rb
CHANGED
|
@@ -5,8 +5,8 @@ Devise.with_options :model => true do |d|
|
|
|
5
5
|
d.with_options :strategy => true do |s|
|
|
6
6
|
routes = [nil, :new, :destroy]
|
|
7
7
|
s.add_module :database_authenticatable, :controller => :sessions, :route => { :session => routes }
|
|
8
|
-
s.add_module :token_authenticatable
|
|
9
|
-
s.add_module :rememberable
|
|
8
|
+
s.add_module :token_authenticatable, :controller => :sessions, :route => { :session => routes }, :no_input => true
|
|
9
|
+
s.add_module :rememberable, :no_input => true
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
# Other authentications
|
|
@@ -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
|
@@ -35,7 +35,7 @@ module Devise
|
|
|
35
35
|
|
|
36
36
|
# Determine which values should be transformed to string or passed as-is to the query builder underneath
|
|
37
37
|
def param_requires_string_conversion?(value)
|
|
38
|
-
|
|
38
|
+
[Fixnum, TrueClass, FalseClass, Regexp].none? {|clz| value.is_a? clz }
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
end
|
data/lib/devise/path_checker.rb
CHANGED
|
@@ -3,7 +3,11 @@ module Devise
|
|
|
3
3
|
include Rails.application.routes.url_helpers
|
|
4
4
|
|
|
5
5
|
def self.default_url_options(*args)
|
|
6
|
-
ApplicationController
|
|
6
|
+
if defined?(ApplicationController)
|
|
7
|
+
ApplicationController.default_url_options(*args)
|
|
8
|
+
else
|
|
9
|
+
{}
|
|
10
|
+
end
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
def initialize(env, scope)
|
data/lib/devise/rails/routes.rb
CHANGED
|
@@ -84,15 +84,16 @@ module ActionDispatch::Routing
|
|
|
84
84
|
#
|
|
85
85
|
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
|
86
86
|
#
|
|
87
|
-
# * :module => the namespace to find
|
|
88
|
-
# devise/registrations and so on. If you want
|
|
87
|
+
# * :module => the namespace to find controllers (default: "devise", thus
|
|
88
|
+
# accessing devise/sessions, devise/registrations, and so on). If you want
|
|
89
|
+
# to namespace all at once, use module:
|
|
89
90
|
#
|
|
90
91
|
# devise_for :users, :module => "users"
|
|
91
92
|
#
|
|
92
93
|
# Notice that whenever you use namespace in the router DSL, it automatically sets the module.
|
|
93
94
|
# So the following setup:
|
|
94
95
|
#
|
|
95
|
-
# namespace :publisher
|
|
96
|
+
# namespace :publisher do
|
|
96
97
|
# devise_for :account
|
|
97
98
|
# end
|
|
98
99
|
#
|
|
@@ -135,15 +136,15 @@ module ActionDispatch::Routing
|
|
|
135
136
|
# devise_for :users
|
|
136
137
|
# end
|
|
137
138
|
#
|
|
138
|
-
# However, since Devise uses the request path to retrieve the current user,
|
|
139
|
-
# If you are using a dynamic segment,
|
|
139
|
+
# However, since Devise uses the request path to retrieve the current user,
|
|
140
|
+
# this has one caveat: If you are using a dynamic segment, like so ...
|
|
140
141
|
#
|
|
141
142
|
# scope ":locale" do
|
|
142
143
|
# devise_for :users
|
|
143
144
|
# end
|
|
144
145
|
#
|
|
145
|
-
#
|
|
146
|
-
# Devise can pick it:
|
|
146
|
+
# you are required to configure default_url_options in your
|
|
147
|
+
# ApplicationController class, so Devise can pick it:
|
|
147
148
|
#
|
|
148
149
|
# class ApplicationController < ActionController::Base
|
|
149
150
|
# def self.default_url_options
|
|
@@ -207,7 +208,12 @@ module ActionDispatch::Routing
|
|
|
207
208
|
routes = mapping.used_routes
|
|
208
209
|
|
|
209
210
|
devise_scope mapping.name do
|
|
210
|
-
|
|
211
|
+
if block_given?
|
|
212
|
+
ActiveSupport::Deprecation.warn "Passing a block to devise_for is deprecated. " \
|
|
213
|
+
"Please call devise_scope :#{mapping.name} do ... end with the block instead", caller
|
|
214
|
+
yield
|
|
215
|
+
end
|
|
216
|
+
|
|
211
217
|
with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
|
|
212
218
|
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
|
|
213
219
|
end
|
|
@@ -369,13 +375,13 @@ module ActionDispatch::Routing
|
|
|
369
375
|
end
|
|
370
376
|
|
|
371
377
|
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
|
|
372
|
-
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
|
|
378
|
+
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
|
|
373
379
|
*@scope.values_at(:as, :path, :module, :constraints, :defaults, :options)
|
|
374
380
|
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
|
|
375
381
|
new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options)
|
|
376
382
|
yield
|
|
377
383
|
ensure
|
|
378
|
-
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
|
|
384
|
+
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
|
|
379
385
|
old_as, old_path, old_module, old_constraints, old_defaults, old_options
|
|
380
386
|
end
|
|
381
387
|
|
|
@@ -34,87 +34,4 @@ class Warden::SessionSerializer
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
unless Devise.rack_session?
|
|
40
|
-
# We cannot use Rails Indifferent Hash because it messes up the flash object.
|
|
41
|
-
class Devise::IndifferentHash < Hash
|
|
42
|
-
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
|
43
|
-
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
|
44
|
-
|
|
45
|
-
def [](key)
|
|
46
|
-
super(convert_key(key))
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def []=(key, value)
|
|
50
|
-
regular_writer(convert_key(key), value)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
alias_method :store, :[]=
|
|
54
|
-
|
|
55
|
-
def update(other_hash)
|
|
56
|
-
other_hash.each_pair { |key, value| regular_writer(convert_key(key), value) }
|
|
57
|
-
self
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
alias_method :merge!, :update
|
|
61
|
-
|
|
62
|
-
def key?(key)
|
|
63
|
-
super(convert_key(key))
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
alias_method :include?, :key?
|
|
67
|
-
alias_method :has_key?, :key?
|
|
68
|
-
alias_method :member?, :key?
|
|
69
|
-
|
|
70
|
-
def fetch(key, *extras)
|
|
71
|
-
super(convert_key(key), *extras)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def values_at(*indices)
|
|
75
|
-
indices.collect {|key| self[convert_key(key)]}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def merge(hash)
|
|
79
|
-
self.dup.update(hash)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def delete(key)
|
|
83
|
-
super(convert_key(key))
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def stringify_keys!; self end
|
|
87
|
-
def stringify_keys; dup end
|
|
88
|
-
|
|
89
|
-
undef :symbolize_keys!
|
|
90
|
-
def symbolize_keys; to_hash.symbolize_keys end
|
|
91
|
-
|
|
92
|
-
def to_options!; self end
|
|
93
|
-
def to_hash; Hash.new.update(self) end
|
|
94
|
-
|
|
95
|
-
protected
|
|
96
|
-
|
|
97
|
-
def convert_key(key)
|
|
98
|
-
key.kind_of?(Symbol) ? key.to_s : key
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
class ActionDispatch::Request
|
|
103
|
-
def reset_session
|
|
104
|
-
session.destroy if session && session.respond_to?(:destroy)
|
|
105
|
-
self.session = {}
|
|
106
|
-
@env['action_dispatch.request.flash_hash'] = nil
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
Warden::Manager.after_set_user :event => [:set_user, :authentication] do |record, warden, options|
|
|
111
|
-
if options[:scope] && warden.authenticated?(options[:scope])
|
|
112
|
-
request, flash = warden.request, warden.env['action_dispatch.request.flash_hash']
|
|
113
|
-
backup = request.session.to_hash
|
|
114
|
-
backup.delete("session_id")
|
|
115
|
-
request.reset_session
|
|
116
|
-
warden.env['action_dispatch.request.flash_hash'] = flash
|
|
117
|
-
request.session = Devise::IndifferentHash.new.update(backup)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
37
|
end
|