Created
April 18, 2013 00:37
-
-
Save anonymous/5408941 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Make sure the socket is coming from our app by matching the session id | |
socketServer.set('authorization', function (data, accept) { | |
cookieParser(data, {}, function(err) { | |
if (err) { | |
accept(err, false); | |
} else { | |
config.sessionStore.load(data.signedCookies[config.sessionKey], function(err, session) { | |
if (err || !session) { | |
accept('Session error', false); | |
} else { | |
data.session = session; | |
accept(null, true); | |
} | |
}); | |
} | |
}); | |
}); | |
// Set up an admin channel that checks for admin authorization | |
socketServer.of('/admin').authorization(function (data, accept) { | |
cookieParser(data, {}, function(err) { | |
if (err) { | |
accept(err, false); | |
} else { | |
config.sessionStore.load(data.signedCookies[config.sessionKey], function(err, session) { | |
if (!session.uid) { | |
accept('Access denied', false); | |
} else { | |
Users.findOne({_id: session.uid}, function (err, db_user) { | |
if (db_user && db_user.name == 'admin') { | |
accept(null, true); | |
} else { | |
accept('Access denied', false); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment