mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(cloudcmd) authCheck: add accept, reject
This commit is contained in:
parent
0edd99a0fd
commit
0ec091a5c8
5 changed files with 66 additions and 55 deletions
|
|
@ -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!');
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!');
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!');
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue