Created
April 3, 2010 02:13
-
-
Save joerussbowman/354003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
this.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); | |
}); | |
}); | |
});*/ | |
}; | |
// 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)); | |
} | |
}; | |
exports.Session = Session; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment