Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(log): Add logging of various account event
Browse files Browse the repository at this point in the history
Events added are:

* account.created
* account.login
* account.signed
  • Loading branch information
chilts committed Jun 9, 2015
1 parent c8a252a commit 8b22c23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/log.js
Expand Up @@ -61,6 +61,20 @@ Lug.prototype.event = function (name, data) {
process.stdout.write(JSON.stringify(e) + '\n')
}

Lug.prototype.activityEvent = function(event, uid, request) {
var info = {
event: event,
uid: uid,
}
if (request.headers['user-agent']) {
info.userAgent = request.headers['user-agent']
}
if (request.payload && request.payload.service) {
info.service = request.payload.service
}
this.logger.info('activityEvent', info)
}

Lug.prototype.stat = function (stats) {
this.logger.info('stat', stats)
}
Expand Down
3 changes: 3 additions & 0 deletions lib/routes/account.js
Expand Up @@ -107,6 +107,7 @@ module.exports = function (
)
.then(
function (account) {
log.activityEvent('account.created', account.uid, request)
if (account.emailVerified) {
log.event('verified', { email: account.email, uid: account.uid, locale: account.locale })
}
Expand Down Expand Up @@ -239,6 +240,8 @@ module.exports = function (
if (!match) {
throw error.incorrectPassword(emailRecord.email, email)
}
var uid = emailRecord.uid.toString('hex')
log.activityEvent('account.login', uid, request)
return db.createSessionToken(
{
uid: emailRecord.uid,
Expand Down
6 changes: 5 additions & 1 deletion lib/routes/sign.js
Expand Up @@ -94,7 +94,11 @@ module.exports = function (log, isA, error, signer, db, domain) {
lastAuthAt: sessionToken.lastAuthAt(),
verifiedEmail: sessionToken.email
}
).then(reply, reply)
).then(function(certResult) {
var uid = sessionToken.uid.toString('hex')
log.activityEvent('account.signed', uid, request)
reply(certResult)
}, reply)
}
}
]
Expand Down

0 comments on commit 8b22c23

Please sign in to comment.