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 =
'rack.session.record'
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>
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
Writes the session information to the database.
Constructor Details
#initialize(app, options = {}) ⇒ CodeIgniterStore
Returns a new instance of CodeIgniterStore.
15 16 17 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 15 def initialize(app, ={}) super(app, { key: 'default_pyrocms' }.merge()) end |
Instance Method Details
#commit_session?(req, session, options) ⇒ Boolean
Note:
This is called from Rack::Session::Abstract::Persisted#commit_session.
Should the session be persisted?
54 55 56 57 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 54 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.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 97 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 it's 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.
116 117 118 119 120 121 122 123 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 116 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>
Finds an existing session or creates a new one.
30 31 32 33 34 35 36 37 38 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 30 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
Writes the session information to the database.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 70 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 |