Class: ActionDispatch::Session::CodeIgniterStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- ActionDispatch::Session::CodeIgniterStore
- Defined in:
- lib/action_dispatch/session/code_igniter_store.rb
Overview
A session store for Rails to handle Pyro sessions.
Constant Summary collapse
- SESSION_RECORD_KEY =
The key name used to store the session model in the request env.
'rack.session.record'
- ACTION_DISPATCH_LOGGER_KEY =
The request env hash key has the logger instance.
'action_dispatch.logger'
Instance Method Summary collapse
-
#commit_session?(req, session, options) ⇒ Boolean
Should the session be persisted?.
-
#delete_session(req, sid, options) ⇒ String?
Deletes then creates a new session in the database.
-
#extract_session_id(req) ⇒ String?
Tries to find the session ID in the requests cookies.
-
#find_session(req, sid) ⇒ Array<String, Hash, Array>
Finds an existing session or creates a new one.
-
#initialize(app, options = {}) ⇒ CodeIgniterStore
constructor
A new instance of CodeIgniterStore.
-
#write_session(req, sid, session, _options) ⇒ String, FalseClass
Writes the session information to the database.
Constructor Details
#initialize(app, options = {}) ⇒ CodeIgniterStore
Returns a new instance of CodeIgniterStore.
18 19 20 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 18 def initialize(app, ={}) super(app, { key: 'default_pyrocms' }.merge()) end |
Instance Method Details
#commit_session?(req, session, options) ⇒ Boolean
This is called from Rack::Session::Abstract::Persisted#commit_session.
Should the session be persisted?
57 58 59 60 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 57 def commit_session?(req, session, ) # If session_filter returns true then let super decide if we commit the session. Firebug.config.session_filter.call(req) ? super : false end |
#delete_session(req, sid, options) ⇒ String?
Deletes then creates a new session in the database.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 102 def delete_session(req, sid, ) silence_logger(req) do # Get the current database record for this session then delete it. find_session_model(req, sid).delete return if [:drop] req.env[SESSION_RECORD_KEY] = nil # Generate a new one and return its ID find_session_model(req).tap { |s| s.save if [:renew] }.session_id end end |
#extract_session_id(req) ⇒ String?
Tries to find the session ID in the requests cookies.
122 123 124 125 126 127 128 129 130 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 122 def extract_session_id(req) sid = req.[@key] # the request didn't have the session cookie so create a new session ID. return generate_sid if sid.nil? # sometimes the cookie contains just the session ID. return sid if sid.size <= 32 Firebug.(sid)[:session_id] end |
#find_session(req, sid) ⇒ Array<String, Hash, Array>
Finds an existing session or creates a new one.
33 34 35 36 37 38 39 40 41 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 33 def find_session(req, sid) silence_logger(req) do model = find_session_model(req, sid) req.env[SESSION_RECORD_KEY] = model # +Rack::Session::Abstract::Persisted#load_session+ expects this to return an Array with the first value being # the session ID and the second the actual session data. [model.session_id, model.user_data] end end |
#write_session(req, sid, session, _options) ⇒ String, FalseClass
Writes the session information to the database.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 74 def write_session(req, sid, session, ) silence_logger(req) do model = find_session_model(req, sid) model_params = { session_id: model.session_id, user_agent: req.user_agent || '', # user_agent can't be null ip_address: req.remote_ip || '', # ip_address can't be null user_data: session } # Returning false will cause Rack to output a warning. return false unless model.update(model_params) req.env[SESSION_RECORD_KEY] = model # Return the encrypted cookie format of the data. Rack sets this value as the cookie in the response. model. end end |