Fix issue #38, pass active request object to authentication library

Esse commit está contido em:
Joshua Gross
2010-11-21 13:37:24 -06:00
commit 00de205459
3 arquivos alterados com 13 adições e 11 exclusões
+4 -2
Ver Arquivo
@@ -1,6 +1,8 @@
// Cookie that stores the session ID
// Will be set as request.sessionID in `authenticate` and `friends` functions
exports.cookie = 'sessionid';
exports.authenticate = function(session_id, callback) {
exports.authenticate = function(request, callback) {
// Verify user based on request.
// On failure, redirect user to auth form
@@ -11,7 +13,7 @@ exports.authenticate = function(session_id, callback) {
});
};
exports.friends = function(session_id, data, callback) {
exports.friends = function(request, data, callback) {
// Create a friends list based on given user data
callback([
+1 -1
Ver Arquivo
@@ -21,7 +21,7 @@ module.exports = function setupHub(options) {
}
if(req.sessionID) {
store.get(req.sessionID, function(err, sess) {
store.get(req, function(err, sess) {
if(err) {
next(err);
return;
+8 -8
Ver Arquivo
@@ -50,16 +50,16 @@ Hub.prototype.reap = function(ms) {
}
};
Hub.prototype.get = function(sid, fn) {
if(this.sessions[sid]) {
fn(null, this.sessions[sid]);
Hub.prototype.get = function(req, fn) {
if(this.sessions[req.sessionID]) {
fn(null, this.sessions[req.sessionID]);
} else {
this.auth.authenticate(sid, o_.bind(function(data) {
this.auth.authenticate(req, o_.bind(function(data) {
if(data) {
var session = new User(sid, data);
this.set(sid, session);
var session = new User(req.sessionID, data);
this.set(req.sessionID, session);
this.auth.friends(sid, data, o_.bind(function(friends) {
this.auth.friends(req, data, o_.bind(function(friends) {
var friends_copy = friends.slice();
o_.values(this.sessions).filter(function(friend) {
return ~friends.indexOf(friend.data('username'));
@@ -78,7 +78,7 @@ Hub.prototype.get = function(sid, fn) {
}, this));
this.events.addListener('update',
o_.bind(session.receivedUpdate, session));
this.set(sid, session);
this.set(req.sessionID, session);
fn(null, session);
}, this));
} else {