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?
|
2010-07-23 17:57:31 -04:00
|
|
|
resource.remember_me!(extend_remember_period?)
|
2010-03-31 15:43:19 -04:00
|
|
|
|
2010-05-16 08:13:43 -04:00
|
|
|
configuration = {
|
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
|
|
|
|
2010-05-16 08:13:43 -04:00
|
|
|
configuration[:domain] = resource.cookie_domain if resource.cookie_domain?
|
|
|
|
cookies.signed["remember_#{scope}_token"] = configuration
|
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
|
|
|
|
2010-07-23 17:57:31 -04:00
|
|
|
def succeeded?
|
|
|
|
@result == :success
|
|
|
|
end
|
|
|
|
|
|
|
|
def extend_remember_period?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|