diff --git a/lib/client/config.js b/lib/client/config.js index 6190f98d..a3393a18 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -66,30 +66,30 @@ var CloudCmd, Util, DOM, io; path: prefix + '/socket.io' }); - auth(socket); - - socket.on('connect', function() { - Config.save = save; - }); - - socket.on('config', function(config) { - DOM.Storage.setAllowed(config.localStorage); - }); - - socket.on('message', function(data) { - onSave(data); - }); - - socket.on('log', function(msg) { - CloudCmd.log(msg); - }); - - socket.on('disconnect', function() { - Config.save = saveHttp; - }); - - socket.on('err', function(error) { - Dialog.alert(TITLE, error); + auth(socket, function() { + socket.on('connect', function() { + Config.save = save; + }); + + socket.on('config', function(config) { + DOM.Storage.setAllowed(config.localStorage); + }); + + socket.on('message', function(data) { + onSave(data); + }); + + socket.on('log', function(msg) { + CloudCmd.log(msg); + }); + + socket.on('disconnect', function() { + Config.save = saveHttp; + }); + + socket.on('err', function(error) { + Dialog.alert(TITLE, error); + }); }); } } @@ -102,7 +102,7 @@ var CloudCmd, Util, DOM, io; if (config.auth) { socket.emit('auth', config.username, config.password); - socket.on('auth', function() { + socket.on('reject', function() { Dialog.alert(TITLE, 'Wrong credentials!'); }); } diff --git a/lib/client/edit.js b/lib/client/edit.js index b4e3ac1b..481b10b3 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -133,7 +133,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; if (config.auth) { spawn.emit('auth', config.username, config.password); - spawn.on('auth', function() { + spawn.on('reject', function() { Dialog.alert(TITLE, 'Wrong credentials!'); }); } diff --git a/lib/client/konsole.js b/lib/client/konsole.js index 08f5cee6..0627826e 100644 --- a/lib/client/konsole.js +++ b/lib/client/konsole.js @@ -76,7 +76,7 @@ if (config.auth) { spawn.emit('auth', config.username, config.password); - spawn.on('auth', function() { + spawn.on('reject', function() { Dialog.alert(TITLE, 'Wrong credentials!'); }); } diff --git a/lib/client/operation.js b/lib/client/operation.js index db97b14a..8f234587 100644 --- a/lib/client/operation.js +++ b/lib/client/operation.js @@ -59,15 +59,18 @@ ]); } - function authCheck(spawn) { + function authCheck(spawn, ok) { DOM.Files.get('config', function(error, config) { if (error) return Dialog.alert(TITLE, error); - if (config.auth) { + if (!config.auth) { + ok(); + } else { spawn.emit('auth', config.username, config.password); - spawn.on('auth', function() { + spawn.on('accept', ok); + spawn.on('reject', function() { Dialog.alert(TITLE, 'Wrong credentials!'); }); } @@ -81,11 +84,12 @@ fn(); copier.on('connect', function() { - authCheck(copier); - copyFn = function(data, callback) { - setListeners(copier, callback); - copier.copy(data.from, data.to, data.names); - }; + authCheck(copier, function() { + copyFn = function(data, callback) { + setListeners(copier, callback); + copier.copy(data.from, data.to, data.names); + }; + }); }); copier.on('disconnect', function() { @@ -98,13 +102,14 @@ remedy(prefix + '/remedy', prefix, function(remover) { fn(); remover.on('connect', function() { - authCheck(remover); - deleteFn = function(from, files, callback) { - from = from.replace(/\?.*/, ''); - - setListeners(remover, callback); - remover.remove(from, files); - }; + authCheck(remover, function() { + deleteFn = function(from, files, callback) { + from = from.replace(/\?.*/, ''); + + setListeners(remover, callback); + remover.remove(from, files); + }; + }); }); remover.on('disconnect', function() { @@ -117,17 +122,18 @@ ishtar(prefix + '/ishtar', prefix, function(packer) { fn(); packer.on('connect', function() { - authCheck(packer); - packFn = function(data, callback) { - setListeners(packer, callback); + authCheck(packer, function() { + packFn = function(data, callback) { + setListeners(packer, callback); + + packer.pack(data.from, data.to, data.names); + }; - packer.pack(data.from, data.to, data.names); - }; - - extractFn = function(data, callback) { - setListeners(packer, callback); - packer.extract(data.from, data.to); - }; + extractFn = function(data, callback) { + setListeners(packer, callback); + packer.extract(data.from, data.to); + }; + }); }); packer.on('disconnect', function() { diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 62bceecb..4dcf71fb 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -88,10 +88,15 @@ function authCheck(socket, success) { return success(); socket.on('auth', function(name, pass) { - name === config('username') && - pass === config('password') ? + var isName = name === config('username'); + var isPass = pass === config('password'); - success() : socket.emit('auth'); + if (isName && isPass) { + success(); + socket.emit('accept'); + } else { + socket.emit('reject'); + } }); }