add support for Gotify push notifications
This commit is contained in:
@@ -28,6 +28,13 @@ class ForeignIPLoginAlertJob extends Job {
|
||||
button_link: `${this.configs.get('app.url')}dash/profile`,
|
||||
}
|
||||
})
|
||||
|
||||
if ( user.notify_config && user.notify_config.active ) {
|
||||
await user.notify_config.log({
|
||||
title: `${this.configs.get('app.name')}: Sign-In From New IP`,
|
||||
message: `Someone signed into your account (${user.uid}) from the IP address ${ip}. If this was you, no further action is required.`,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
this.output.error(e)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,15 @@ class PasswordResetJob extends Job {
|
||||
button_link: key_action.url(),
|
||||
}
|
||||
})
|
||||
|
||||
if ( user.notify_config && user.notify_config.active ) {
|
||||
await user.notify_config.log({
|
||||
title: `${this.configs.get('app.name')}: Password Reset Requested`,
|
||||
message: `A password reset request was logged for your account (${user.uid}). If this was you, please check your e-mail for further instructions.`,
|
||||
priority: 8,
|
||||
})
|
||||
}
|
||||
|
||||
this.output.success('Password reset logged.')
|
||||
} catch (e) {
|
||||
this.output.error(e)
|
||||
|
||||
@@ -27,6 +27,14 @@ class PasswordResetAlertJob extends Job {
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
if ( user.notify_config && user.notify_config.active ) {
|
||||
await user.notify_config.log({
|
||||
title: `${this.configs.get('app.name')}: Password Reset`,
|
||||
message: `The password to your account (${user.uid}) was reset from the IP address ${ip}. If this was not you, please contact your system administrator.`,
|
||||
priority: 8,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
this.output.error(e)
|
||||
}
|
||||
|
||||
31
app/jobs/PushNotify.job.js
Normal file
31
app/jobs/PushNotify.job.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { Job } = require('flitter-jobs')
|
||||
|
||||
class PushNotifyJob extends Job {
|
||||
static get services() {
|
||||
return [...super.services, 'models', 'jobs', 'output']
|
||||
}
|
||||
|
||||
async execute(job) {
|
||||
try {
|
||||
const User = this.models.get('auth:User')
|
||||
|
||||
const { data } = job
|
||||
let { title = '', message, priority = 5, user_id } = data
|
||||
|
||||
const user = await User.findById(user_id)
|
||||
if ( !user ) throw new Error('Invalid user_id.')
|
||||
|
||||
const notify = user.notify_config
|
||||
if ( !notify || !notify.active ) throw new Error('User does not have notifications configured.')
|
||||
|
||||
this.output.info(`Sending notification to ${user.uid}...`)
|
||||
|
||||
await notify.send({ title, message, priority })
|
||||
} catch (e) {
|
||||
this.output.error(e)
|
||||
}
|
||||
this.output.success(`Notification sent!`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PushNotifyJob
|
||||
Reference in New Issue
Block a user