mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-20 14:32:59 +01:00
added email verification on registration
added email header and footer
This commit is contained in:
@@ -49,10 +49,11 @@ var templates = {};
|
||||
|
||||
function init() {
|
||||
loadTemplates([
|
||||
'header', 'footer', 'register', 'home', 'topic',
|
||||
'login', 'reset', 'reset_code', 'account',
|
||||
'emails/reset', 'emails/reset_plaintext'
|
||||
]);
|
||||
'header', 'footer', 'register', 'home', 'topic',
|
||||
'login', 'reset', 'reset_code', 'account',
|
||||
'confirm',
|
||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
7
public/templates/confirm.tpl
Normal file
7
public/templates/confirm.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="alert {alert-class}">
|
||||
<strong>{title}</strong>
|
||||
<p>{text}</p>
|
||||
<p>
|
||||
<a href="/">NodeBB Home</a>
|
||||
</p>
|
||||
</div>
|
||||
7
public/templates/emails/email_confirm.tpl
Normal file
7
public/templates/emails/email_confirm.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
<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>
|
||||
12
public/templates/emails/email_confirm_plaintext.tpl
Normal file
12
public/templates/emails/email_confirm_plaintext.tpl
Normal file
@@ -0,0 +1,12 @@
|
||||
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
|
||||
10
public/templates/emails/footer.tpl
Normal file
10
public/templates/emails/footer.tpl
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
</div>
|
||||
<hr />
|
||||
<p style="
|
||||
font-size: 10px;
|
||||
padding: 6px 12px;
|
||||
">
|
||||
This email was sent by NodeBB. If it does not apply to you, please ignore it.
|
||||
</p>
|
||||
</div>
|
||||
26
public/templates/emails/header.tpl
Normal file
26
public/templates/emails/header.tpl
Normal file
@@ -0,0 +1,26 @@
|
||||
<div style="
|
||||
width: 640px;
|
||||
border: 1px solid #666;
|
||||
margin: 0 auto;
|
||||
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
|
||||
background: #f6f6f6;
|
||||
">
|
||||
<h1 style="
|
||||
background-color: #1b1b1b;
|
||||
margin: 0;
|
||||
padding: 6px 12px;
|
||||
font-size: 20px;
|
||||
background-image: -moz-linear-gradient(top,#222,#111);
|
||||
background-image: -webkit-gradient(linear,0 0,0 100%,from(#222),to(#111));
|
||||
background-image: -webkit-linear-gradient(top,#222,#111);
|
||||
background-image: -o-linear-gradient(top,#222,#111);
|
||||
background-image: linear-gradient(to bottom,#222,#111);
|
||||
color: #777;
|
||||
font-weight: normal;
|
||||
">
|
||||
NodeBB
|
||||
</h1>
|
||||
<div style="
|
||||
padding: 20px;
|
||||
color: #333;
|
||||
">
|
||||
@@ -28,7 +28,8 @@
|
||||
'header', 'footer', 'register', 'home', 'topic', 'account',
|
||||
'login', 'reset', 'reset_code', 'logout',
|
||||
'403',
|
||||
'emails/reset', 'emails/reset_plaintext'
|
||||
'emails/header', 'emails/footer',
|
||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
42
src/user.js
42
src/user.js
@@ -277,8 +277,35 @@ var config = require('../config.js'),
|
||||
}
|
||||
|
||||
if (email) {
|
||||
var confirm_code = utils.generateUUID(),
|
||||
confirm_link = config.url + 'confirm/' + confirm_code,
|
||||
confirm_email = global.templates['emails/header'] + global.templates['emails/email_confirm'].parse({'CONFIRM_LINK': confirm_link}) + global.templates['emails/footer'],
|
||||
confirm_email_plaintext = global.templates['emails/email_confirm_plaintext'].parse({ 'CONFIRM_LINK': confirm_link });
|
||||
|
||||
RDB.set('uid:' + uid + ':email', email);
|
||||
RDB.set('email:' + email, uid);
|
||||
|
||||
// Email confirmation code
|
||||
RDB.set('email:' + email + ':confirm', confirm_code, 60*60*2);
|
||||
RDB.set('confirm:' + confirm_code + ':email', email, 60*60*2); // Expire after 2 hours
|
||||
|
||||
// Send intro email w/ confirm code
|
||||
var message = emailjs.message.create({
|
||||
text: confirm_email_plaintext,
|
||||
from: config.mailer.from,
|
||||
to: email,
|
||||
subject: '[NodeBB] Registration Email Verification',
|
||||
attachment: [
|
||||
{
|
||||
data: confirm_email,
|
||||
alternative: true
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
emailjsServer.send(message, function(err, success) {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
RDB.set('uid:' + uid + ':joindate', new Date().getTime());
|
||||
@@ -485,6 +512,21 @@ var config = require('../config.js'),
|
||||
if (typeof callback !== 'function') socket.emit('user.email.exists', { exists: exists });
|
||||
else callback(exists);
|
||||
});
|
||||
},
|
||||
confirm: function(code, callback) {
|
||||
RDB.get('confirm:' + code + ':email', function(email) {
|
||||
if (email !== null) {
|
||||
RDB.set('email:' + email + ':confirm', true);
|
||||
RDB.del('confirm:' + code + ':email');
|
||||
callback({
|
||||
status: 'ok'
|
||||
});
|
||||
} else {
|
||||
callback({
|
||||
status: 'not_ok'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,9 @@ passport.deserializeUser(function(uid, done) {
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'topic/' + req.params.topic_id + '");});</script>' + templates['footer']);
|
||||
});
|
||||
|
||||
|
||||
app.get('/confirm/:code', function(req, res) {
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
||||
});
|
||||
|
||||
// These functions are called via ajax once the initial page is loaded to populate templates with data
|
||||
function api_method(req, res) {
|
||||
@@ -176,6 +178,23 @@ passport.deserializeUser(function(uid, done) {
|
||||
res.send(JSON.stringify(data));
|
||||
}, req.params.id, (req.user) ? req.user.uid : 0);
|
||||
break;
|
||||
case 'confirm':
|
||||
global.modules.user.email.confirm(req.params.id, function(data) {
|
||||
if (data.status === 'ok') {
|
||||
res.send(JSON.stringify({
|
||||
'alert-class': 'alert-success',
|
||||
title: 'Email Confirmed',
|
||||
text: 'Thank you for vaidating your email. Your account is now fully activated.'
|
||||
}));
|
||||
} else {
|
||||
res.send(JSON.stringify({
|
||||
'alert-class': 'alert-error',
|
||||
title: 'An error occurred...',
|
||||
text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.'
|
||||
}));
|
||||
}
|
||||
});
|
||||
break;
|
||||
default :
|
||||
res.send('{}');
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user