From 68c18c7f31fa51c07727a2f1b2d3277caa12e1d3 Mon Sep 17 00:00:00 2001 From: Ugo Date: Tue, 11 Jun 2019 00:00:00 +0200 Subject: [PATCH] Fix - pass all the required parameters to email template --- server/auth/auth.controller.js | 1 + server/email/index.js | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/auth/auth.controller.js b/server/auth/auth.controller.js index 756c43c..9e08048 100644 --- a/server/auth/auth.controller.js +++ b/server/auth/auth.controller.js @@ -174,6 +174,7 @@ exports.postForgot = (req, res) => { }); }) .catch(err => { + console.log(err); res .status(err.status || 500) .send({ message: err.message || 'An error occurred', err }); diff --git a/server/email/index.js b/server/email/index.js index 9aff151..f288014 100644 --- a/server/email/index.js +++ b/server/email/index.js @@ -3,9 +3,10 @@ const ejs = require('ejs'); const cfg = require('../../cfg'); const getTransporter = require('./get-transporter'); +const HOST = cfg.clientHost; + const sendEmail = props => { const { email, token, template } = props; - const host = cfg.clientHost; // Sets the service used const transporter = new Promise((resolve, reject) => { @@ -17,7 +18,7 @@ const sendEmail = props => { loadTemplate({ to: email, token, - host, + host: HOST, type: template }), transporter @@ -32,7 +33,7 @@ const sendEmail = props => { const loadTemplate = props => { const { to, token, host, type } = props; const year = new Date().getFullYear(); - const { html, subject, text } = getTemplate(type); + const { html, subject, text } = getTemplate({ type, host, token }); return ejs.renderFile(html, { token, host, year }).then(html => { return { from: '"Gastronomycon" ', @@ -45,7 +46,9 @@ const loadTemplate = props => { }; // util for selecting the specific template -const getTemplate = type => { +const getTemplate = props => { + const { type, host, token } = props; + if (type == 'activation') { return { html: `${__dirname}/template/activate-account.ejs`,