diff --git a/TODO.text b/TODO.text index 310e4d0..dfa3876 100644 --- a/TODO.text +++ b/TODO.text @@ -1,6 +1,6 @@ - OAuth2 -> support refresh tokens - Localize all the things -- Setup wizard -- Logins as jobs +- show app documentation somewhere besides final page of setup +- Logins as jobs? - OpenID Connect - oidc-provider - Login from new IP notifications \ No newline at end of file diff --git a/app/jobs/EMail.job.js b/app/jobs/EMail.job.js index 6da66c0..c2eef2c 100644 --- a/app/jobs/EMail.job.js +++ b/app/jobs/EMail.job.js @@ -2,18 +2,20 @@ const { Job } = require('flitter-jobs') class EMailJob extends Job { static get services() { - return [...super.services, 'smtp', 'output'] + return [...super.services, 'smtp', 'output', 'configs'] } async execute(job) { - const config = this.smtp.config() - const transport = this.smtp.transport() + try { + const config = this.smtp.config() + const transport = this.smtp.transport() - const { data } = job - const { from = config.default_sender, to, subject, html } = data + const { data } = job + let { from = config.default_sender, to, subject, html = undefined, email_params = undefined } = data + this.output.info(`Sending mail to ${to}...`) + + if ( !html && email_params ) html = this.email(email_params) - this.output.info(`Sending mail to ${to}...`) - try { await transport.sendMail({ from, to, subject, html, }) @@ -22,6 +24,464 @@ class EMailJob extends Job { } this.output.success(`Mail sent!`) } + + email({ header_text, body_paragraphs = [], button_text = '', button_link = '' }) { + const app_name = this.configs.get('app.name') + const login_url = this.configs.get('app.url') + 'auth/login' + + // Build the body paragraphs + const body_text = body_paragraphs.map(x => { + return `

${x}

` + }).join(` +

+ `) + + let button_html = '' + if ( button_text && button_link ) { + button_html = `
${button_text}
` + } + + return ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + +` + } } module.exports = exports = EMailJob diff --git a/app/jobs/PasswordReset.job.js b/app/jobs/PasswordReset.job.js index 4078077..5ea946a 100644 --- a/app/jobs/PasswordReset.job.js +++ b/app/jobs/PasswordReset.job.js @@ -20,11 +20,18 @@ class PasswordResetJob extends Job { this.output.info(`Resetting password for user: ${user.uid}`) // Create an authenticated key-action const key_action = await this.key_action(user) - const email = this.email(key_action.url()) await this.jobs.queue('mailer').add('EMail', { to: user.email, subject: 'Reset Your Password | ' + this.configs.get('app.name'), - html: email, + email_params: { + header_text: 'Forget your password?', + body_paragraphs: [ + 'It looks like you requested a password reset for your account. Click the button below, and we\'ll walk you through creating a new one.', + 'If you didn\'t request this e-mail, please contact your system administrator.', + ], + button_text: 'Reset Password', + button_link: key_action.url(), + } }) this.output.success('Password reset logged.') } catch (e) { @@ -44,454 +51,6 @@ class PasswordResetJob extends Job { return (new KeyAction(ka_data)).save() } - - email(keyaction_link) { - const app_name = this.configs.get('app.name') - const login_url = this.configs.get('app.url') + 'auth/login' - const image_url = this.configs.get('app.url') + 'assets/reset_pass_email_image.jpg' - return ` - - - - - - - - - - - - - - - - - - - - - - - - - - - - -` - } } module.exports = exports = PasswordResetJob