+ 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:
Bryan Ashby 2018-06-03 19:58:31 -06:00
parent fbe87640c5
commit 1cb811576b
2 changed files with 15 additions and 3 deletions

View File

@ -8,6 +8,7 @@ const Events = require('./events.js');
// deps
const _ = require('lodash');
const moment = require('moment');
const hashids = require('hashids');
exports.getActiveConnections = getActiveConnections;
exports.getActiveNodeList = getActiveNodeList;
@ -60,9 +61,12 @@ function addNewClient(client, clientSock) {
const id = client.session.id = clientConnections.push(client) - 1;
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
// 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 = {
remoteAddress : remoteAddress,

View File

@ -55,11 +55,19 @@ function userLogin(client, username, password, cb) {
return cb(existingConnError);
}
// 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');
// User's unique session identifier is the same as the connection itself
user.sessionId = client.session.uniqueId; // convienence
Events.emit(Events.getSystemEvents().UserLogin, { user } );
async.parallel(