+ Add unique session ID to client sessions
* Aliased to user for convienence * Added to logs for easy tracing * Can be used from events/etc. for grouping
This commit is contained in:
parent
fbe87640c5
commit
1cb811576b
|
@ -8,6 +8,7 @@ const Events = require('./events.js');
|
||||||
// deps
|
// deps
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const hashids = require('hashids');
|
||||||
|
|
||||||
exports.getActiveConnections = getActiveConnections;
|
exports.getActiveConnections = getActiveConnections;
|
||||||
exports.getActiveNodeList = getActiveNodeList;
|
exports.getActiveNodeList = getActiveNodeList;
|
||||||
|
@ -60,9 +61,12 @@ function addNewClient(client, clientSock) {
|
||||||
const id = client.session.id = clientConnections.push(client) - 1;
|
const id = client.session.id = clientConnections.push(client) - 1;
|
||||||
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
|
const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
|
||||||
|
|
||||||
|
// create a uniqe identifier one-time ID for this session
|
||||||
|
client.session.uniqueId = new hashids('ENiGMA½ClientSession').encode([ id, moment().valueOf() ]);
|
||||||
|
|
||||||
// Create a client specific logger
|
// Create a client specific logger
|
||||||
// Note that this will be updated @ login with additional information
|
// Note that this will be updated @ login with additional information
|
||||||
client.log = logger.log.child( { clientId : id } );
|
client.log = logger.log.child( { clientId : id, sessionId : client.session.uniqueId } );
|
||||||
|
|
||||||
const connInfo = {
|
const connInfo = {
|
||||||
remoteAddress : remoteAddress,
|
remoteAddress : remoteAddress,
|
||||||
|
|
|
@ -55,11 +55,19 @@ function userLogin(client, username, password, cb) {
|
||||||
return cb(existingConnError);
|
return cb(existingConnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update client logger with addition of username
|
// update client logger with addition of username
|
||||||
client.log = logger.log.child( { clientId : client.log.fields.clientId, username : user.username });
|
client.log = logger.log.child(
|
||||||
|
{
|
||||||
|
clientId : client.log.fields.clientId,
|
||||||
|
sessionId : client.log.fields.sessionId,
|
||||||
|
username : user.username,
|
||||||
|
}
|
||||||
|
);
|
||||||
client.log.info('Successful login');
|
client.log.info('Successful login');
|
||||||
|
|
||||||
|
// User's unique session identifier is the same as the connection itself
|
||||||
|
user.sessionId = client.session.uniqueId; // convienence
|
||||||
|
|
||||||
Events.emit(Events.getSystemEvents().UserLogin, { user } );
|
Events.emit(Events.getSystemEvents().UserLogin, { user } );
|
||||||
|
|
||||||
async.parallel(
|
async.parallel(
|
||||||
|
|
Loading…
Reference in New Issue