io.configure(function (){
io.set('authorization', function (handshakeData, callback) {
var cook = handshakeData.headers.cookie;
console.log(cook);
callback(null, true); // error first callback style
});
});
io.configure(function (){
io.set('authorization', function (handshakeData, callback) {
var cookies = parseCookies(handshakeData);
console.log(cookies);
callback(null, true); // error first callback style
});
});
function parseCookies(request) {
var list = {},
rc = request.headers.cookie;
rc && rc.split(';').forEach(function(cookie) {
var parts = cookie.split('=');
list[parts.shift().trim()] = unescape(parts.join('='));
});
return list;
}
//Проверка на авторизацию
io.configure(function (){
io.set('authorization', function (handshakeData, callback) {
function parseCookies () {
var list = {},
rc = handshakeData.headers.cookie;
rc && rc.split(';').forEach(function( cookie ) {
var parts = cookie.split('=');
list[parts.shift().trim()] = unescape(parts.join('='));
});
return list;
}
var cookies = parseCookies();
//Проверяем, определена ли конкретная кука
if(cookies['login'] != undefined){
callback(null, true);
}
else{
callback(null, false);
}
});
});