Sha256: ba96672998639a0e062b92341c1973e4ecf35edf0c55eb8051b1281a870c0245
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
module RememberMe module Controller def cookie_values Rails.configuration.session_options.slice(:path, :domain, :secure) end def remember_me? params.has_key?(:remember_me) && params[:remember_me] end def scope_of(resource) resource.class.to_s.underscore end def remember_me(resource) resource.remember_me! cookies.signed[remember_key(scope_of resource)] = remember_cookie_values(resource) end def forget_me(resource) resource.forget_me! cookies.delete remember_key(scope_of resource), forget_cookie_values(resource) end 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 def forget_cookie_values(resource) cookie_values.merge!(resource.rememberable_options) end def remember_key(scope) # remember_token_for_user :"_rtf#{scope}" end def remember(scope) cookie = cookies.signed[remember_key(scope)] "#{scope.classify}".constantize.serialize_from_cookie(*cookie) if cookie end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
remember_me-0.0.2 | lib/remember_me/controller.rb |
remember_me-0.0.1 | lib/remember_me/controller.rb |