Skip to content

Node.js based forum software built for the modern web

tweaks to emailer, implemented emailer hook for password reset

Julian Lam11ed9e8c8530
diff --git a/public/templates/emails/reset.hbs b/public/templates/emails/reset.hbs
new file mode 100644
index 0000000000..0974092869
--- /dev/null
+++ b/public/templates/emails/reset.hbs
@@ -0,0 +1,20 @@
+<p>
+ Hello,
+</p>
+
+<p>
+ We received a request to reset your password, possibly because you have forgotten it. If this is not the case, please ignore this email.
+</p>
+
+<p>
+ To continue with the password reset, please click on the following link:
+</p>
+
+<blockquote>
+ {{reset_link}}
+</blockquote>
+
+<p>
+ Thanks!<br />
+ <strong>{{site_title}}</strong>
+</p>
\ No newline at end of file
diff --git a/public/templates/emails/reset.tpl b/public/templates/emails/reset.tpl
deleted file mode 100644
index eb03cac612..0000000000
--- a/public/templates/emails/reset.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-<p>Hello,</p>
-<p>We received a request to reset your password, possibly because you have forgotten it. If this is not the case, please ignore this email.</p>
-<p>To continue with the password reset, please click on the following link:</p>
-<blockquote>{RESET_LINK}</blockquote>
-<p>Thanks!<br /><strong>NodeBB</strong>
\ No newline at end of file
diff --git a/public/templates/emails/reset_plaintext.tpl b/public/templates/emails/reset_plaintext.hbs
similarity index 100%
rename from public/templates/emails/reset_plaintext.tpl
rename to public/templates/emails/reset_plaintext.hbs
diff --git a/public/templates/emails/welcome.hbs b/public/templates/emails/welcome.hbs
index 0043548aee..efe1f039fe 100644
--- a/public/templates/emails/welcome.hbs
+++ b/public/templates/emails/welcome.hbs
@@ -1,15 +1,19 @@
<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>
diff --git a/src/emailer.js b/src/emailer.js
index 1d7d479db3..ec8dffc33c 100644
--- a/src/emailer.js
+++ b/src/emailer.js
@@ -62,7 +62,10 @@ Emailer.send = function(template, uid, params) {
from: Meta.config['email:from'] || '[email protected]',
subject: params.subject,
html: results.html,
- plaintext: results.plaintext
+ plaintext: results.plaintext,
+
+ template: template,
+ uid: uid
});
}
});
diff --git a/src/user.js b/src/user.js
index efa3fadb32..12d3367956 100644
--- a/src/user.js
+++ b/src/user.js
@@ -755,39 +755,21 @@ var bcrypt = require('bcrypt'),
db.setObjectField('reset:uid', reset_code, uid);
db.setObjectField('reset:expiry', reset_code, (60 * 60) + new Date() / 1000 | 0); // Active for one hour
- var reset_link = nconf.get('url') + 'reset/' + reset_code,
- reset_email = global.templates['emails/reset'].parse({
- 'RESET_LINK': reset_link
- }),
- reset_email_plaintext = global.templates['emails/reset_plaintext'].parse({
- 'RESET_LINK': reset_link
- });
+ var reset_link = nconf.get('url') + 'reset/' + reset_code;
+
+ Emailer.send('reset', uid, {
+ 'site_title': (meta.config['title'] || 'NodeBB'),
+ 'reset_link': reset_link,
- var message = emailjs.message.create({
- text: reset_email_plaintext,
- from: meta.config['email:from'] ? meta.config['email:from'] : '[email protected]',
- to: email,
- subject: 'Password Reset Requested',
- attachment: [{
- data: reset_email,
- alternative: true
- }]
+ subject: 'Password Reset Requested - ' + (meta.config['title'] || 'NodeBB') + '!',
+ template: 'reset',
+ uid: uid
});
- emailjsServer.send(message, function(err, success) {
- if (err === null) {
- socket.emit('user.send_reset', {
- status: "ok",
- message: "code-sent",
- email: email
- });
- } else {
- socket.emit('user.send_reset', {
- status: "error",
- message: "send-failed"
- });
- winston.err(err);
- }
+ socket.emit('user.send_reset', {
+ status: "ok",
+ message: "code-sent",
+ email: email
});
} else {
socket.emit('user.send_reset', {
@@ -853,9 +835,12 @@ var bcrypt = require('bcrypt'),
User.getUserField(uid, 'username', function(err, username) {
Emailer.send('welcome', uid, {
'site_title': (meta.config['title'] || 'NodeBB'),
- subject: 'Welcome to ' + (meta.config['title'] || 'NodeBB') + '!',
username: username,
- 'confirm_link': confirm_link
+ 'confirm_link': confirm_link,
+
+ subject: 'Welcome to ' + (meta.config['title'] || 'NodeBB') + '!',
+ template: 'welcome',
+ uid: uid
});
});
});