38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
|
const { Job } = require('flitter-jobs')
|
||
|
|
||
|
class ForeignIPLoginAlertJob extends Job {
|
||
|
static get services() { return [...super.services, 'models', 'jobs', 'output', 'configs'] }
|
||
|
|
||
|
async execute(job) {
|
||
|
const { data } = job
|
||
|
const { user_id, ip } = data
|
||
|
|
||
|
try {
|
||
|
const User = this.models.get('auth:User')
|
||
|
const user = await User.findById(user_id)
|
||
|
if ( !user ) throw new Error('Unable to find user with ID: '+user_id)
|
||
|
|
||
|
this.output.info('Sending foreign IP login alert to user.')
|
||
|
|
||
|
await this.jobs.queue('mailer').add('EMail', {
|
||
|
to: user.email,
|
||
|
subject: `Security Alert | ${this.configs.get('app.name')}`,
|
||
|
email_params: {
|
||
|
header_text: 'Login From New IP',
|
||
|
body_paragraphs: [
|
||
|
`We've detected a login to your ${this.configs.get('app.name')} account from a new IP address (${ip}).`,
|
||
|
'If this was you, no further action is required. If this was not you, please log into your account and reset your password.',
|
||
|
'Also, consider enabling multi-factor authentication to protect your account.',
|
||
|
],
|
||
|
button_text: 'Account Settings',
|
||
|
button_link: `${this.configs.get('app.url')}dash/profile`,
|
||
|
}
|
||
|
})
|
||
|
} catch (e) {
|
||
|
this.output.error(e)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = exports = ForeignIPLoginAlertJob
|