Module: Authentication::ByCookieToken::ModelInstanceMethods
- Defined in:
- lib/authentication/by_cookie_token.rb
Overview
Instance Methods
Instance Method Summary collapse
-
#forget_me ⇒ Object
Deletes the server-side record of the authentication token.
-
#refresh_token ⇒ Object
refresh token (keeping same expires_at) if it exists.
-
#remember_me ⇒ Object
These create and unset the fields required for remembering users between browser closes.
- #remember_me_for(time) ⇒ Object
- #remember_me_until(time) ⇒ Object
- #remember_token? ⇒ Boolean
Instance Method Details
#forget_me ⇒ Object
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/authentication/by_cookie_token.rb', line 55 def forget_me self.remember_token_expires_at = nil self.remember_token = nil save(false) end |
#refresh_token ⇒ Object
refresh token (keeping same expires_at) if it exists
43 44 45 46 47 48 |
# File '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_me ⇒ Object
These create and unset the fields required for remembering users between browser closes
28 29 30 |
# File '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/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/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
22 23 24 25 |
# File '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 |