Skip to content

Instantly share code, notes, and snippets.

@joerussbowman
Created April 3, 2010 02:11
Show Gist options
  • Save joerussbowman/354002 to your computer and use it in GitHub Desktop.
Save joerussbowman/354002 to your computer and use it in GitHub Desktop.
/*
* mongodb based sessions with rotating tokens
*/
require("./Math.uuid");
var sys = require("sys");
var cookies = require("./cookies");
var mongo = require('./mongodb');
Session = function(req, res, callback){
var sid, token, session;
var myCookies = new cookies.Cookies(req, res);
var validSession = false;
// cookie validation
if (!myCookies.get(global.config.session.cookie_name, false)) {
sys.debug("Creating a new session.");
sid = Math.uuid();
token = Math.uuid();
session = {
sid: sid,
token: [token]
};
this.save();
}
else {
sys.debug('Have a session.');
sys.puts(myCookies.get(global.config.session.cookie_name, false));
}
};
Session.prototype.save = function(){
sys.debug(req.method);
/* req.db.open(function(req_db){
req.db.collection('unscatter', function(err, collection){
req.db.collection.insert(session, function(err, docs){
sys.debug(docs);
});
});
});*/
};
exports.Session = Session;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment