| Class | Mack::SessionStore::Cookie |
| In: |
lib/mack/sessions/cookie_session_store.rb
|
| Parent: | Mack::SessionStore::Base |
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. :)
Deletes the cookie.
# File lib/mack/sessions/cookie_session_store.rb, line 36
36: def expire(id, request, response, cookies)
37: cookies.delete(id)
38: response.delete_cookie(id)
39: end
Returns a decrypted session from the cookie or nil.
# File lib/mack/sessions/cookie_session_store.rb, line 17
17: def get(id, request, response, cookies)
18: c = cookies[id]
19: return nil if c.nil?
20: begin
21: sess = YAML.load(c.decrypt)
22: return sess
23: rescue Exception => e
24: # The cookie was bad, delete it and start a new session.
25: expire(id, request, response, cookies)
26: return nil
27: end
28: end
Encrypts the session and places it into the cookie.
# File lib/mack/sessions/cookie_session_store.rb, line 31
31: def set(id, request, response, cookies)
32: cookies[id] = {:value => YAML.dump(request.session).encrypt, :expires => (Time.now + configatron.mack.cookie_session_store.expiry_time)}
33: end