Class: AbstractStore::SessionHash

Inherits:
Object
  • Object
show all
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

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(options = {})
  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, options = {})
  Rails.logger.debug("Sessionvoc#delete_form_data")
  ActionDispatch::Session::SessionvocStore::Session.client.delete_form_data(self['sid'], fid, options)
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, options = {})
  Rails.logger.debug("Sessionvoc#get_form_data")
  ActionDispatch::Session::SessionvocStore::Session.client.get_form_data(self['sid'], fid, options)
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 (sid, uid, password, options = {})
  Rails.logger.debug("Sessionvoc#login")
  client = ActionDispatch::Session::SessionvocStore::Session.client; response = nil
  options = options.merge(:no_exception => true)
  if client.configuration.options["auth"] == 'none' or client.configuration.options["auth"] == 'simple'
    response = client.simple(sid, uid, password, options)
  elsif client.configuration.options["auth"] == 'challenge'
    response = client.challenge(sid, uid, password, options)
  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, options = {})
  Rails.logger.debug("Sessionvoc#logout")
  ActionDispatch::Session::SessionvocStore::Session.client.logout(sid, options)
end

#new_formObject

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

Returns:

  • (Boolean)


139
140
141
# File 'lib/sessionvoc-store/open/sessionvoc_store.rb', line 139

def nonce_still_valid?(nonce, options = {})
  ActionDispatch::Session::SessionvocStore::Session.client.get_nonce(nonce, options)
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, options = {})
  Rails.logger.debug("Sessionvoc#set_form_data")
  ActionDispatch::Session::SessionvocStore::Session.client.update_form_data(self['sid'], fid, data, options)
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, options = {})
  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, options = {})
  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