Created
March 6, 2013 19:58
-
-
Save mbarinov/5102527 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
var sockets = sockjs.createServer(); | |
sockets.on('connection', function (client) { | |
client.on('data', function (message) { | |
var message = JSON.parse(message); | |
switch (message.type) { | |
case "authCookie": | |
// http запрос к API с полученной кукой | |
// Для зарегистрированных пользователей LinguaLeo http://lingualeo.com/api/login | |
auth.getUserInfo(message.data.cookie, function (res) { | |
try { | |
var userInfo = JSON.parse(res); | |
if (userInfo.error_code === undefined) { | |
// Выставляем флаг авторизации | |
client.auth = true; | |
// Записываем userId и userInfo к клиенту | |
client.userId = userInfo.user.user_id; | |
client.info = userInfo; | |
// Добавляем клиента в пулл всех коннектов | |
connections[client.name] = client; | |
// Отправляем на клиент статус авторизации | |
client.write(JSON.stringify({"type":"authReady", "data":{"status":"true"}})); | |
} else { | |
client.write(JSON.stringify({"type":"authReady", "data":{"status":"false"}})); | |
} | |
} catch (e) { | |
client.write(JSON.stringify({"type":"authReady", "data":{"status":"false"}})); | |
return false; | |
} | |
}); | |
break; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment