Class: AbstractStore::SessionHash
- Inherits:
-
Object
- Object
- AbstractStore::SessionHash
- Includes:
- Sessionvoc::Open::DataConversion
- Defined in:
- lib/sessionvoc-store/open/sessionvoc_store.rb
Overview
Monkey patch to include SessionVOC specific methods into the session context. Convenience methods for the SessionVOC client.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Overriden method to incept session hash access.
-
#[]=(key, value) ⇒ Object
Overriden method to incept session hash access.
-
#create_nonce(options = {}) ⇒ Object
Creates a one time use nonce.
-
#delete_form_data(fid, options = {}) ⇒ Object
Deletes a form context in SessionVOC === Parameters * fid = Form Id * options.
-
#get_form_data(fid, options = {}) ⇒ Object
Returns a form context from SessionVOC identified by a fid.
-
#login(sid, uid, password, options = {}) ⇒ Object
Performs an authentification against SessionVOC.
-
#logout(sid, options = {}) ⇒ Object
Performs a user logout.
-
#new_form ⇒ Object
Creates a new form context within this session.
-
#nonce_still_valid?(nonce, options = {}) ⇒ Boolean
Checks if the nonce is still valid and has not been used yet.
-
#set_form_data(fid, data, options = {}) ⇒ Object
Updates/replaces the form data identified by a sid in SessionVOC.
-
#set_trans_data(sid, key, value, options = {}) ⇒ Object
Adds a key/value pair to the transData context of a SessionVOC session.
-
#set_user_data(sid, key, value, options = {}) ⇒ Object
Adds a key/value pair to the userData context of a SessionVOC session.
Methods included from Sessionvoc::Open::DataConversion
#convert, #datainfo, #enforce_value_type
Instance Method Details
#[](key) ⇒ Object
Overriden method to incept session hash access.
Parameters
-
key = Session key
13 14 15 16 17 18 19 20 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 13 def [](key) if key == :_csrf_token self['transData']['_csrf_token'] if self['transData'] else load_for_read! super(key.to_s) end end |
#[]=(key, value) ⇒ Object
Overriden method to incept session hash access.
Parameters
-
key = Session key
-
value = Value
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 26 def []=(key, value) if key == :_csrf_token self['transData'] = {} unless self['transData'] self['transData']['_csrf_token'] = value ActionDispatch::Session::SessionvocStore::Session.client.update(self['sid'], self) else load_for_write! super(key.to_s, value) end end |
#create_nonce(options = {}) ⇒ Object
Creates a one time use nonce.
Parameters
-
options
130 131 132 133 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 130 def create_nonce( = {}) nonce = ActionDispatch::Session::SessionvocStore::Session.client.create_nonce(nil, nil, :no_encode => true) Base64.encode64(nonce) end |
#delete_form_data(fid, options = {}) ⇒ Object
Deletes a form context in SessionVOC
Parameters
-
fid = Form Id
-
options
90 91 92 93 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 90 def delete_form_data(fid, = {}) Rails.logger.debug("Sessionvoc#delete_form_data") ActionDispatch::Session::SessionvocStore::Session.client.delete_form_data(self['sid'], fid, ) end |
#get_form_data(fid, options = {}) ⇒ Object
Returns a form context from SessionVOC identified by a fid.
Parameters
-
fid = Form Id
-
options
81 82 83 84 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 81 def get_form_data(fid, = {}) Rails.logger.debug("Sessionvoc#get_form_data") ActionDispatch::Session::SessionvocStore::Session.client.get_form_data(self['sid'], fid, ) end |
#login(sid, uid, password, options = {}) ⇒ Object
Performs an authentification against SessionVOC.
Parameters
-
sid = Session Id
-
uid = User
-
password = User password
-
options
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 101 def login(sid, uid, password, = {}) Rails.logger.debug("Sessionvoc#login") client = ActionDispatch::Session::SessionvocStore::Session.client; response = nil = .merge(:no_exception => true) if client.configuration.["auth"] == 'none' or client.configuration.["auth"] == 'simple' response = client.simple(sid, uid, password, ) elsif client.configuration.["auth"] == 'challenge' response = client.challenge(sid, uid, password, ) end if response and response['userData'] self['userData'] = response['userData'] else return false end true end |
#logout(sid, options = {}) ⇒ Object
Performs a user logout.
Parameters
-
sid = Session Id
-
options
122 123 124 125 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 122 def logout(sid, = {}) Rails.logger.debug("Sessionvoc#logout") ActionDispatch::Session::SessionvocStore::Session.client.logout(sid, ) end |
#new_form ⇒ Object
Creates a new form context within this session.
62 63 64 65 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 62 def new_form Rails.logger.debug("AbstractStore::SessionHash#new_form") ActionDispatch::Session::SessionvocStore::Session.client.create_form_data(self['sid']) end |
#nonce_still_valid?(nonce, options = {}) ⇒ Boolean
Checks if the nonce is still valid and has not been used yet.
Parameters
-
nonce = Nonce string
-
options
139 140 141 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 139 def nonce_still_valid?(nonce, = {}) ActionDispatch::Session::SessionvocStore::Session.client.get_nonce(nonce, ) end |
#set_form_data(fid, data, options = {}) ⇒ Object
Updates/replaces the form data identified by a sid in SessionVOC.
Parameters
-
fid = Form Id
-
data = Form data hash
-
options
72 73 74 75 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 72 def set_form_data(fid, data, = {}) Rails.logger.debug("Sessionvoc#set_form_data") ActionDispatch::Session::SessionvocStore::Session.client.update_form_data(self['sid'], fid, data, ) end |
#set_trans_data(sid, key, value, options = {}) ⇒ Object
Adds a key/value pair to the transData context of a SessionVOC session.
Parameters
-
sid = Session Id
-
key = Key
-
value = Value
-
options
43 44 45 46 47 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 43 def set_trans_data(sid, key, value, = {}) Rails.logger.debug("AbstractStore::SessionHash#set_trans_data") enforce_value_type("transData", key.to_s, value, self) ActionDispatch::Session::SessionvocStore::Session.client.update(sid, self) end |
#set_user_data(sid, key, value, options = {}) ⇒ Object
Adds a key/value pair to the userData context of a SessionVOC session.
Parameters
-
sid = Session Id
-
key = Key
-
value = Value
-
options
55 56 57 58 59 |
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 55 def set_user_data(sid, key, value, = {}) Rails.logger.debug("AbstractStore::SessionHash#set_user_data") enforce_value_type("userData", key.to_s, value, self) ActionDispatch::Session::SessionvocStore::Session.client.update(sid, self) end |