Begin supporting the database but still have a problem where it generates new key on restart...
parent
14dca92692
commit
5c9d081391
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* The Session Manager provides functions to manage session in the database
|
* The Session Manager provides functions to manage session in the database, it only provides session management for sessions created by the API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Store = require('ep_etherpad-lite/node_modules/connect/lib/middleware/session/store'),
|
||||||
|
utils = require('ep_etherpad-lite/node_modules/connect/lib/utils'),
|
||||||
|
Session = require('ep_etherpad-lite/node_modules/connect/lib/middleware/session/session'),
|
||||||
|
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;
|
||||||
|
|
||||||
|
SessionStore.prototype.get = function(sid, fn){
|
||||||
|
messageLogger.debug('GET ' + sid);
|
||||||
|
var self = this;
|
||||||
|
db.get("sessionstorage:" + sid, function (err, sess)
|
||||||
|
{
|
||||||
|
if (sess) {
|
||||||
|
sess.cookie.expires = 'string' == typeof sess.cookie.expires ? new Date(sess.cookie.expires) : sess.cookie.expires;
|
||||||
|
if (!sess.cookie.expires || new Date() < expires) {
|
||||||
|
fn(null, sess);
|
||||||
|
} else {
|
||||||
|
self.destroy(sid, fn);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SessionStore.prototype.set = function(sid, sess, fn){
|
||||||
|
messageLogger.debug('SET ' + sid);
|
||||||
|
db.set("sessionstorage:" + sid, sess);
|
||||||
|
process.nextTick(function(){
|
||||||
|
if(fn) fn();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SessionStore.prototype.destroy = function(sid, fn){
|
||||||
|
messageLogger.debug('DESTROY ' + sid);
|
||||||
|
db.remove("sessionstorage:" + sid);
|
||||||
|
process.nextTick(function(){
|
||||||
|
if(fn) fn();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SessionStore.prototype.all = function(fn){
|
||||||
|
messageLogger.debug('ALL');
|
||||||
|
var sessions = [];
|
||||||
|
db.forEach(function(key, value){
|
||||||
|
if (key.substr(0,15) === "sessionstorage:") {
|
||||||
|
sessions.push(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fn(null, sessions);
|
||||||
|
};
|
||||||
|
|
||||||
|
SessionStore.prototype.clear = function(fn){
|
||||||
|
messageLogger.debug('CLEAR');
|
||||||
|
db.forEach(function(key, value){
|
||||||
|
if (key.substr(0,15) === "sessionstorage:") {
|
||||||
|
db.db.remove("session:" + key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(fn) fn();
|
||||||
|
};
|
||||||
|
|
||||||
|
SessionStore.prototype.length = function(fn){
|
||||||
|
messageLogger.debug('LENGTH');
|
||||||
|
var i = 0;
|
||||||
|
db.forEach(function(key, value){
|
||||||
|
if (key.substr(0,15) === "sessionstorage:") {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fn(null, i);
|
||||||
|
};
|
|
@ -4,7 +4,7 @@ var httpLogger = log4js.getLogger("http");
|
||||||
var settings = require('../../utils/Settings');
|
var settings = require('../../utils/Settings');
|
||||||
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
||||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
var ueberStore = require('../../db/SessionStore');
|
||||||
|
|
||||||
//checks for basic http auth
|
//checks for basic http auth
|
||||||
exports.basicAuth = function (req, res, next) {
|
exports.basicAuth = function (req, res, next) {
|
||||||
|
@ -102,15 +102,14 @@ exports.expressConfigure = function (hook_name, args, cb) {
|
||||||
* handling it cleaner :) */
|
* handling it cleaner :) */
|
||||||
|
|
||||||
if (!exports.sessionStore) {
|
if (!exports.sessionStore) {
|
||||||
exports.sessionStore = new express.session.MemoryStore();
|
exports.sessionStore = new ueberStore();
|
||||||
exports.secret = randomString(32);
|
exports.secret = randomString(32); // Isn't this being reset each time the server spawns?
|
||||||
}
|
}
|
||||||
|
|
||||||
args.app.use(express.cookieParser(exports.secret));
|
args.app.use(express.cookieParser(exports.secret));
|
||||||
|
|
||||||
args.app.sessionStore = exports.sessionStore;
|
args.app.sessionStore = exports.sessionStore;
|
||||||
args.app.use(express.session({store: args.app.sessionStore,
|
args.app.use(express.session({secret: exports.secret, store: args.app.sessionStore, key: 'express_sid' }));
|
||||||
key: 'express_sid' }));
|
|
||||||
|
|
||||||
args.app.use(exports.basicAuth);
|
args.app.use(exports.basicAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue