Class: Clearance::Session
- Inherits:
-
Object
- Object
- Clearance::Session
- Defined in:
- lib/clearance/session.rb
Constant Summary collapse
- REMEMBER_TOKEN_COOKIE =
"remember_token".freeze
Instance Method Summary collapse
- #add_cookie_to_headers(headers) ⇒ Object
- #current_user ⇒ Object
-
#initialize(env) ⇒ Session
constructor
A new instance of Session.
- #sign_in(user) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Session
Returns a new instance of Session.
5 6 7 |
# File 'lib/clearance/session.rb', line 5 def initialize(env) @env = env end |
Instance Method Details
#add_cookie_to_headers(headers) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/clearance/session.rb', line 29 def (headers) if signed_in? Rack::Utils.(headers, REMEMBER_TOKEN_COOKIE, :value => current_user.remember_token, :expires => Clearance.configuration..call, :path => "/") end end |
#current_user ⇒ Object
13 14 15 16 17 |
# File 'lib/clearance/session.rb', line 13 def current_user @current_user ||= with_remember_token do |token| Clearance.configuration.user_model.find_by_remember_token(token) end end |
#sign_in(user) ⇒ Object
19 20 21 |
# File 'lib/clearance/session.rb', line 19 def sign_in(user) @current_user = user end |
#sign_out ⇒ Object
23 24 25 26 27 |
# File 'lib/clearance/session.rb', line 23 def sign_out current_user.reset_remember_token! if signed_in? @current_user = nil .delete(REMEMBER_TOKEN_COOKIE) end |
#signed_in? ⇒ Boolean
9 10 11 |
# File 'lib/clearance/session.rb', line 9 def signed_in? current_user.present? end |