mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
fixing 'back to nodebb' ext, and revamping email confirm logic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"title": "Notifications",
|
||||
"back_to_home": "back to NodeBB",
|
||||
"back_to_home": "Back to NodeBB",
|
||||
"mark_all_as_read": "Mark All as Read",
|
||||
"outgoing_link": "Outgoing Link",
|
||||
"outgoing_link_message": "You are now leaving",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"title": "Notificaciones",
|
||||
"back_to_home": "volver al Inicio",
|
||||
"back_to_home": "Volver al Inicio",
|
||||
"mark_all_as_read": "Marcar todo como leeido",
|
||||
"outgoing_link": "Link Externo",
|
||||
"outgoing_link_message": "Estas saliendo del sitio",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"title": "Notifications",
|
||||
"back_to_home": "retour à NodeBB",
|
||||
"back_to_home": "Retour à NodeBB",
|
||||
"mark_all_as_read": "Tout marquer comme lu",
|
||||
"outgoing_link": "Lien Sortant",
|
||||
"outgoing_link_message": "Vous quitter NodeBB",
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
<strong>{title}</strong>
|
||||
<p>{text}</p>
|
||||
<p>
|
||||
<a href="/">[[notification:back_to_home]]</a>
|
||||
<a href="/">[[notifications:back_to_home]]</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -221,7 +221,7 @@ var path = require('path'),
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
'alert-class': 'alert-error',
|
||||
'alert-class': 'alert-danger',
|
||||
title: 'An error occurred...',
|
||||
text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.'
|
||||
});
|
||||
|
||||
107
src/user.js
107
src/user.js
@@ -103,7 +103,7 @@ var bcrypt = require('bcrypt'),
|
||||
|
||||
if (email !== undefined) {
|
||||
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});
|
||||
@@ -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.notifications.getUnreadCount(uid, function(err, count) {
|
||||
if (!err) {
|
||||
@@ -873,6 +834,32 @@ var bcrypt = require('bcrypt'),
|
||||
};
|
||||
|
||||
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) {
|
||||
User.getUidByEmail(email, function(err, exists) {
|
||||
exists = !! exists;
|
||||
@@ -886,37 +873,23 @@ var bcrypt = require('bcrypt'),
|
||||
});
|
||||
},
|
||||
confirm: function(code, callback) {
|
||||
db.getObjectFields('confirm:email', [code, code + ':expire'], function(err, data) {
|
||||
db.getObject('confirm:' + code, function(err, confirmObj) {
|
||||
if (err) {
|
||||
return callback({
|
||||
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({
|
||||
status: 'ok'
|
||||
});
|
||||
} else {
|
||||
callback({
|
||||
status: 'not_ok'
|
||||
});
|
||||
if (confirmObj.uid && confirmObj.email) {
|
||||
db.setObjectField('email:confirmed', confirmObj.email, '1', function() {
|
||||
callback({
|
||||
status: 'ok'
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback({
|
||||
status: 'not_ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user