mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
module changes, fixed missing interval
This commit is contained in:
@@ -11,52 +11,56 @@ var fs = require('fs'),
|
||||
meta = require('./meta'),
|
||||
translator = require('../public/src/translator'),
|
||||
|
||||
app = {},
|
||||
Emailer = {};
|
||||
app;
|
||||
|
||||
(function(Emailer) {
|
||||
Emailer.registerApp = function(expressApp) {
|
||||
app = expressApp;
|
||||
return Emailer;
|
||||
};
|
||||
|
||||
Emailer.registerApp = function(expressApp) {
|
||||
app = expressApp;
|
||||
return Emailer;
|
||||
};
|
||||
Emailer.send = function(template, uid, params) {
|
||||
if (!app) {
|
||||
winston.warn('[emailer] App not ready!');
|
||||
return;
|
||||
}
|
||||
|
||||
Emailer.send = function(template, uid, params) {
|
||||
async.parallel({
|
||||
html: function(next) {
|
||||
app.render('emails/' + template, params, next);
|
||||
},
|
||||
plaintext: function(next) {
|
||||
app.render('emails/' + template + '_plaintext', params, next);
|
||||
},
|
||||
email: async.apply(User.getUserField, uid, 'email'),
|
||||
settings: async.apply(User.getSettings, uid)
|
||||
}, function(err, results) {
|
||||
async.map([results.html, results.plaintext, params.subject], function(raw, next) {
|
||||
translator.translate(raw, results.settings.language || meta.config.defaultLang || 'en_GB', function(translated) {
|
||||
next(undefined, translated);
|
||||
});
|
||||
}, function(err, translated) {
|
||||
if (err) {
|
||||
return winston.error(err.message);
|
||||
} else if (!results.email) {
|
||||
return winston.warn('uid : ' + uid + ' has no email, not sending.');
|
||||
}
|
||||
|
||||
if (Plugins.hasListeners('action:email.send')) {
|
||||
Plugins.fireHook('action:email.send', {
|
||||
to: results.email,
|
||||
from: meta.config['email:from'] || 'no-reply@localhost.lan',
|
||||
subject: translated[2],
|
||||
html: translated[0],
|
||||
plaintext: translated[1],
|
||||
template: template,
|
||||
uid: uid
|
||||
async.parallel({
|
||||
html: function(next) {
|
||||
app.render('emails/' + template, params, next);
|
||||
},
|
||||
plaintext: function(next) {
|
||||
app.render('emails/' + template + '_plaintext', params, next);
|
||||
},
|
||||
email: async.apply(User.getUserField, uid, 'email'),
|
||||
settings: async.apply(User.getSettings, uid)
|
||||
}, function(err, results) {
|
||||
async.map([results.html, results.plaintext, params.subject], function(raw, next) {
|
||||
translator.translate(raw, results.settings.language || meta.config.defaultLang || 'en_GB', function(translated) {
|
||||
next(undefined, translated);
|
||||
});
|
||||
} else {
|
||||
winston.warn('[emailer] No active email plugin found!');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}, function(err, translated) {
|
||||
if (err) {
|
||||
return winston.error(err.message);
|
||||
} else if (!results.email) {
|
||||
return winston.warn('uid : ' + uid + ' has no email, not sending.');
|
||||
}
|
||||
|
||||
if (Plugins.hasListeners('action:email.send')) {
|
||||
Plugins.fireHook('action:email.send', {
|
||||
to: results.email,
|
||||
from: meta.config['email:from'] || 'no-reply@localhost.lan',
|
||||
subject: translated[2],
|
||||
html: translated[0],
|
||||
plaintext: translated[1],
|
||||
template: template,
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
winston.warn('[emailer] No active email plugin found!');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}(module.exports));
|
||||
|
||||
module.exports = Emailer;
|
||||
|
||||
Reference in New Issue
Block a user