mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 23:52:58 +01:00
initial commit to emailer system overhaul
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,3 +19,4 @@ feeds/recent.rss
|
||||
|
||||
# winston?
|
||||
error.log
|
||||
events.log
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
"nodebb-theme-cerulean": "0.0.10",
|
||||
"cron": "~1.0.1",
|
||||
"semver": "~2.2.1",
|
||||
"string": "~1.7.0"
|
||||
"string": "~1.7.0",
|
||||
"handlebars": "~1.2.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"redis": "0.8.3",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
<p>Hello,</p>
|
||||
<p><strong>Thank you for registering with NodeBB!</strong></p>
|
||||
<p>To fully activate your account, we need to verify that you own the email address you registered with.</p>
|
||||
<p>Please click on the following link:</p>
|
||||
<blockquote>{CONFIRM_LINK}</blockquote>
|
||||
<p>Thanks!<br /><strong>NodeBB</strong>
|
||||
@@ -1,12 +0,0 @@
|
||||
Hello,
|
||||
|
||||
Thank you for registering with NodeBB!
|
||||
|
||||
To fully activate your account, we need to verify that you own the email address you registered with.
|
||||
|
||||
Please click on the following link:
|
||||
|
||||
{CONFIRM_LINK}
|
||||
|
||||
Thanks!
|
||||
NodeBB
|
||||
20
public/templates/emails/welcome.hbs
Normal file
20
public/templates/emails/welcome.hbs
Normal file
@@ -0,0 +1,20 @@
|
||||
<p>
|
||||
Hello {{username}},
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Thank you for registering with {{site_title}}!</strong>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To fully activate your account, we need to verify that you own the email address you registered with. Please click on the following link:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
{{confirm_link}}
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
Thanks!<br />
|
||||
<strong>{{site_title}}</strong>
|
||||
</p>
|
||||
11
public/templates/emails/welcome_plaintext.hbs
Normal file
11
public/templates/emails/welcome_plaintext.hbs
Normal file
@@ -0,0 +1,11 @@
|
||||
Hello {{username}},
|
||||
|
||||
Thank you for registering with {{site_title}}!
|
||||
|
||||
To fully activate your account, we need to verify that you own the email address you registered with. Please click on the following link:
|
||||
|
||||
{{confirm_link}}
|
||||
|
||||
|
||||
Thanks!
|
||||
{{site_title}}
|
||||
69
src/emailer.js
Normal file
69
src/emailer.js
Normal file
@@ -0,0 +1,69 @@
|
||||
var User = require('./user'),
|
||||
Plugins = require('./plugins'),
|
||||
|
||||
Handlebars = require('handlebars'),
|
||||
fs = require('fs'),
|
||||
async = require('async'),
|
||||
path = require('path'),
|
||||
|
||||
Emailer = {},
|
||||
templates = {};
|
||||
|
||||
var prepareTemplate = function(template, callback) {
|
||||
if (templates[template] === undefined) {
|
||||
var templatePath = path.join(__dirname, '../public/templates/emails/' + template + '.hbs');
|
||||
|
||||
fs.exists(templatePath, function(exists) {
|
||||
if (exists) {
|
||||
fs.readFile(templatePath, function(err, fileStream) {
|
||||
if (!err) {
|
||||
templates[template] = Handlebars.compile(fileStream.toString());
|
||||
} else {
|
||||
templates[template] = null;
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
templates[template] = null;
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Template loaded already
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
var render = function(template, params, callback) {
|
||||
prepareTemplate(template, function() {
|
||||
if (templates[template] !== null) {
|
||||
callback(null, templates[template](params));
|
||||
} else {
|
||||
callback(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Emailer.send = function(template, uid, params) {
|
||||
async.parallel({
|
||||
html: function(next) {
|
||||
render(template, params, next);
|
||||
},
|
||||
plaintext: function(next) {
|
||||
render(template + '_plaintext', params, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
User.getUserField(uid, 'email', function(err, email) {
|
||||
if (!err) {
|
||||
Plugins.fireHook('action:email.send', {
|
||||
email: email,
|
||||
html: results.html,
|
||||
plaintext: results.plaintext
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Emailer;
|
||||
@@ -80,7 +80,12 @@ var DebugRoute = function(app) {
|
||||
});
|
||||
|
||||
app.get('/test', function(req, res) {
|
||||
user.pushNotifCount(2);
|
||||
var Emailer = require('../emailer');
|
||||
Emailer.send('welcome', {
|
||||
username: 'test',
|
||||
site_title: 'derp',
|
||||
confirm_link: 'linkylink'
|
||||
});
|
||||
res.send();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user