-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (66 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var ce = require('cloneextend')
var mixin = require('simple-mixin')
var inspect = require('eyespect').inspector();
var AccountLogger = function (account, logger) {
mixin(account, this)
this.innerAccount = account
this.logger = logger
}
AccountLogger.prototype.register = function (data, cb) {
var logger = this.logger
var logData = ce.clone(data)
logData.password = '****'
logger.info('begin registering new account', {
data: logData,
section: 'registerAccount'
})
return this.innerAccount.register(data, function (err, reply) {
if (err) {
logger.error('register account failed to complete correctly', {
data: logData,
error: err,
section: 'registerAccount'
})
}
else {
logger.info('registered new account correctly', {
data: logData,
section: 'registerAccount'
})
}
return cb(err, reply)
})
}
AccountLogger.prototype.login = function (data, cb) {
var logger = this.logger
return this.innerAccount.login(data, function (err, reply) {
var logData = ce.clone(data)
logData.password = '****'
if (err) {
logger.error('error for login account', {
data: logData,
error: err,
section: 'loginAccount'
})
}
else if (!reply) {
logger.info('login account failed to complete correctly', {
data: logData,
reply: reply,
section: 'loginAccount'
})
}
else {
data.password = '****'
var replyLogData = ce.clone(reply)
replyLogData.hash = '****'
logger.info('login account completed correctly', {
data: logData,
reply: replyLogData,
section: 'loginAccount'
})
}
return cb(err, reply)
})
}
module.exports = AccountLogger