mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-28 01:21:13 +01:00
refactor for sendValidationEmail, and sending better dummy data for welcome email template
This commit is contained in:
@@ -9,6 +9,7 @@ var plugins = require('../plugins');
|
||||
var widgets = require('../widgets');
|
||||
var user = require('../user');
|
||||
var userDigest = require('../user/digest');
|
||||
var userEmail = require('../user/email');
|
||||
var logger = require('../logger');
|
||||
var events = require('../events');
|
||||
var emailer = require('../emailer');
|
||||
@@ -230,6 +231,12 @@ SocketAdmin.email.test = function (socket, data, callback) {
|
||||
emailer.send(data.template, socket.uid, payload, callback);
|
||||
break;
|
||||
|
||||
case 'welcome':
|
||||
userEmail.sendValidationEmail(socket.uid, {
|
||||
force: 1,
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
emailer.send(data.template, socket.uid, payload, callback);
|
||||
break;
|
||||
|
||||
@@ -101,20 +101,9 @@ User.sendValidationEmail = function (socket, uids, callback) {
|
||||
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.getUsersFields(uids, ['uid', 'email'], next);
|
||||
},
|
||||
function (usersData, next) {
|
||||
async.eachLimit(usersData, 50, function (userData, next) {
|
||||
if (userData.email && userData.uid) {
|
||||
user.email.sendValidationEmail(userData.uid, userData.email, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
async.eachLimit(uids, 50, function (uid, next) {
|
||||
user.email.sendValidationEmail(uid, next);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
User.sendPasswordResetEmail = function (socket, uids, callback) {
|
||||
|
||||
@@ -75,18 +75,7 @@ SocketUser.emailConfirm = function (socket, data, callback) {
|
||||
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.getUserField(socket.uid, 'email', next);
|
||||
},
|
||||
function (email, next) {
|
||||
if (!email) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
user.email.sendValidationEmail(socket.uid, email, next);
|
||||
},
|
||||
], callback);
|
||||
user.email.sendValidationEmail(socket.uid, next);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +103,9 @@ module.exports = function (User) {
|
||||
], next);
|
||||
|
||||
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
|
||||
User.email.sendValidationEmail(userData.uid, userData.email);
|
||||
User.email.sendValidationEmail(userData.uid, {
|
||||
email: userData.email,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
|
||||
@@ -26,7 +26,26 @@ UserEmail.available = function (email, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
UserEmail.sendValidationEmail = function (uid, email, callback) {
|
||||
UserEmail.sendValidationEmail = function (uid, options, callback) {
|
||||
/*
|
||||
* Options:
|
||||
* - email, overrides email retrieval
|
||||
* - force, sends email even if it is too soon to send another
|
||||
*/
|
||||
|
||||
// Handling for 2 arguments
|
||||
if (arguments.length === 2 && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
// Fallback behaviour (email passed in as second argument)
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
email: options,
|
||||
};
|
||||
}
|
||||
|
||||
callback = callback || function () {};
|
||||
var confirm_code = utils.generateUUID();
|
||||
var confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
|
||||
@@ -35,6 +54,25 @@ UserEmail.sendValidationEmail = function (uid, email, callback) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
// If no email passed in (default), retrieve email from uid
|
||||
if (options.email && options.email.length) {
|
||||
return setImmediate(next);
|
||||
}
|
||||
|
||||
user.getUserField(uid, 'email', function (err, email) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
options.email = email;
|
||||
next();
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
if (options.force) {
|
||||
return setImmediate(next, null, false);
|
||||
}
|
||||
|
||||
db.get('uid:' + uid + ':confirm:email:sent', next);
|
||||
},
|
||||
function (sent, next) {
|
||||
@@ -52,7 +90,7 @@ UserEmail.sendValidationEmail = function (uid, email, callback) {
|
||||
function (_confirm_code, next) {
|
||||
confirm_code = _confirm_code;
|
||||
db.setObject('confirm:' + confirm_code, {
|
||||
email: email.toLowerCase(),
|
||||
email: options.email.toLowerCase(),
|
||||
uid: uid,
|
||||
}, next);
|
||||
},
|
||||
|
||||
@@ -176,7 +176,9 @@ module.exports = function (User) {
|
||||
},
|
||||
function (next) {
|
||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && newEmail) {
|
||||
User.email.sendValidationEmail(uid, newEmail);
|
||||
User.email.sendValidationEmail(uid, {
|
||||
email: newEmail,
|
||||
});
|
||||
}
|
||||
User.setUserField(uid, 'email:confirmed', 0, next);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user