Class: WackyCanvas::Session
- Inherits:
-
Object
- Object
- WackyCanvas::Session
- Defined in:
- lib/wacky_canvas/session.rb
Constant Summary collapse
- REMEMBER_TOKEN_COOKIE =
"remember_token".freeze
Instance Method Summary collapse
- #add_remember_cookie(headers) ⇒ Object
- #current_signed_request ⇒ Object
- #current_user ⇒ Object
-
#initialize(env) ⇒ Session
constructor
A new instance of Session.
- #request ⇒ Object
- #signed_in? ⇒ Boolean
- #signed_request? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Session
Returns a new instance of Session.
5 6 7 |
# File 'lib/wacky_canvas/session.rb', line 5 def initialize(env) @env = env end |
Instance Method Details
#add_remember_cookie(headers) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/wacky_canvas/session.rb', line 29 def (headers) # Make sure the user has been saved if signed_in? && !current_user.new_record? # The cookie expiration is only a day since we always get a signed request Rack::Utils.(headers, REMEMBER_TOKEN_COOKIE, :value => current_user.remember_token, :expires => 1.day.from_now, :path => "/") end end |
#current_signed_request ⇒ Object
13 14 15 |
# File 'lib/wacky_canvas/session.rb', line 13 def current_signed_request @current_signed_request ||= parse_signed_request(request.params['signed_request']) end |
#current_user ⇒ Object
9 10 11 |
# File 'lib/wacky_canvas/session.rb', line 9 def current_user @current_user ||= get_current_user end |
#request ⇒ Object
25 26 27 |
# File 'lib/wacky_canvas/session.rb', line 25 def request @request ||= Rack::Request.new(@env) end |
#signed_in? ⇒ Boolean
17 18 19 |
# File 'lib/wacky_canvas/session.rb', line 17 def signed_in? current_user.present? end |
#signed_request? ⇒ Boolean
21 22 23 |
# File 'lib/wacky_canvas/session.rb', line 21 def signed_request? current_signed_request.present? end |