sessionstore
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -17,3 +17,4 @@ 'use strict'; | ||
dbName: 'express-sessions', | ||
collectionName: 'sessions' | ||
collectionName: 'sessions', | ||
ttl: 60 * 60 * 24 * 14 // 14 days | ||
}; | ||
@@ -118,2 +119,14 @@ | ||
sess.collectionName = this.collectionName; | ||
if (sess && sess.cookie && sess.cookie.expires) { | ||
sess.expires = new Date(sess.cookie.expires); | ||
} else { | ||
// If there's no expiration date specified, it is | ||
// browser-session cookie or there is no cookie at all, | ||
// as per the connect docs. | ||
// | ||
// So we set the expiration to two-weeks from now | ||
// - as is common practice in the industry (e.g Django) - | ||
// or the default specified in the options. | ||
sess.expires = new Date(Date.now() + this.options.ttl * 1000); | ||
} | ||
this.db.save(hash, sess, callback || function() {}); | ||
@@ -123,2 +136,4 @@ }, | ||
get: function (hash, callback) { | ||
var self = this; | ||
// this.db.get(hash, callback || function() {}); | ||
@@ -129,2 +144,8 @@ this.db.get(hash, function(err, res) { | ||
} | ||
if (res && (res.expires.getTime() - Date.now()) < 0) { | ||
self.destroy(hash); | ||
res = null; | ||
} | ||
if (callback) callback(err, res); | ||
@@ -131,0 +152,0 @@ }); |
@@ -13,4 +13,2 @@ 'use strict'; | ||
var self = this; | ||
var defaults = { | ||
@@ -71,3 +69,12 @@ host: 'localhost', | ||
this.client.set(prefixedSid, sessString, callback || function () {}); | ||
var ttl = this.options.expires; | ||
if (sess && sess.cookie && sess.cookie.expires) { | ||
var expInMs = (new Date(sess.cookie.expires)).getTime() - Date.now(); | ||
if (expInMs < 1000) { | ||
expInMs = 1000; | ||
} | ||
ttl = Math.round(expInMs / 1000); | ||
} | ||
this.client.set(prefixedSid, sessString, callback || function () {}, ttl); | ||
}, | ||
@@ -119,2 +126,2 @@ | ||
module.exports = MemcachedSessionStore; | ||
module.exports = MemcachedSessionStore; |
@@ -38,4 +38,3 @@ 'use strict'; | ||
collectionName: 'sessions', | ||
reapInterval: 600000, | ||
maxAge: 1000 * 60 * 60 * 2 | ||
ttl: 60 * 60 * 24 * 14 // 14 days | ||
}; | ||
@@ -66,6 +65,2 @@ | ||
setInterval(function () { | ||
self.reap(options.maxAge); | ||
}, options.reapInterval); | ||
var server; | ||
@@ -89,5 +84,8 @@ | ||
this.db.on('close', function() { | ||
self.isConnected = false; | ||
self.emit('disconnect'); | ||
}); | ||
this.isConnected = false; | ||
this.db.open(function (err, client) { | ||
@@ -100,4 +98,5 @@ if (err) { | ||
self.sessions = self.db.collection(options.collectionName); | ||
self.sessions.ensureIndex({ '_sessionid': 1 }, function() {}); | ||
self.sessions.ensureIndex({ expires: 1 }, { expireAfterSeconds: 0 }, function() {}); | ||
if (!err) { | ||
self.isConnected = true; | ||
self.emit('connect'); | ||
@@ -118,3 +117,3 @@ } | ||
disconnect: function (callback) { | ||
if (!this.db) { | ||
if (!this.db || !this.isConnected) { | ||
if (callback) callback(null); | ||
@@ -124,38 +123,29 @@ return; | ||
this.db.close(callback || function () {}); | ||
this.db.close(function (err) { | ||
if (callback) callback(err); | ||
}); | ||
}, | ||
reap: function (ms, callback) { | ||
var thresh = Number(new Date(Number(new Date()) - ms)); | ||
this.sessions.remove( | ||
{ | ||
'$or': [ | ||
{ "lastAccess": { "$lt": thresh }}, | ||
{ "lastAccess": { "$exists": false }} | ||
] | ||
}, callback || function () {}); | ||
}, | ||
set: function (sid, sess, callback) { | ||
var self = this; | ||
if (sess && sess.cookie && sess.cookie.expires) { | ||
sess.expires = new Date(sess.cookie.expires); | ||
} else { | ||
// If there's no expiration date specified, it is | ||
// browser-session cookie or there is no cookie at all, | ||
// as per the connect docs. | ||
// | ||
// So we set the expiration to two-weeks from now | ||
// - as is common practice in the industry (e.g Django) - | ||
// or the default specified in the options. | ||
sess.expires = new Date(Date.now() + this.options.ttl * 1000); | ||
} | ||
this.sessions.findOne({ _sessionid: sid }, function (err, session_data) { | ||
sess._id = sid; | ||
this.sessions.update({_id: sid}, sess, { upsert: true, safe: true }, function(err) { | ||
if (err) { | ||
if (callback) callback(err); | ||
} else { | ||
sess._sessionid = sid; | ||
var method = 'insert'; | ||
if (session_data) { | ||
sess._id = session_data._id; | ||
sess.lastAccess = (new Date()).getTime(); | ||
method = 'save'; | ||
} | ||
self.sessions[method](sess, function (err, document) { | ||
if (err) { | ||
if (callback) callback(err); | ||
return; | ||
} | ||
if (callback) callback(null, sess); | ||
}); | ||
return; | ||
} | ||
if (callback) callback(null, sess); | ||
}); | ||
@@ -165,3 +155,9 @@ }, | ||
get: function (sid, callback) { | ||
this.sessions.findOne({ _sessionid: sid }, function (err, session_data) { | ||
this.sessions.findOne({ | ||
_id: sid, | ||
$or: [ | ||
{ expires: { $exists: false } }, | ||
{ expires: { $gt: new Date() } } | ||
] | ||
}, function (err, session_data) { | ||
if (err) { | ||
@@ -177,3 +173,3 @@ if (callback) callback(err); | ||
destroy: function (sid, callback) { | ||
this.sessions.remove({ _sessionid: sid }, callback || function () {}); | ||
this.sessions.remove({ _id: sid }, callback || function () {}); | ||
}, | ||
@@ -180,0 +176,0 @@ |
@@ -18,3 +18,3 @@ 'use strict'; | ||
prefix: 'sess', | ||
ttl: 804600, | ||
ttl: 60 * 60 * 24 * 14, // 14 days | ||
max_attempts: 1 | ||
@@ -96,3 +96,3 @@ }; | ||
} | ||
self.emit('connect'); | ||
@@ -117,2 +117,9 @@ | ||
var ttl = this.ttl; | ||
if (sess && sess.cookie && sess.cookie.expires) { | ||
var expInMs = (new Date(sess.cookie.expires)).getTime() - Date.now(); | ||
if (expInMs < 1000) { | ||
expInMs = 1000; | ||
} | ||
ttl = Math.round(expInMs / 1000); | ||
} | ||
sess = JSON.stringify(sess); | ||
@@ -119,0 +126,0 @@ this.client.setex(prefixedSid, ttl, sess, callback || function () {}); |
@@ -34,4 +34,3 @@ 'use strict'; | ||
collectionName: 'sessions', | ||
reapInterval: 600000, | ||
maxAge: 1000 * 60 * 60 * 2 | ||
ttl: 60 * 60 * 24 * 14 // 14 days | ||
}; | ||
@@ -49,10 +48,4 @@ | ||
connect: function (callback) { | ||
var self = this; | ||
var options = this.options; | ||
setInterval(function () { | ||
self.reap(options.maxAge); | ||
}, options.reapInterval); | ||
this.db = new tingodb.Db(options.dbPath, {}); | ||
@@ -63,2 +56,3 @@ // this.db.on('close', function() { | ||
this.sessions = this.db.collection(options.collectionName + '.tingo'); | ||
this.sessions.ensureIndex({ expires: 1 }, { expireAfterSeconds: 0 }, function() {}); | ||
@@ -79,35 +73,24 @@ this.emit('connect'); | ||
reap: function (ms, callback) { | ||
var thresh = Number(new Date(Number(new Date()) - ms)); | ||
this.sessions.remove( | ||
{ | ||
'$or': [ | ||
{ "lastAccess": { "$lt": thresh }}, | ||
{ "lastAccess": { "$exists": false }} | ||
] | ||
}, callback || function () {}); | ||
}, | ||
set: function (sid, sess, callback) { | ||
var self = this; | ||
if (sess && sess.cookie && sess.cookie.expires) { | ||
sess.expires = new Date(sess.cookie.expires); | ||
} else { | ||
// If there's no expiration date specified, it is | ||
// browser-session cookie or there is no cookie at all, | ||
// as per the connect docs. | ||
// | ||
// So we set the expiration to two-weeks from now | ||
// - as is common practice in the industry (e.g Django) - | ||
// or the default specified in the options. | ||
sess.expires = new Date(Date.now() + this.options.ttl * 1000); | ||
} | ||
this.sessions.findOne({ _sessionid: sid }, function (err, session_data) { | ||
sess._id = sid; | ||
this.sessions.update({_id: sid}, sess, { upsert: true, safe: true }, function(err) { | ||
if (err) { | ||
if (callback) callback(err); | ||
} else { | ||
sess._sessionid = sid; | ||
var method = 'insert'; | ||
if (session_data) { | ||
sess._id = session_data._id; | ||
sess.lastAccess = (new Date()).getTime(); | ||
method = 'save'; | ||
} | ||
self.sessions[method](sess, function (err, document) { | ||
if (err) { | ||
if (callback) callback(err); | ||
return; | ||
} | ||
if (callback) callback(null, sess); | ||
}); | ||
return; | ||
} | ||
if (callback) callback(null, sess); | ||
}); | ||
@@ -117,3 +100,9 @@ }, | ||
get: function (sid, callback) { | ||
this.sessions.findOne({ _sessionid: sid }, function (err, session_data) { | ||
this.sessions.findOne({ | ||
_id: sid, | ||
$or: [ | ||
{ expires: { $exists: false } }, | ||
{ expires: { $gt: new Date() } } | ||
] | ||
}, function (err, session_data) { | ||
if (err) { | ||
@@ -129,3 +118,3 @@ if (callback) callback(err); | ||
destroy: function (sid, callback) { | ||
this.sessions.remove({ _sessionid: sid }, callback || function () {}); | ||
this.sessions.remove({ _id: sid }, callback || function () {}); | ||
}, | ||
@@ -132,0 +121,0 @@ |
{ | ||
"author": "adrai", | ||
"name": "sessionstore", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"private": false, | ||
@@ -14,5 +14,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "0.9.0", | ||
"async": "1.2.1", | ||
"jsondate": "0.0.1", | ||
"lodash": "2.4.1", | ||
"lodash": "3.9.3", | ||
"tolerance": "1.0.0" | ||
@@ -19,0 +19,0 @@ }, |
@@ -38,4 +38,2 @@ # Introduction | ||
collectionName: 'sessions',// optional | ||
reapInterval: 600000, // optional | ||
maxAge: 1000 * 60 * 60 * 2,// optional | ||
timeout: 10000 // optional | ||
@@ -57,4 +55,2 @@ }) | ||
collectionName: 'sessions',// optional | ||
reapInterval: 600000, // optional | ||
maxAge: 1000 * 60 * 60 * 2,// optional | ||
timeout: 10000 // optional | ||
@@ -95,3 +91,2 @@ }) | ||
prefix: 'sess', // optional | ||
ttl: 804600, // optional | ||
timeout: 10000 // optional | ||
@@ -114,3 +109,2 @@ }) | ||
prefix: 'sess', // optional | ||
expires: 80, // optional | ||
retries: 2, // optional | ||
@@ -158,3 +152,3 @@ failover: false, // optional | ||
Copyright (c) 2014 Adriano Raiano | ||
Copyright (c) 2015 Adriano Raiano | ||
@@ -161,0 +155,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -0,1 +1,4 @@ | ||
#### v1.1.0 | ||
- session expiration comes from cookie now | ||
#### v1.0.6 | ||
@@ -2,0 +5,0 @@ - added mongodb driver 2.x support |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33260
19
798
167
+ Addedasync@1.2.1(transitive)
+ Addedlodash@3.9.3(transitive)
- Removedasync@0.9.0(transitive)
- Removedlodash@2.4.1(transitive)
Updatedasync@1.2.1
Updatedlodash@3.9.3