+ 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
|
||||
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,
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue