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.
Files changed (125) hide show
  1. data/CHANGELOG.rdoc +98 -71
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +4 -2
  4. data/app/controllers/devise/confirmations_controller.rb +3 -6
  5. data/app/controllers/devise/omniauth_callbacks_controller.rb +1 -3
  6. data/app/controllers/devise/passwords_controller.rb +3 -6
  7. data/app/controllers/devise/registrations_controller.rb +40 -42
  8. data/app/controllers/devise/sessions_controller.rb +2 -3
  9. data/app/controllers/devise/unlocks_controller.rb +4 -7
  10. data/app/controllers/devise_controller.rb +169 -0
  11. data/app/views/devise/_links.erb +25 -0
  12. data/app/views/devise/confirmations/new.html.erb +1 -1
  13. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  14. data/app/views/devise/passwords/edit.html.erb +1 -1
  15. data/app/views/devise/passwords/new.html.erb +1 -1
  16. data/app/views/devise/registrations/new.html.erb +1 -1
  17. data/app/views/devise/sessions/new.html.erb +1 -1
  18. data/app/views/devise/shared/_links.erb +3 -25
  19. data/app/views/devise/unlocks/new.html.erb +1 -1
  20. data/config/locales/en.yml +5 -6
  21. data/lib/devise/controllers/helpers.rb +8 -2
  22. data/lib/devise/controllers/scoped_views.rb +0 -16
  23. data/lib/devise/controllers/url_helpers.rb +16 -2
  24. data/lib/devise/failure_app.rb +43 -8
  25. data/lib/devise/models/authenticatable.rb +22 -1
  26. data/lib/devise/models/confirmable.rb +80 -22
  27. data/lib/devise/models/database_authenticatable.rb +0 -11
  28. data/lib/devise/models/lockable.rb +1 -1
  29. data/lib/devise/models/recoverable.rb +5 -5
  30. data/lib/devise/models/rememberable.rb +5 -20
  31. data/lib/devise/models/serializable.rb +5 -2
  32. data/lib/devise/models/timeoutable.rb +1 -3
  33. data/lib/devise/models/token_authenticatable.rb +1 -4
  34. data/lib/devise/models/validatable.rb +1 -1
  35. data/lib/devise/models.rb +1 -1
  36. data/lib/devise/modules.rb +2 -2
  37. data/lib/devise/orm/active_record.rb +6 -0
  38. data/lib/devise/param_filter.rb +1 -1
  39. data/lib/devise/path_checker.rb +5 -1
  40. data/lib/devise/rails/routes.rb +16 -10
  41. data/lib/devise/rails/warden_compat.rb +0 -83
  42. data/lib/devise/rails.rb +61 -0
  43. data/lib/devise/schema.rb +5 -0
  44. data/lib/devise/strategies/authenticatable.rb +14 -10
  45. data/lib/devise/strategies/token_authenticatable.rb +3 -3
  46. data/lib/devise/version.rb +1 -1
  47. data/lib/devise.rb +56 -33
  48. data/lib/generators/active_record/devise_generator.rb +40 -2
  49. data/lib/generators/active_record/templates/migration.rb +1 -19
  50. data/lib/generators/active_record/templates/migration_existing.rb +1 -9
  51. data/lib/generators/devise/views_generator.rb +6 -14
  52. data/lib/generators/mongoid/devise_generator.rb +43 -0
  53. data/lib/generators/templates/devise.rb +26 -12
  54. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -1
  55. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
  56. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +1 -1
  57. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  58. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +1 -1
  59. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -1
  60. data/test/controllers/internal_helpers_test.rb +5 -4
  61. data/test/devise_test.rb +2 -2
  62. data/test/failure_app_test.rb +24 -20
  63. data/test/generators/active_record_generator_test.rb +3 -13
  64. data/test/generators/views_generator_test.rb +1 -1
  65. data/test/integration/authenticatable_test.rb +4 -7
  66. data/test/integration/confirmable_test.rb +55 -3
  67. data/test/integration/http_authenticatable_test.rb +20 -5
  68. data/test/integration/lockable_test.rb +26 -14
  69. data/test/integration/registerable_test.rb +33 -2
  70. data/test/integration/rememberable_test.rb +0 -50
  71. data/test/integration/timeoutable_test.rb +18 -4
  72. data/test/integration/token_authenticatable_test.rb +5 -5
  73. data/test/integration/trackable_test.rb +6 -6
  74. data/test/mapping_test.rb +2 -3
  75. data/test/models/confirmable_test.rb +101 -8
  76. data/test/models/database_authenticatable_test.rb +6 -0
  77. data/test/models/encryptable_test.rb +1 -1
  78. data/test/models/lockable_test.rb +13 -0
  79. data/test/models/recoverable_test.rb +0 -27
  80. data/test/models/rememberable_test.rb +41 -160
  81. data/test/models/serializable_test.rb +1 -1
  82. data/test/models_test.rb +7 -7
  83. data/test/rails_app/app/mongoid/admin.rb +22 -1
  84. data/test/rails_app/app/mongoid/user.rb +35 -0
  85. data/test/rails_app/config/initializers/devise.rb +6 -7
  86. data/test/rails_app/config/routes.rb +3 -5
  87. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
  88. data/test/rails_app/lib/shared_admin.rb +6 -2
  89. data/test/rails_app/log/development.log +13 -0
  90. data/test/rails_app/log/test.log +319550 -0
  91. data/test/support/assertions.rb +4 -1
  92. data/test/support/helpers.rb +0 -17
  93. data/test/support/integration.rb +3 -1
  94. data/test/test_helpers_test.rb +2 -2
  95. data/test/tmp/app/views/devise/_links.erb +25 -0
  96. data/test/tmp/app/views/devise/confirmations/new.html.erb +15 -0
  97. data/test/tmp/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  98. data/test/tmp/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  99. data/test/tmp/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  100. data/test/tmp/app/views/devise/passwords/edit.html.erb +19 -0
  101. data/test/tmp/app/views/devise/passwords/new.html.erb +15 -0
  102. data/test/tmp/app/views/devise/registrations/edit.html.erb +22 -0
  103. data/test/tmp/app/views/devise/registrations/new.html.erb +17 -0
  104. data/test/tmp/app/views/devise/sessions/new.html.erb +15 -0
  105. data/test/tmp/app/views/devise/unlocks/new.html.erb +15 -0
  106. data/test/tmp/app/views/users/_links.erb +25 -0
  107. data/test/tmp/app/views/users/confirmations/new.html.erb +15 -0
  108. data/test/tmp/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
  109. data/test/tmp/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
  110. data/test/tmp/app/views/users/mailer/unlock_instructions.html.erb +7 -0
  111. data/test/tmp/app/views/users/passwords/edit.html.erb +19 -0
  112. data/test/tmp/app/views/users/passwords/new.html.erb +15 -0
  113. data/test/tmp/app/views/users/registrations/edit.html.erb +22 -0
  114. data/test/tmp/app/views/users/registrations/new.html.erb +17 -0
  115. data/test/tmp/app/views/users/sessions/new.html.erb +15 -0
  116. data/test/tmp/app/views/users/unlocks/new.html.erb +15 -0
  117. metadata +78 -26
  118. data/.gitignore +0 -12
  119. data/.travis.yml +0 -13
  120. data/Gemfile +0 -35
  121. data/Rakefile +0 -34
  122. data/devise.gemspec +0 -25
  123. data/lib/devise/controllers/internal_helpers.rb +0 -154
  124. data/lib/devise/controllers/shared_helpers.rb +0 -26
  125. 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
- # * +confirm_within+: the time you want to allow the user to access his account
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 confirm_within is zero, it means users always have to confirm to sign in.
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 its confirmed_at to actual time. If the user
33
- # is already confirmed, add en error to email field
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
- unless_confirmed do
43
+ pending_any_confirmation do
36
44
  self.confirmation_token = nil
37
45
  self.confirmed_at = Time.now.utc
38
- save(:validate => false)
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
- generate_confirmation_token! if self.confirmation_token.nil?
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
- unless_confirmed { send_confirmation_instructions }
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
- # # confirm_within = 1.day and confirmation_sent_at = today
124
+ # # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
92
125
  # confirmation_period_valid? # returns true
93
126
  #
94
- # # confirm_within = 5.days and confirmation_sent_at = 4.days.ago
127
+ # # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
95
128
  # confirmation_period_valid? # returns true
96
129
  #
97
- # # confirm_within = 5.days and confirmation_sent_at = 5.days.ago
130
+ # # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
98
131
  # confirmation_period_valid? # returns false
99
132
  #
100
- # # confirm_within = 0.days
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.confirm_within.ago
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 is confirmed or not, yielding to the block
108
- # if it's already confirmed, otherwise adds an error to email.
109
- def unless_confirmed
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 user is found, returns a new user
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 = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
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
- Devise::Models.config(self, :confirm_within, :confirmation_keys)
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
@@ -79,7 +79,7 @@ module Devise
79
79
  # if the user can login or not (wrong password, etc)
80
80
  unlock_access! if lock_expired?
81
81
 
82
- if super
82
+ if super && !access_locked?
83
83
  self.failed_attempts = 0
84
84
  save(:validate => false)
85
85
  true
@@ -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 should_generate_token?
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 should_generate_token?
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 if respond_to?(:reset_password_sent_at=)
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 if respond_to?(:reset_password_sent_at=)
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 respond_to?(:remember_token)
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 "The #{self.class.name} class does not respond to remember_token and " <<
84
- "authenticatable_salt returns nil. In order to use rememberable, you must " <<
85
- "add a remember_token field to your model or ensure a password is always set."
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, :remember_across_browsers,
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
- # TODO: to_xml does not call serializable_hash. Hopefully someone will fix this in AR.
13
- %w(to_xml serializable_hash).each do |method|
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?(:remember_expired?)
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, :stateless_token)
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, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true, :if => :email_changed?
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
 
@@ -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
@@ -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
- true unless value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(Fixnum)
38
+ [Fixnum, TrueClass, FalseClass, Regexp].none? {|clz| value.is_a? clz }
39
39
  end
40
40
  end
41
41
  end
@@ -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.default_url_options(*args)
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)
@@ -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 controlers. By default, devise will access devise/sessions,
88
- # devise/registrations and so on. If you want to namespace all at once, use module:
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, it has one caveats.
139
- # If you are using a dynamic segment, as below:
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
- # You are required to configure default_url_options in your ApplicationController class level, so
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
- yield if block_given?
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