fixing 'back to nodebb' ext, and revamping email confirm logic

v1.18.x
Julian Lam 11 years ago
parent d6e0625fc8
commit 24944762d7

@ -1,6 +1,6 @@
{ {
"title": "Notifications", "title": "Notifications",
"back_to_home": "back to NodeBB", "back_to_home": "Back to NodeBB",
"mark_all_as_read": "Mark All as Read", "mark_all_as_read": "Mark All as Read",
"outgoing_link": "Outgoing Link", "outgoing_link": "Outgoing Link",
"outgoing_link_message": "You are now leaving", "outgoing_link_message": "You are now leaving",

@ -1,6 +1,6 @@
{ {
"title": "Notificaciones", "title": "Notificaciones",
"back_to_home": "volver al Inicio", "back_to_home": "Volver al Inicio",
"mark_all_as_read": "Marcar todo como leeido", "mark_all_as_read": "Marcar todo como leeido",
"outgoing_link": "Link Externo", "outgoing_link": "Link Externo",
"outgoing_link_message": "Estas saliendo del sitio", "outgoing_link_message": "Estas saliendo del sitio",

@ -1,6 +1,6 @@
{ {
"title": "Notifications", "title": "Notifications",
"back_to_home": "retour à NodeBB", "back_to_home": "Retour à NodeBB",
"mark_all_as_read": "Tout marquer comme lu", "mark_all_as_read": "Tout marquer comme lu",
"outgoing_link": "Lien Sortant", "outgoing_link": "Lien Sortant",
"outgoing_link_message": "Vous quitter NodeBB", "outgoing_link_message": "Vous quitter NodeBB",

@ -2,6 +2,6 @@
<strong>{title}</strong> <strong>{title}</strong>
<p>{text}</p> <p>{text}</p>
<p> <p>
<a href="/">[[notification:back_to_home]]</a> <a href="/">[[notifications:back_to_home]]</a>
</p> </p>
</div> </div>

@ -221,7 +221,7 @@ var path = require('path'),
}); });
} else { } else {
res.json({ res.json({
'alert-class': 'alert-error', 'alert-class': 'alert-danger',
title: 'An error occurred...', title: 'An error occurred...',
text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.' text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.'
}); });

@ -103,7 +103,7 @@ var bcrypt = require('bcrypt'),
if (email !== undefined) { if (email !== undefined) {
db.setObjectField('email:uid', email, uid); db.setObjectField('email:uid', email, uid);
User.sendConfirmationEmail(uid, email); User.email.verify(uid, email);
} }
plugins.fireHook('action:user.create', {uid: uid, username: username, email: email, picture: gravatar, timestamp: timestamp}); plugins.fireHook('action:user.create', {uid: uid, username: username, email: email, picture: gravatar, timestamp: timestamp});
@ -823,45 +823,6 @@ var bcrypt = require('bcrypt'),
} }
}; };
User.sendConfirmationEmail = function(uid, email) {
var confirm_code = utils.generateUUID(),
confirm_link = nconf.get('url') + 'confirm/' + confirm_code;
// Email confirmation code
var expiry_time = Date.now() / 1000 + 60 * 60 * 2;
db.setObjectField('email:confirm', email, confirm_code);
db.setObjectField('confirm:email', confirm_code, email);
db.setObjectField('confirm:email', confirm_code + ':expire', expiry_time);
// Send intro email w/ confirm code
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
});
});
// var message = emailjs.message.create({
// text: confirm_email_plaintext,
// from: meta.config['email:from'] || 'localhost@example.org',
// to: email,
// subject: '[NodeBB] Registration Email Verification',
// attachment: [{
// data: confirm_email,
// alternative: true
// }]
// });
// emailjsServer.send(message, function(err, success) {
// if (err) {
// console.log(err);
// }
// });
};
User.pushNotifCount = function(uid) { User.pushNotifCount = function(uid) {
User.notifications.getUnreadCount(uid, function(err, count) { User.notifications.getUnreadCount(uid, function(err, count) {
if (!err) { if (!err) {
@ -873,6 +834,32 @@ var bcrypt = require('bcrypt'),
}; };
User.email = { User.email = {
verify: function(uid, email) {
var confirm_code = utils.generateUUID(),
confirm_link = nconf.get('url') + 'confirm/' + confirm_code;
async.series([
function(next) {
db.setObject('confirm:' + confirm_code, {
email: email,
uid: uid
}, next);
},
function(next) {
db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 2), next);
}
], function(err) {
// Send intro email w/ confirm code
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
});
});
});
},
exists: function(socket, email, callback) { exists: function(socket, email, callback) {
User.getUidByEmail(email, function(err, exists) { User.getUidByEmail(email, function(err, exists) {
exists = !! exists; exists = !! exists;
@ -886,37 +873,23 @@ var bcrypt = require('bcrypt'),
}); });
}, },
confirm: function(code, callback) { confirm: function(code, callback) {
db.getObjectFields('confirm:email', [code, code + ':expire'], function(err, data) { db.getObject('confirm:' + code, function(err, confirmObj) {
if (err) { if (err) {
return callback({
status:'error'
});
}
var email = data.email;
var expiry = data[code + ':expire'];
if (parseInt(expiry, 10) >= Date.now() / 1000) {
db.deleteObjectField('confirm:email', code);
db.deleteObjectField('confirm:email', code + ':expire');
return callback({
status: 'expired'
});
}
if (email !== null) {
db.setObjectField('email:confirm', email, true);
db.deleteObjectField('confirm:email', code);
db.deleteObjectField('confirm:email', code + ':expire');
callback({ callback({
status: 'ok' status:'error'
}); });
} else { } else {
callback({ if (confirmObj.uid && confirmObj.email) {
status: 'not_ok' db.setObjectField('email:confirmed', confirmObj.email, '1', function() {
}); callback({
status: 'ok'
});
});
} else {
callback({
status: 'not_ok'
});
}
} }
}); });
} }

Loading…
Cancel
Save