parent
d29e6f057a
commit
143fccf179
@ -0,0 +1,36 @@
|
||||
const { Job } = require('flitter-jobs')
|
||||
|
||||
class PasswordResetAlertJob 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 password reset 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: 'Your Password Was Reset',
|
||||
body_paragraphs: [
|
||||
`The password to your ${this.configs.get('app.name')} account (${user.uid}) was recently reset from the IP ${ip}.`,
|
||||
'If this was you, please disregard this email. Otherwise, please contact your administrator for assistance recovering your account.',
|
||||
],
|
||||
},
|
||||
})
|
||||
} catch (e) {
|
||||
this.output.error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PasswordResetAlertJob
|
Loading…
Reference in new issue