Skip to content

Commit

Permalink
quickfix: improved logging for login attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
nbiton committed May 23, 2019
1 parent d7db675 commit eef3de0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions imports/api/hooks/on-login-failure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Accounts } from 'meteor/accounts-base'
import { logger } from '../../util/logger'

Accounts.onLoginFailure(({ user, type, error }) => {
logger.warn(`User with email ${user.emails[0].address} has tried to login with the '${type}' method unsuccessfully. Reason: "${error.reason}"`)
})
22 changes: 14 additions & 8 deletions imports/api/hooks/on-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ import { logger } from '../../util/logger'

// Enforces one-time usage of random generated passwords for newly invited users
Accounts.onLogin(info => {
const { user } = info
const { user, ...rest } = info
if (info.methodName === 'resetPassword') {
Meteor.users.update(user._id, {
$set: {
'profile.isLimited': false
}
})
logger.info(`User ${user.emails[0].address} has successfully reset their password`)
if (user.profile.isLimited) {
logger.info(`User ${user.emails[0].address} is no longer "limited" after password reset`)
Meteor.users.update(user._id, {
$unset: {
'profile.isLimited': 1
}
})
}
} else if (info.type === 'password') {
logger.info('info', info)
logger.info(`User with email ${user.emails[0].address} has logged in using a password`)
if (user.profile.isLimited) {
logger.info(`resetting the password for ${user.emails[0].address} after one-time usage by invitation`)
logger.info(`Resetting the password for ${user.emails[0].address} after one-time usage by invitation`)
const randPass = randToken.generate(12)
Accounts.setPassword(user._id, randPass, { logout: false })
}
} else if (rest.type !== 'resume') {
logger.info(`User with email ${user.emails[0].address} has logged in using an alternative method`, rest)
}
})
1 change: 1 addition & 0 deletions server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import '../imports/api/failed-unit-creations'
import '../imports/api/increment-counters'
import '../imports/api/hooks/on-create-user'
import '../imports/api/hooks/on-login'
import '../imports/api/hooks/on-login-failure'
import '../imports/api/rest/rest-routes'
import '../imports/config/email'

Expand Down

0 comments on commit eef3de0

Please sign in to comment.