2010-03-31 15:43:19 -04:00
|
|
|
module Devise
|
|
|
|
module Hooks
|
|
|
|
# Overwrite success! in authentication strategies allowing users to be remembered.
|
2010-04-06 10:34:22 -04:00
|
|
|
# We choose to implement this as an strategy hook instead of a warden hook to allow a specific
|
|
|
|
# strategy (like token authenticatable or facebook authenticatable) to turn off remember_me?
|
|
|
|
# cookies.
|
2010-03-31 15:43:19 -04:00
|
|
|
module Rememberable #:nodoc:
|
|
|
|
def success!(resource)
|
|
|
|
super
|
|
|
|
|
|
|
|
if succeeded? && resource.respond_to?(:remember_me!) && remember_me?
|
|
|
|
resource.remember_me!
|
|
|
|
|
2010-05-05 13:25:59 -04:00
|
|
|
conf = {
|
2010-03-31 15:43:19 -04:00
|
|
|
:value => resource.class.serialize_into_cookie(resource),
|
|
|
|
:expires => resource.remember_expires_at,
|
|
|
|
:path => "/"
|
|
|
|
}
|
2010-05-05 13:25:59 -04:00
|
|
|
|
|
|
|
conf[:domain] = resource.cookie_domain if resource.cookie_domain?
|
|
|
|
|
|
|
|
Warden::Manager.after_set_user do |record, warden, options|
|
|
|
|
warden.cookies["remember_#{options[:scope]}_token"] = conf
|
|
|
|
end
|
2010-03-31 15:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-06 10:34:22 -04:00
|
|
|
protected
|
2010-03-31 15:43:19 -04:00
|
|
|
|
|
|
|
def remember_me?
|
2010-04-01 16:11:59 -04:00
|
|
|
valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
|
2010-03-31 15:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-05 13:25:59 -04:00
|
|
|
Devise::Strategies::Authenticatable.send :include, Devise::Hooks::Rememberable
|
|
|
|
|