|
|
|
module.exports = function(app, io, authentication) {
|
|
|
|
|
|
|
|
var docker = require('docker.js')(app, io);
|
|
|
|
|
|
|
|
// New Authenticated Client
|
|
|
|
function connection(socket, userdata) {
|
|
|
|
console.log("=> new connection from "+userdata.username);
|
|
|
|
docker.connect(socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Connection Authentication
|
|
|
|
require('socketio-auth')(io, {
|
|
|
|
authenticate: function (socket, data, callback) {
|
|
|
|
console.log("=> authenticate: ", data.username);
|
|
|
|
authentication(data.username, data.password,
|
|
|
|
function(username) {
|
|
|
|
console.log("user logged in", username);
|
|
|
|
callback(null, true)
|
|
|
|
},
|
|
|
|
function(username, where, err) {
|
|
|
|
console.log("login failed", username, where, err);
|
|
|
|
callback(new Error("wrong credentials"))
|
|
|
|
});
|
|
|
|
},
|
|
|
|
postAuthenticate: connection,
|
|
|
|
timeout: "none"
|
|
|
|
});
|
|
|
|
|
|
|
|
var module = {};
|
|
|
|
return module;
|
|
|
|
}
|