From 63ebe5386579b0a8714217f825368f91fc9254e1 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 29 Sep 2015 10:37:28 -0400 Subject: [PATCH] feature(cloudcmd) console: add authCheck --- lib/client/konsole.js | 14 +++++++++++++- lib/cloudcmd.js | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/client/konsole.js b/lib/client/konsole.js index 25db8efd..0fdf8f73 100644 --- a/lib/client/konsole.js +++ b/lib/client/konsole.js @@ -50,7 +50,19 @@ function create(callback) { var prefix = getPrefix(); - Console(Element, prefix, function() { + Console(Element, prefix, function(spawn) { + spawn.on('auth', function() { + Dialog.alert(TITLE, 'Wrong credentials!'); + }); + + DOM.Files.get('config', function(error, config) { + if (error) + return Dialog.alert(TITLE, error); + + if (config.auth) + spawn.emit('auth', config.username, config.password); + }); + Util.exec(callback); }); diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 98f06a3b..db96e8a3 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -94,13 +94,26 @@ return cloudcmd(prefix, p.socket); }; + function authCheck(socket, success) { + if (!config('auth')) + return success(); + + socket.on('auth', function(name, pass) { + name === config('username') && + pass === config('password') ? + + success() : socket.emit('auth'); + }); + } + function listen(prefix, socket) { var size = cloudfunc.MAX_SIZE, pref = getPrefix(prefix); webconsole({ socket: socket, - prefix: pref + '/console' + prefix: pref + '/console', + authCheck: authCheck }); edward.listen(socket, {