mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 13:56:09 +02:00
added email verification on registration
added email header and footer
This commit is contained in:
@@ -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