Module: Devise::Controllers::Rememberable

Included in:
Hooks::Proxy
Defined in:
lib/devise/controllers/rememberable.rb

Overview

A module that may be optionally included in a controller in order to provide remember me behavior. Useful when signing in is done through a callback, like in OmniAuth.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

Return default cookie values retrieved from session options.



8
9
10
# File 'lib/devise/controllers/rememberable.rb', line 8

def self.cookie_values
  Rails.configuration.session_options.slice(:path, :domain, :secure)
end

Instance Method Details



36
37
38
# File 'lib/devise/controllers/rememberable.rb', line 36

def forget_cookie_values(resource)
  Devise::Controllers::Rememberable.cookie_values.merge!(resource.rememberable_options)
end

#forget_me(resource) ⇒ Object

Forgets the given resource by deleting a cookie



28
29
30
31
32
# File 'lib/devise/controllers/rememberable.rb', line 28

def forget_me(resource)
  scope = Devise::Mapping.find_scope!(resource)
  resource.forget_me!
  cookies.delete(remember_key(resource, scope), forget_cookie_values(resource))
end


40
41
42
43
44
45
46
47
# File 'lib/devise/controllers/rememberable.rb', line 40

def remember_cookie_values(resource)
  options = { httponly: true }
  options.merge!(forget_cookie_values(resource))
  options.merge!(
    value: resource.class.serialize_into_cookie(resource),
    expires: resource.remember_expires_at
  )
end

#remember_key(resource, scope) ⇒ Object (protected)



49
50
51
# File 'lib/devise/controllers/rememberable.rb', line 49

def remember_key(resource, scope)
  resource.rememberable_options.fetch(:key, "remember_#{scope}_token")
end

#remember_me(resource) ⇒ Object

Remembers the given resource by setting up a cookie



20
21
22
23
24
25
# File 'lib/devise/controllers/rememberable.rb', line 20

def remember_me(resource)
  return if env["devise.skip_storage"]
  scope = Devise::Mapping.find_scope!(resource)
  resource.remember_me!
  cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
end

#remember_me_is_active?(resource) ⇒ Boolean



12
13
14
15
16
17
# File 'lib/devise/controllers/rememberable.rb', line 12

def remember_me_is_active?(resource)
  return false unless resource.respond_to?(:remember_me)
  scope = Devise::Mapping.find_scope!(resource)
  _, token, generated_at = cookies.signed[remember_key(resource, scope)]
  resource.remember_me?(token, generated_at)
end