Class: Mack::SessionStore::Cookie
- Defined in:
- lib/mack/sessions/cookie_session_store.rb
Overview
Stores session information in the user’s cookie. The session information is encrypted using the mack-encryption library. This is the default session store for Mack applications. To set the expiry time for this session store use the following configatron setting:
cookie_session_store::expiry_time: <%= 4.hours %>
It is recommend that you set the configatron setting ‘default_secret_key’ to something, otherwise it will generate a random one each time you start your application, which could make decrypting cookies a bit of a pain. :)
Class Method Summary collapse
-
.expire(id, request, response, cookies) ⇒ Object
Deletes the cookie.
-
.get(id, request, response, cookies) ⇒ Object
Returns a decrypted session from the cookie or nil.
-
.set(id, request, response, cookies) ⇒ Object
Encrypts the session and places it into the cookie.
Methods inherited from Base
Class Method Details
.expire(id, request, response, cookies) ⇒ Object
Deletes the cookie.
36 37 38 39 |
# File 'lib/mack/sessions/cookie_session_store.rb', line 36 def expire(id, request, response, ) .delete(id) response.(id) end |
.get(id, request, response, cookies) ⇒ Object
Returns a decrypted session from the cookie or nil.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mack/sessions/cookie_session_store.rb', line 17 def get(id, request, response, ) c = [id] return nil if c.nil? begin sess = YAML.load(c.decrypt) return sess rescue Exception => e # The cookie was bad, delete it and start a new session. expire(id, request, response, ) return nil end end |
.set(id, request, response, cookies) ⇒ Object
Encrypts the session and places it into the cookie.
31 32 33 |
# File 'lib/mack/sessions/cookie_session_store.rb', line 31 def set(id, request, response, ) [id] = {:value => YAML.dump(request.session).encrypt, :expires => (Time.now + configatron.mack..expiry_time)} end |