Class: ConstantContact::Auth::Session
- Inherits:
-
Object
- Object
- ConstantContact::Auth::Session
- Defined in:
- lib/constantcontact/auth/session_data_store.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
-
#add_user(username, params) ⇒ Object
Add a new user to the data store.
-
#close ⇒ Object
Close current session.
-
#delete_user(username) ⇒ Object
Delete an existing user from the data store.
-
#get_user(username) ⇒ String
Get an existing user from the data store.
-
#initialize ⇒ Session
constructor
Create and initialize the session.
-
#update_user(username, params) ⇒ Object
Update an existing user in the data store.
Constructor Details
#initialize ⇒ Session
Create and initialize the session
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 13 def initialize cgi = CGI.new('html4') # We make sure to delete an old session if one exists, # not just to free resources, but to prevent the session # from being maliciously hijacked later on. begin @session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, 'new_session' => false) @session.delete rescue ArgumentError # if no old session end @session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, 'new_session' => true) @session['datastore'] = {} end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session
10 11 12 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 10 def session @session end |
Instance Method Details
#add_user(username, params) ⇒ Object
Add a new user to the data store
32 33 34 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 32 def add_user(username, params) @session['datastore'][username] = params end |
#close ⇒ Object
Close current session
62 63 64 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 62 def close @session.close end |
#delete_user(username) ⇒ Object
Delete an existing user from the data store
56 57 58 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 56 def delete_user(username) @session['datastore'][username] = nil end |
#get_user(username) ⇒ String
Get an existing user from the data store
39 40 41 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 39 def get_user(username) @session['datastore'].has_key?(username) ? @session['datastore'][username] : false end |
#update_user(username, params) ⇒ Object
Update an existing user in the data store
47 48 49 50 51 |
# File 'lib/constantcontact/auth/session_data_store.rb', line 47 def update_user(username, params) if @session['datastore'].has_key?(username) @session['datastore'][username] = params end end |