Fork me on GitHub CONNECT.JS SessionVOC

CONNECT.JS SessionVOC

secure, reliable, external session database SessionVOC

sessionvoc-store

lib/sessionvoc-store.js

Module dependencies.

var sessionvocClient = require('sessionvoc-client'),
    Session = require('./sessionvoc-session');

Exports.

module.exports = SessionVocStore;

Export the debugging flag.

module.exports.debug = false;


Initializes a new SessionVocStore. You can define an options array to specifiy the host and port.

  • param: Object options

  • api: public

function SessionVocStore (options) {
  var host = options && options.host;
  var port = options && options.port;

  var self = this;

  self.description = 'Secure and reliable session store using a SessionVOC';
  self.client = sessionvocClient.createClient(host, port); 
  self.datainfo = null;

  // executes after datainfo is fetched. 
  self.client.on('ready', function(dinfo) { 
    self.datainfo = dinfo; 
  }); 
};


Creates a new session object.

  • param: String sid

  • param: Object data

  • param: Function next(session)

SessionVocStore.prototype.createSession = function (sid, data, next) {
  next(new Session(this, sid, data));
};

Reads or creates a new Session object. If the session could be read, then the function 'read' is called. If the session could not be restored, but a new session could be created then the function 'created' is called. In case of an error, the 'error' function is called. If 'sid' is not given, then a new session (and sid) is created.

  • param: String sid (optional)

  • param: Function created(session)

  • param: Function read(session)

  • param: Function error(err)

  • api: public

SessionVocStore.prototype.loadSession = function (sid, created, loaded, error) {
  var self = this;

  if (typeof sid === 'function') {
    error = loaded;
    loaded = created;
    created = sid;
    sid = false;
  }

  if (sid) {
    self.readSessionVoc(sid,
                        function (result) {
                          self.createSession(sid, result, loaded);
                        },
                        function () {
                          self.createSessionVoc(function (sid, result) {
                                                  self.createSession(sid, result, created);
                                                },
                                                error);
                        },
                        error);
  }
  else {
    self.createSessionVoc(function (sid, result) {
                            self.createSession(sid, result, created);
                          },
                          error);
  }
};




Log informational output if debug flag is set.

function debuglog (msg) {
  if (module.exports.debug) {
    console.log('[sessionvoc-store] ' + msg);
  }
}