Merge pull request #437 from williamboman/fix/save-token
src/client: fix storing updated token, ensure client config is always an object
This commit is contained in:
commit
1cc02221a3
@ -55,6 +55,9 @@ var inputs = [
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
function Client(manager, name, config) {
|
function Client(manager, name, config) {
|
||||||
|
if (typeof config !== "object") {
|
||||||
|
config = {};
|
||||||
|
}
|
||||||
_.merge(this, {
|
_.merge(this, {
|
||||||
activeChannel: -1,
|
activeChannel: -1,
|
||||||
config: config,
|
config: config,
|
||||||
@ -67,22 +70,22 @@ function Client(manager, name, config) {
|
|||||||
|
|
||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
if (config) {
|
if (client.name && !client.config.token) {
|
||||||
if (!config.token) {
|
client.updateToken(function(token) {
|
||||||
client.updateToken(function() {
|
client.manager.updateUser(client.name, {token: token});
|
||||||
client.manager.updateUser(client.name, {token: config.token});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var delay = 0;
|
var delay = 0;
|
||||||
(config.networks || []).forEach(function(n) {
|
(client.config.networks || []).forEach(function(n) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
client.connect(n);
|
client.connect(n);
|
||||||
}, delay);
|
}, delay);
|
||||||
delay += 1000;
|
delay += 1000;
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("User '" + name + "' loaded");
|
if (client.name) {
|
||||||
|
log.info("User '" + client.name + "' loaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +93,7 @@ Client.prototype.emit = function(event, data) {
|
|||||||
if (this.sockets !== null) {
|
if (this.sockets !== null) {
|
||||||
this.sockets.in(this.id).emit(event, data);
|
this.sockets.in(this.id).emit(event, data);
|
||||||
}
|
}
|
||||||
var config = this.config || {};
|
if (this.config.log === true) {
|
||||||
if (config.log === true) {
|
|
||||||
if (event === "msg") {
|
if (event === "msg") {
|
||||||
var target = this.find(data.chan);
|
var target = this.find(data.chan);
|
||||||
if (target) {
|
if (target) {
|
||||||
@ -245,17 +247,16 @@ Client.prototype.updateToken = function(callback) {
|
|||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
crypto.randomBytes(48, function(err, buf) {
|
crypto.randomBytes(48, function(err, buf) {
|
||||||
client.config.token = buf.toString("hex");
|
callback(client.config.token = buf.toString("hex"));
|
||||||
callback();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.setPassword = function(hash, callback) {
|
Client.prototype.setPassword = function(hash, callback) {
|
||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
client.updateToken(function() {
|
client.updateToken(function(token) {
|
||||||
client.manager.updateUser(client.name, {
|
client.manager.updateUser(client.name, {
|
||||||
token: client.config.token,
|
token: token,
|
||||||
password: hash
|
password: hash
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ function init(socket, client) {
|
|||||||
socket.emit("init", {
|
socket.emit("init", {
|
||||||
active: client.activeChannel,
|
active: client.activeChannel,
|
||||||
networks: client.networks,
|
networks: client.networks,
|
||||||
token: client.config ? client.config.token : null
|
token: client.config.token || null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user