feature(cloudcmd) console: add authCheck

This commit is contained in:
coderaiser 2015-09-29 10:37:28 -04:00
parent f4f3f65701
commit 63ebe53865
2 changed files with 27 additions and 2 deletions

View file

@ -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);
});

View file

@ -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, {