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}
+ `) + + let button_html = '' + if ( button_text && button_link ) { + button_html = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${app_name} +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${header_text} +
+
+
+
+
+ ${body_text}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${app_name} | Login |
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${app_name} -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Forgot Password? -
-
-
-
-
-
- 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. -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${app_name} | Login |
-