From 6563a72b5be20ddcc7929d6d3f1c7a2cfce5a57a Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 13 Mar 2014 00:49:32 -0400 Subject: [PATCH] fixed emailer templates --- src/emailer.js | 21 +++++++++------------ src/webserver.js | 2 ++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/emailer.js b/src/emailer.js index 021f6a84e7..402bce31cd 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -1,3 +1,5 @@ +"use strict"; + var fs = require('fs'), async = require('async'), path = require('path'), @@ -9,27 +11,22 @@ var fs = require('fs'), Translator = require('../public/src/translator'), templates = require('../public/src/templates'), + app = {}, Emailer = {}; -var render = function(template, params, callback) { - if (templates[template]) { - Translator.translate(templates[template].parse(params), function(template) { - callback(null, template); - }); - } else { - callback(null, null); - } -} +Emailer.registerApp = function(expressApp) { + app = expressApp; + return Emailer; +}; Emailer.send = function(template, uid, params) { - async.parallel({ html: function(next) { - render('emails/' + template, params, next); + app.render('emails/' + template, params, next); }, plaintext: function(next) { - render('emails/' + template + '_plaintext', params, next); + app.render('emails/' + template + '_plaintext', params, next); } }, function(err, results) { User.getUserField(uid, 'email', function(err, email) { diff --git a/src/webserver.js b/src/webserver.js index b3db354389..2197c29fa9 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -8,6 +8,7 @@ var path = require('path'), winston = require('winston'), async = require('async'), + emailer = require('./emailer'), db = require('./database'), auth = require('./routes/authentication'), meta = require('./meta'), @@ -31,6 +32,7 @@ if(nconf.get('ssl')) { logger.init(app); auth.registerApp(app); + emailer.registerApp(app); async.series({ themesData: meta.themes.get,