devise 1.2.rc → 1.2.rc2

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.

Files changed (101) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.rdoc +45 -1
  4. data/Gemfile +29 -0
  5. data/Gemfile.lock +158 -0
  6. data/MIT-LICENSE +1 -1
  7. data/README.rdoc +25 -8
  8. data/Rakefile +34 -0
  9. data/TODO +4 -0
  10. data/app/controllers/devise/omniauth_callbacks_controller.rb +3 -3
  11. data/app/controllers/devise/registrations_controller.rb +4 -4
  12. data/app/controllers/devise/sessions_controller.rb +3 -2
  13. data/app/helpers/devise_helper.rb +6 -0
  14. data/config/locales/en.yml +2 -0
  15. data/devise.gemspec +25 -0
  16. data/lib/devise.rb +31 -5
  17. data/lib/devise/controllers/helpers.rb +30 -29
  18. data/lib/devise/controllers/internal_helpers.rb +6 -1
  19. data/lib/devise/controllers/rememberable.rb +52 -0
  20. data/lib/devise/encryptors/authlogic_sha512.rb +1 -1
  21. data/lib/devise/failure_app.rb +20 -4
  22. data/lib/devise/hooks/forgetable.rb +1 -4
  23. data/lib/devise/hooks/rememberable.rb +5 -44
  24. data/lib/devise/hooks/timeoutable.rb +1 -1
  25. data/lib/devise/models.rb +4 -2
  26. data/lib/devise/models/authenticatable.rb +13 -3
  27. data/lib/devise/models/confirmable.rb +3 -3
  28. data/lib/devise/models/database_authenticatable.rb +5 -3
  29. data/lib/devise/models/encryptable.rb +9 -2
  30. data/lib/devise/models/lockable.rb +18 -13
  31. data/lib/devise/models/recoverable.rb +9 -1
  32. data/lib/devise/models/registerable.rb +1 -1
  33. data/lib/devise/models/rememberable.rb +2 -5
  34. data/lib/devise/models/token_authenticatable.rb +4 -4
  35. data/lib/devise/omniauth.rb +3 -18
  36. data/lib/devise/omniauth/test_helpers.rb +14 -40
  37. data/lib/devise/omniauth/url_helpers.rb +6 -2
  38. data/lib/devise/rails.rb +3 -2
  39. data/lib/devise/rails/warden_compat.rb +5 -0
  40. data/lib/devise/schema.rb +3 -2
  41. data/lib/devise/strategies/authenticatable.rb +15 -1
  42. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  43. data/lib/devise/strategies/rememberable.rb +6 -5
  44. data/lib/devise/strategies/token_authenticatable.rb +1 -1
  45. data/lib/devise/test_helpers.rb +3 -3
  46. data/lib/devise/version.rb +1 -1
  47. data/lib/generators/active_record/devise_generator.rb +2 -2
  48. data/lib/generators/active_record/templates/migration.rb +1 -0
  49. data/lib/generators/devise/devise_generator.rb +3 -1
  50. data/lib/generators/devise/orm_helpers.rb +1 -2
  51. data/lib/generators/devise/views_generator.rb +8 -45
  52. data/lib/generators/mongoid/devise_generator.rb +2 -2
  53. data/lib/generators/templates/devise.rb +19 -7
  54. data/test/controllers/helpers_test.rb +35 -5
  55. data/test/devise_test.rb +10 -0
  56. data/test/failure_app_test.rb +32 -3
  57. data/test/generators/active_record_generator_test.rb +24 -0
  58. data/test/generators/devise_generator_test.rb +33 -0
  59. data/test/generators/install_generator_test.rb +3 -4
  60. data/test/generators/mongoid_generator_test.rb +22 -0
  61. data/test/generators/views_generator_test.rb +13 -15
  62. data/test/indifferent_hash.rb +33 -0
  63. data/test/integration/authenticatable_test.rb +7 -0
  64. data/test/integration/omniauthable_test.rb +67 -32
  65. data/test/integration/registerable_test.rb +30 -0
  66. data/test/integration/rememberable_test.rb +16 -6
  67. data/test/integration/token_authenticatable_test.rb +43 -5
  68. data/test/models/confirmable_test.rb +20 -3
  69. data/test/models/encryptable_test.rb +1 -1
  70. data/test/models/lockable_test.rb +36 -15
  71. data/test/models/recoverable_test.rb +20 -11
  72. data/test/models/token_authenticatable_test.rb +19 -1
  73. data/test/models_test.rb +7 -0
  74. data/test/omniauth/test_helpers_test.rb +25 -0
  75. data/test/omniauth/url_helpers_test.rb +7 -0
  76. data/test/rails_app/Rakefile +10 -0
  77. data/test/rails_app/app/controllers/application_controller.rb +0 -1
  78. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
  79. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  80. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  81. data/test/rails_app/app/views/home/index.html.erb +1 -0
  82. data/test/rails_app/app/views/home/private.html.erb +1 -0
  83. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  84. data/test/rails_app/app/views/users/index.html.erb +1 -0
  85. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  86. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  87. data/test/rails_app/config.ru +4 -0
  88. data/test/rails_app/config/application.rb +5 -0
  89. data/test/rails_app/config/database.yml +18 -0
  90. data/test/rails_app/config/initializers/devise.rb +18 -2
  91. data/test/rails_app/public/404.html +26 -0
  92. data/test/rails_app/public/422.html +26 -0
  93. data/test/rails_app/public/500.html +26 -0
  94. data/test/rails_app/public/favicon.ico +0 -0
  95. data/test/rails_app/script/rails +10 -0
  96. data/test/schema_test.rb +33 -0
  97. data/test/support/locale/en.yml +4 -0
  98. data/test/test_helper.rb +5 -2
  99. data/test/test_helpers_test.rb +33 -0
  100. metadata +71 -20
  101. data/test/generators/generators_test_helper.rb +0 -4
@@ -11,8 +11,9 @@ class Devise::SessionsController < ApplicationController
11
11
  # POST /resource/sign_in
12
12
  def create
13
13
  resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
14
- set_flash_message :notice, :signed_in
15
- sign_in_and_redirect(resource_name, resource)
14
+ set_flash_message(:notice, :signed_in) if is_navigational_format?
15
+ sign_in(resource_name, resource)
16
+ respond_with resource, :location => redirect_location(resource_name, resource)
16
17
  end
17
18
 
18
19
  # GET /resource/sign_out
@@ -1,4 +1,10 @@
1
1
  module DeviseHelper
2
+ # A simple way to show error messages for the current devise resource. If you need
3
+ # to customize this method, you can either overwrite it in your application helpers or
4
+ # copy the views to your application.
5
+ #
6
+ # This method is intended to stay simple and it is unlikely that we are going to change
7
+ # it to add more behavior or options.
2
8
  def devise_error_messages!
3
9
  return "" if resource.errors.empty?
4
10
 
@@ -1,3 +1,5 @@
1
+ # Additional translations at http://github.com/plataformatec/devise/wiki/I18n
2
+
1
3
  en:
2
4
  errors:
3
5
  messages:
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "devise/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "devise"
7
+ s.version = Devise::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Flexible authentication solution for Rails with Warden"
10
+ s.email = "contact@plataformatec.com.br"
11
+ s.homepage = "http://github.com/plataformatec/devise"
12
+ s.description = "Flexible authentication solution for Rails with Warden"
13
+ s.authors = ['José Valim', 'Carlos Antônio']
14
+
15
+ s.rubyforge_project = "devise"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("warden", "~> 1.0.3")
23
+ s.add_dependency("orm_adapter", "~> 0.0.3")
24
+ s.add_dependency("bcrypt-ruby", "~> 2.1.2")
25
+ end
@@ -1,3 +1,4 @@
1
+ require 'rails'
1
2
  require 'active_support/core_ext/numeric/time'
2
3
  require 'active_support/dependencies'
3
4
  require 'orm_adapter'
@@ -13,6 +14,7 @@ module Devise
13
14
  module Controllers
14
15
  autoload :Helpers, 'devise/controllers/helpers'
15
16
  autoload :InternalHelpers, 'devise/controllers/internal_helpers'
17
+ autoload :Rememberable, 'devise/controllers/rememberable'
16
18
  autoload :ScopedViews, 'devise/controllers/scoped_views'
17
19
  autoload :UrlHelpers, 'devise/controllers/url_helpers'
18
20
  end
@@ -68,8 +70,9 @@ module Devise
68
70
  @@request_keys = []
69
71
 
70
72
  # Keys that should be case-insensitive.
73
+ # Empty by default for backwards compatibility.
71
74
  mattr_accessor :case_insensitive_keys
72
- @@case_insensitive_keys = [ :email ]
75
+ @@case_insensitive_keys = []
73
76
 
74
77
  # If http authentication is enabled by default.
75
78
  mattr_accessor :http_authenticatable
@@ -89,7 +92,7 @@ module Devise
89
92
 
90
93
  # Email regex used to validate email formats. Adapted from authlogic.
91
94
  mattr_accessor :email_regexp
92
- @@email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
95
+ @@email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
93
96
 
94
97
  # Range validation for password length
95
98
  mattr_accessor :password_length
@@ -116,6 +119,10 @@ module Devise
116
119
  mattr_accessor :confirm_within
117
120
  @@confirm_within = 0.days
118
121
 
122
+ # Defines which key will be used when confirming an account
123
+ mattr_accessor :confirmation_keys
124
+ @@confirmation_keys = [ :email ]
125
+
119
126
  # Time interval to timeout the user session without activity.
120
127
  mattr_accessor :timeout_in
121
128
  @@timeout_in = 30.minutes
@@ -143,6 +150,10 @@ module Devise
143
150
  mattr_accessor :lock_strategy
144
151
  @@lock_strategy = :failed_attempts
145
152
 
153
+ # Defines which key will be used when locking and unlocking an account
154
+ mattr_accessor :unlock_keys
155
+ @@unlock_keys = [ :email ]
156
+
146
157
  # Defines which strategy can be used to unlock an account.
147
158
  # Values: :email, :time, :both
148
159
  mattr_accessor :unlock_strategy
@@ -156,6 +167,10 @@ module Devise
156
167
  mattr_accessor :unlock_in
157
168
  @@unlock_in = 1.hour
158
169
 
170
+ # Defines which key will be used when recovering the password for an account
171
+ mattr_accessor :reset_password_keys
172
+ @@reset_password_keys = [ :email ]
173
+
159
174
  # The default scope which is used by warden.
160
175
  mattr_accessor :default_scope
161
176
  @@default_scope = nil
@@ -173,10 +188,11 @@ module Devise
173
188
  @@stateless_token = false
174
189
 
175
190
  # Which formats should be treated as navigational.
191
+ # We need both :"*/*" and "*/*" to work on different Rails versions.
176
192
  mattr_accessor :navigational_formats
177
- @@navigational_formats = [:"*/*", :html]
193
+ @@navigational_formats = [:"*/*", "*/*", :html]
178
194
 
179
- # When set to true, signing out an user signs out all other scopes.
195
+ # When set to true, signing out a user signs out all other scopes.
180
196
  mattr_accessor :sign_out_all_scopes
181
197
  @@sign_out_all_scopes = true
182
198
 
@@ -357,7 +373,17 @@ module Devise
357
373
 
358
374
  # Generate a friendly string randomically to be used as token.
359
375
  def self.friendly_token
360
- ActiveSupport::SecureRandom.base64(44).tr('+/=', 'xyz')
376
+ ActiveSupport::SecureRandom.base64(15).tr('+/=', 'xyz')
377
+ end
378
+
379
+ # constant-time comparison algorithm to prevent timing attacks
380
+ def self.secure_compare(a, b)
381
+ return false if a.blank? || b.blank? || a.bytesize != b.bytesize
382
+ l = a.unpack "C#{a.bytesize}"
383
+
384
+ res = 0
385
+ b.each_byte { |byte| res |= byte ^ l.shift }
386
+ res == 0
361
387
  end
362
388
  end
363
389
 
@@ -21,7 +21,7 @@ module Devise
21
21
  # Generated methods:
22
22
  # authenticate_user! # Signs user in or redirect
23
23
  # authenticate_admin! # Signs admin in or redirect
24
- # user_signed_in? # Checks whether there is an user signed in or not
24
+ # user_signed_in? # Checks whether there is a user signed in or not
25
25
  # admin_signed_in? # Checks whether there is an admin signed in or not
26
26
  # current_user # Current signed in user
27
27
  # current_admin # Current signed in admin
@@ -36,8 +36,8 @@ module Devise
36
36
  mapping = mapping.name
37
37
 
38
38
  class_eval <<-METHODS, __FILE__, __LINE__ + 1
39
- def authenticate_#{mapping}!
40
- warden.authenticate!(:scope => :#{mapping})
39
+ def authenticate_#{mapping}!(force = false)
40
+ warden.authenticate!(:scope => :#{mapping}) if !devise_controller? || force
41
41
  end
42
42
 
43
43
  def #{mapping}_signed_in?
@@ -72,19 +72,21 @@ module Devise
72
72
  false
73
73
  end
74
74
 
75
- # Check if the given scope is signed in session, without running
76
- # authentication hooks.
77
- def signed_in?(scope)
78
- warden.authenticate?(:scope => scope)
75
+ # Return true if the given scope is signed in session. If no scope given, return
76
+ # true if any scope is signed in. Does not run authentication hooks.
77
+ def signed_in?(scope=nil)
78
+ [ scope || Devise.mappings.keys ].flatten.any? do |scope|
79
+ warden.authenticate?(:scope => scope)
80
+ end
79
81
  end
80
82
 
81
- # Check if the any scope is signed in session, without running
82
- # authentication hooks.
83
83
  def anybody_signed_in?
84
- Devise.mappings.keys.any? { |scope| signed_in?(scope) }
84
+ ActiveSupport::Deprecation.warn "Devise#anybody_signed_in? is deprecated. "
85
+ "Please use Devise#signed_in?(nil) instead."
86
+ signed_in?
85
87
  end
86
88
 
87
- # Sign in an user that already was authenticated. This helper is useful for logging
89
+ # Sign in a user that already was authenticated. This helper is useful for logging
88
90
  # users in after sign up.
89
91
  #
90
92
  # All options given to sign_in is passed forward to the set_user method in warden.
@@ -108,12 +110,14 @@ module Devise
108
110
 
109
111
  if options[:bypass]
110
112
  warden.session_serializer.store(resource, scope)
113
+ elsif warden.user(scope) == resource && !options.delete(:force)
114
+ # Do nothing. User already signed in and we are not forcing it.
111
115
  else
112
116
  warden.set_user(resource, options.merge!(:scope => scope))
113
117
  end
114
118
  end
115
119
 
116
- # Sign out a given user or scope. This helper is useful for signing out an user
120
+ # Sign out a given user or scope. This helper is useful for signing out a user
117
121
  # after deleting accounts.
118
122
  #
119
123
  # Examples:
@@ -132,6 +136,7 @@ module Devise
132
136
  # Sign out all active users or scopes. This helper is useful for signing out all roles
133
137
  # in one click. This signs out ALL scopes in warden.
134
138
  def sign_out_all_scopes
139
+ Devise.mappings.keys.each { |s| warden.user(s) }
135
140
  warden.raw_session.inspect
136
141
  warden.logout
137
142
  end
@@ -180,7 +185,7 @@ module Devise
180
185
  respond_to?(home_path, true) ? send(home_path) : root_path
181
186
  end
182
187
 
183
- # Method used by sessions controller to sign out an user. You can overwrite
188
+ # Method used by sessions controller to sign out a user. You can overwrite
184
189
  # it in your ApplicationController to provide a custom hook for a custom
185
190
  # scope. Notice that differently from +after_sign_in_path_for+ this method
186
191
  # receives a symbol with the scope, and not the resource.
@@ -190,36 +195,26 @@ module Devise
190
195
  root_path
191
196
  end
192
197
 
193
- # Sign in an user and tries to redirect first to the stored location and
198
+ # Sign in a user and tries to redirect first to the stored location and
194
199
  # then to the url specified by after_sign_in_path_for. It accepts the same
195
200
  # parameters as the sign_in method.
196
201
  def sign_in_and_redirect(resource_or_scope, *args)
197
202
  options = args.extract_options!
198
203
  scope = Devise::Mapping.find_scope!(resource_or_scope)
199
204
  resource = args.last || resource_or_scope
200
-
201
- if warden.user(scope) == resource
202
- expire_session_data_after_sign_in!
203
- else
204
- sign_in(scope, resource, options)
205
- end
206
-
207
- redirect_for_sign_in(scope, resource)
205
+ sign_in(scope, resource, options)
206
+ redirect_to redirect_location(scope, resource)
208
207
  end
209
208
 
210
- def redirect_for_sign_in(scope, resource) #:nodoc:
211
- redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
209
+ def redirect_location(scope, resource) #:nodoc:
210
+ stored_location_for(scope) || after_sign_in_path_for(resource)
212
211
  end
213
212
 
214
- # Sign out an user and tries to redirect to the url specified by
213
+ # Sign out a user and tries to redirect to the url specified by
215
214
  # after_sign_out_path_for.
216
215
  def sign_out_and_redirect(resource_or_scope)
217
216
  scope = Devise::Mapping.find_scope!(resource_or_scope)
218
217
  Devise.sign_out_all_scopes ? sign_out : sign_out(scope)
219
- redirect_for_sign_out(scope)
220
- end
221
-
222
- def redirect_for_sign_out(scope) #:nodoc:
223
218
  redirect_to after_sign_out_path_for(scope)
224
219
  end
225
220
 
@@ -228,6 +223,12 @@ module Devise
228
223
  def expire_session_data_after_sign_in!
229
224
  session.keys.grep(/^devise\./).each { |k| session.delete(k) }
230
225
  end
226
+
227
+ # Overwrite Rails' handle unverified request to sign out all scopes.
228
+ def handle_unverified_request
229
+ sign_out_all_scopes
230
+ super # call the default behaviour which resets the session
231
+ end
231
232
  end
232
233
  end
233
234
  end
@@ -16,7 +16,7 @@ module Devise
16
16
  helper_method *helpers
17
17
 
18
18
  prepend_before_filter :is_devise_resource?
19
- skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
19
+ respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
20
20
  end
21
21
 
22
22
  # Gets the actual resource stored in the instance variable
@@ -57,6 +57,11 @@ module Devise
57
57
  unknown_action!("Could not find devise mapping for path #{request.fullpath.inspect}") unless devise_mapping
58
58
  end
59
59
 
60
+ # Check whether it's navigational format, such as :html or :iphone, or not.
61
+ def is_navigational_format?
62
+ Devise.navigational_formats.include?(request.format.to_sym)
63
+ end
64
+
60
65
  def unknown_action!(msg)
61
66
  logger.debug "[Devise] #{msg}" if logger
62
67
  raise ActionController::UnknownAction, msg
@@ -0,0 +1,52 @@
1
+ module Devise
2
+ module Controllers
3
+ # A module that may be optionally included in a controller in order
4
+ # to provide remember me behavior.
5
+ module Rememberable
6
+ # Return default cookie values retrieved from session options.
7
+ def self.cookie_values
8
+ Rails.configuration.session_options.slice(:path, :domain, :secure)
9
+ end
10
+
11
+ # A small warden proxy so we can remember and forget uses from hooks.
12
+ class Proxy #:nodoc:
13
+ include Devise::Controllers::Rememberable
14
+
15
+ delegate :cookies, :env, :to => :@warden
16
+
17
+ def initialize(warden)
18
+ @warden = warden
19
+ end
20
+ end
21
+
22
+ # Remembers the given resource by setting up a cookie
23
+ def remember_me(resource)
24
+ scope = Devise::Mapping.find_scope!(resource)
25
+ resource.remember_me!(resource.extend_remember_period)
26
+ cookies.signed["remember_#{scope}_token"] = remember_cookie_values(resource)
27
+ end
28
+
29
+ # Forgets the given resource by deleting a cookie
30
+ def forget_me(resource)
31
+ scope = Devise::Mapping.find_scope!(resource)
32
+ resource.forget_me! unless resource.frozen?
33
+ cookies.delete("remember_#{scope}_token", forget_cookie_values(resource))
34
+ end
35
+
36
+ protected
37
+
38
+ def forget_cookie_values(resource)
39
+ Devise::Controllers::Rememberable.cookie_values.merge!(resource.cookie_options)
40
+ end
41
+
42
+ def remember_cookie_values(resource)
43
+ options = { :httponly => true }
44
+ options.merge!(forget_cookie_values(resource))
45
+ options.merge!(
46
+ :value => resource.class.serialize_into_cookie(resource),
47
+ :expires => resource.remember_expires_at
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
@@ -4,7 +4,7 @@ module Devise
4
4
  module Encryptors
5
5
  # = AuthlogicSha512
6
6
  # Simulates Authlogic's default encryption mechanism.
7
- # Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to silumate
7
+ # Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to simulate
8
8
  # the default behavior.
9
9
  class AuthlogicSha512 < Base
10
10
  # Gererates a default password digest based on salt, pepper and the
@@ -64,7 +64,11 @@ module Devise
64
64
  end
65
65
 
66
66
  def redirect_url
67
- send(:"new_#{scope}_session_path")
67
+ if request_format == :html
68
+ send(:"new_#{scope}_session_path")
69
+ else
70
+ send(:"new_#{scope}_session_path", :format => request_format)
71
+ end
68
72
  end
69
73
 
70
74
  # Choose whether we should respond in a http authentication fashion,
@@ -79,7 +83,7 @@ module Devise
79
83
  if request.xhr?
80
84
  Devise.http_authenticatable_on_xhr
81
85
  else
82
- !(request.format && Devise.navigational_formats.include?(request.format.to_sym))
86
+ !(request_format && Devise.navigational_formats.include?(request_format))
83
87
  end
84
88
  end
85
89
 
@@ -90,8 +94,8 @@ module Devise
90
94
  end
91
95
 
92
96
  def http_auth_body
93
- return i18n_message unless request.format
94
- method = "to_#{request.format.to_sym}"
97
+ return i18n_message unless request_format
98
+ method = "to_#{request_format}"
95
99
  {}.respond_to?(method) ? { :error => i18n_message }.send(method) : i18n_message
96
100
  end
97
101
 
@@ -123,5 +127,17 @@ module Devise
123
127
  def store_location!
124
128
  session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
125
129
  end
130
+
131
+ MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
132
+
133
+ def request_format
134
+ @request_format ||= if request.format.respond_to?(:ref)
135
+ request.format.ref
136
+ elsif MIME_REFERENCES
137
+ request.format
138
+ else # Rails < 3.0.4
139
+ request.format.to_sym
140
+ end
141
+ end
126
142
  end
127
143
  end
@@ -4,9 +4,6 @@
4
4
  # This avoids forgetting deleted users.
5
5
  Warden::Manager.before_logout do |record, warden, options|
6
6
  if record.respond_to?(:forget_me!)
7
- record.forget_me! unless record.frozen?
8
- cookie_options = Rails.configuration.session_options.slice(:path, :domain, :secure)
9
- cookie_options.merge!(record.cookie_options)
10
- warden.cookies.delete("remember_#{options[:scope]}_token", cookie_options)
7
+ Devise::Controllers::Rememberable::Proxy.new(warden).forget_me(record)
11
8
  end
12
9
  end
@@ -1,45 +1,6 @@
1
- module Devise
2
- module Hooks
3
- # Overwrite success! in authentication strategies allowing users to be remembered.
4
- # We choose to implement this as an strategy hook instead of a warden hook to allow a specific
5
- # strategy (like token authenticatable or facebook authenticatable) to turn off remember_me?
6
- # cookies.
7
- module Rememberable #:nodoc:
8
- def success!(resource)
9
- super
10
-
11
- if succeeded? && resource.respond_to?(:remember_me!) && remember_me?
12
- resource.remember_me!(extend_remember_period?)
13
- cookies.signed["remember_#{scope}_token"] = cookie_values(resource)
14
- end
15
- end
16
-
17
- protected
18
-
19
- def cookie_values(resource)
20
- options = Rails.configuration.session_options.slice(:path, :domain, :secure)
21
- options.merge!(resource.cookie_options)
22
- options.merge!(
23
- :value => resource.class.serialize_into_cookie(resource),
24
- :expires => resource.remember_expires_at
25
- )
26
- options
27
- end
28
-
29
- def succeeded?
30
- @result == :success
31
- end
32
-
33
- def extend_remember_period?
34
- false
35
- end
36
-
37
- def remember_me?
38
- valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
39
- end
40
- end
1
+ Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
2
+ scope = options[:scope]
3
+ if record.respond_to?(:remember_me) && record.remember_me && warden.authenticated?(scope)
4
+ Devise::Controllers::Rememberable::Proxy.new(warden).remember_me(record)
41
5
  end
42
- end
43
-
44
- Devise::Strategies::Authenticatable.send :include, Devise::Hooks::Rememberable
45
-
6
+ end