2019-02-08 23:20:57 +01:00
|
|
|
/*
|
2013-02-13 01:33:22 +00:00
|
|
|
* Stores session data in the database
|
|
|
|
* Source; https://github.com/edy-b/SciFlowWriter/blob/develop/available_plugins/ep_sciflowwriter/db/DirtyStore.js
|
|
|
|
* This is not used for authors that are created via the API at current
|
2019-01-23 16:58:43 +00:00
|
|
|
*
|
|
|
|
* RPB: this module was not migrated to Promises, because it is only used via
|
|
|
|
* express-session, which can't actually use promises anyway.
|
2013-02-13 01:33:22 +00:00
|
|
|
*/
|
|
|
|
|
2015-04-07 07:55:05 -05:00
|
|
|
var Store = require('ep_etherpad-lite/node_modules/express-session').Store,
|
2013-02-13 01:33:22 +00:00
|
|
|
db = require('ep_etherpad-lite/node/db/DB').db,
|
|
|
|
log4js = require('ep_etherpad-lite/node_modules/log4js'),
|
|
|
|
messageLogger = log4js.getLogger("SessionStore");
|
|
|
|
|
|
|
|
var SessionStore = module.exports = function SessionStore() {};
|
|
|
|
|
|
|
|
SessionStore.prototype.__proto__ = Store.prototype;
|
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
SessionStore.prototype.get = function(sid, fn) {
|
2013-02-13 01:33:22 +00:00
|
|
|
messageLogger.debug('GET ' + sid);
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2013-02-13 01:33:22 +00:00
|
|
|
var self = this;
|
2019-02-08 23:20:57 +01:00
|
|
|
|
|
|
|
db.get("sessionstorage:" + sid, function(err, sess) {
|
2013-02-13 01:33:22 +00:00
|
|
|
if (sess) {
|
|
|
|
sess.cookie.expires = 'string' == typeof sess.cookie.expires ? new Date(sess.cookie.expires) : sess.cookie.expires;
|
2013-03-23 18:01:44 +00:00
|
|
|
if (!sess.cookie.expires || new Date() < sess.cookie.expires) {
|
2013-02-13 01:33:22 +00:00
|
|
|
fn(null, sess);
|
|
|
|
} else {
|
|
|
|
self.destroy(sid, fn);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fn();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
SessionStore.prototype.set = function(sid, sess, fn) {
|
2013-02-13 01:33:22 +00:00
|
|
|
messageLogger.debug('SET ' + sid);
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2013-02-13 01:33:22 +00:00
|
|
|
db.set("sessionstorage:" + sid, sess);
|
2019-02-09 00:14:53 +01:00
|
|
|
if (fn) {
|
|
|
|
process.nextTick(fn);
|
|
|
|
}
|
2013-02-13 01:33:22 +00:00
|
|
|
};
|
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
SessionStore.prototype.destroy = function(sid, fn) {
|
2013-02-13 01:33:22 +00:00
|
|
|
messageLogger.debug('DESTROY ' + sid);
|
2019-02-08 23:20:57 +01:00
|
|
|
|
2013-02-13 01:33:22 +00:00
|
|
|
db.remove("sessionstorage:" + sid);
|
2019-02-09 00:14:53 +01:00
|
|
|
if (fn) {
|
|
|
|
process.nextTick(fn);
|
|
|
|
}
|
2013-02-13 01:33:22 +00:00
|
|
|
};
|