diff --git a/src/controllers/debug.js b/src/controllers/debug.js index e1a93674c..5542fe14a 100644 --- a/src/controllers/debug.js +++ b/src/controllers/debug.js @@ -15,7 +15,7 @@ var _ = require('lodash') var async = require('async') var path = require('path') -var winston = require('winston') +var winston = require('../logger') var debugController = {} @@ -468,7 +468,7 @@ debugController.sendmail = function (req, res) { var mailer = require('../mailer') var templateSchema = require('../models/template') var Email = require('email-templates') - // var templateDir = path.resolve(__dirname, '..', 'mailer', 'templates') + var templateDir = path.resolve(__dirname, '..', 'mailer', 'templates') var to = req.query.email if (to === undefined) { @@ -476,22 +476,30 @@ debugController.sendmail = function (req, res) { } var email = new Email({ - render: function (view, locals) { - return new Promise(function (resolve, reject) { - if (!global.Handlebars) return reject(new Error('Could not load global.Handlebars')) - templateSchema.findOne({ name: view }, function (err, template) { - if (err) return reject(err) - if (!template) return reject(new Error('Invalid Template')) - var html = global.Handlebars.compile(template.data['gjs-fullHtml'])(locals) - console.log(html) - email.juiceResources(html).then(resolve) - }) - }) + views: { + root: templateDir, + options: { + extension: 'handlebars' + } } + // This is to test the new email templates (beta feature) + // render: function (view, locals) { + // return new Promise(function (resolve, reject) { + // if (!global.Handlebars) return reject(new Error('Could not load global.Handlebars')) + // templateSchema.findOne({ name: view }, function (err, template) { + // if (err) return reject(err) + // if (!template) return reject(new Error('Invalid Template')) + // var html = global.Handlebars.compile(template.data['gjs-fullHtml'])(locals) + // console.log(html) + // email.juiceResources(html).then(resolve) + // }) + // }) + // } }) var ticket = { uid: 100001, + issue: 'This is the test issue', comments: [ { date: new Date(), @@ -505,11 +513,11 @@ debugController.sendmail = function (req, res) { } email - .render('ticket-updated', { base_url: global.TRUDESK_BASEURL, ticket: ticket }) + .render('ticket-comment-added', { base_url: global.TRUDESK_BASEURL, ticket: ticket, comment: ticket.comments[0] }) .then(function (html) { var mailOptions = { to: to, - subject: 'Trudesk Test Email [Debugger]', + subject: 'Trudesk Test Email #' + ticket.uid + ' [Debugger]', html: html, generateTextFromHTML: true } @@ -521,8 +529,8 @@ debugController.sendmail = function (req, res) { }) }) .catch(function (err) { - winston.warn(err) - res.status(400).send(err) + console.log(err) + res.status(400).json({ error: err }) }) } diff --git a/src/controllers/main.js b/src/controllers/main.js index 76fbb89e6..8700cc924 100644 --- a/src/controllers/main.js +++ b/src/controllers/main.js @@ -202,6 +202,8 @@ mainController.forgotL2Auth = function (req, res) { } }) + savedUser = savedUser.toJSON() + var data = { base_url: req.protocol + '://' + req.get('host'), user: savedUser @@ -277,6 +279,8 @@ mainController.forgotPass = function (req, res) { var email = null + savedUser = savedUser.toJSON() + var data = { base_url: req.protocol + '://' + req.get('host'), user: savedUser @@ -412,6 +416,8 @@ mainController.resetl2auth = function (req, res) { } }) + updated = updated.toJSON() + email .render('l2auth-cleared', user) .then(function (html) { @@ -491,6 +497,8 @@ mainController.resetPass = function (req, res) { } }) + updated = updated.toJSON() + var data = { password: gPass, user: updated diff --git a/src/emitter/events.js b/src/emitter/events.js index 73a89a612..55d445562 100644 --- a/src/emitter/events.js +++ b/src/emitter/events.js @@ -154,6 +154,8 @@ var notifications = require('../notifications') // Load Push Events if (err) return c(err) if (!template) return c() + ticket = ticket.toJSON() + var context = { base_url: baseUrl, ticket: ticket } email @@ -504,6 +506,8 @@ var notifications = require('../notifications') // Load Push Events if (err) winston.warn(err) if (err) return c() + ticket = ticket.toJSON() + email .render('ticket-comment-added', { ticket: ticket,