Class: Intra::Session
- Inherits:
-
Object
- Object
- Intra::Session
- Defined in:
- lib/intra/session.rb
Instance Method Summary collapse
- #add_cookie_to_headers(headers) ⇒ Object
- #check_timeout ⇒ Object
- #current_user ⇒ Object
-
#initialize(env) ⇒ Session
constructor
A new instance of Session.
- #sign_in(user) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
- #signed_out? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Session
Returns a new instance of Session.
3 4 5 6 7 8 |
# File 'lib/intra/session.rb', line 3 def initialize(env) @env = env @current_user = nil @cookies = nil check_timeout end |
Instance Method Details
#add_cookie_to_headers(headers) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/intra/session.rb', line 10 def (headers) if current_user&.remember_token value = value['remember_token'] = current_user.remember_token = .merge value: value.to_json Rack::Utils. headers, INTRA_COOKIE, end end |
#check_timeout ⇒ Object
45 46 47 |
# File 'lib/intra/session.rb', line 45 def check_timeout sign_out if timed_out? end |
#current_user ⇒ Object
19 20 21 22 23 24 |
# File 'lib/intra/session.rb', line 19 def current_user if remember_token.present? @current_user ||= user_model.find_by(remember_token: remember_token) end @current_user end |
#sign_in(user) ⇒ Object
26 27 28 |
# File 'lib/intra/session.rb', line 26 def sign_in(user) @current_user = user end |
#sign_out ⇒ Object
30 31 32 33 34 35 |
# File 'lib/intra/session.rb', line 30 def sign_out current_user.reset_remember_token! if signed_in? @current_user = nil .delete INTRA_COOKIE end |
#signed_in? ⇒ Boolean
37 38 39 |
# File 'lib/intra/session.rb', line 37 def signed_in? current_user.present? end |
#signed_out? ⇒ Boolean
41 42 43 |
# File 'lib/intra/session.rb', line 41 def signed_out? !signed_in? end |