Module: Authentication::ByCookieToken::ModelInstanceMethods

Defined in:
lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb

Overview

Instance Methods

Instance Method Summary collapse

Instance Method Details

#forget_meObject

Deletes the server-side record of the authentication token. The client-side (browser cookie) and server-side (this remember_token) must always be deleted together.



55
56
57
58
59
# File 'lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb', line 55

def forget_me
  self.remember_token_expires_at = nil
  self.remember_token            = nil
  save(false)
end

#refresh_tokenObject

refresh token (keeping same expires_at) if it exists



43
44
45
46
47
48
# File 'lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb', line 43

def refresh_token
  if remember_token?
    self.remember_token = self.class.make_token 
    save(false)      
  end
end

#remember_meObject

These create and unset the fields required for remembering users between browser closes



28
29
30
# File 'lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb', line 28

def remember_me
  remember_me_for 2.weeks
end

#remember_me_for(time) ⇒ Object



32
33
34
# File 'lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb', line 32

def remember_me_for(time)
  remember_me_until time.from_now.utc
end

#remember_me_until(time) ⇒ Object



36
37
38
39
40
# File 'lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb', line 36

def remember_me_until(time)
  self.remember_token_expires_at = time
  self.remember_token            = self.class.make_token
  save(false)
end

#remember_token?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb', line 22

def remember_token?
  (!remember_token.blank?) && 
    remember_token_expires_at && (Time.now.utc < remember_token_expires_at.utc)
end