|
|
|
@ -27,61 +27,68 @@ var async = require('async'),
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserEmail.verify = function(uid, email, callback) {
|
|
|
|
|
UserEmail.sendValidationEmail = function(uid, email, callback) {
|
|
|
|
|
callback = callback || function() {};
|
|
|
|
|
var confirm_code = utils.generateUUID(),
|
|
|
|
|
confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:user.verify.code', confirm_code, function(err, confirm_code) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
var emailInterval = 10;
|
|
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
|
function(next) {
|
|
|
|
|
db.setObject('confirm:' + confirm_code, {
|
|
|
|
|
email: email.toLowerCase(),
|
|
|
|
|
uid: uid
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 2), next);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
db.get('uid:' + uid + ':confirm:email:sent', next);
|
|
|
|
|
},
|
|
|
|
|
function(sent, next) {
|
|
|
|
|
if (sent) {
|
|
|
|
|
return next(new Error('[[error:confirm-email-already-sent, ' + emailInterval + ']]'));
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
user.getUserField(uid, 'username', function(err, username) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return winston.error(err.stack);
|
|
|
|
|
}
|
|
|
|
|
db.set('uid:' + uid + ':confirm:email:sent', 1, next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
db.pexpireAt('uid:' + uid + ':confirm:email:sent', Date.now() + (emailInterval * 60 * 1000), next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
plugins.fireHook('filter:user.verify.code', confirm_code, next);
|
|
|
|
|
},
|
|
|
|
|
function(_confirm_code, next) {
|
|
|
|
|
confirm_code = _confirm_code;
|
|
|
|
|
db.setObject('confirm:' + confirm_code, {
|
|
|
|
|
email: email.toLowerCase(),
|
|
|
|
|
uid: uid
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 2), next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
user.getUserField(uid, 'username', next);
|
|
|
|
|
},
|
|
|
|
|
function(username, next) {
|
|
|
|
|
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
|
|
|
|
|
translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function(subject) {
|
|
|
|
|
var data = {
|
|
|
|
|
site_title: title,
|
|
|
|
|
username: username,
|
|
|
|
|
confirm_link: confirm_link,
|
|
|
|
|
confirm_code: confirm_code,
|
|
|
|
|
|
|
|
|
|
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
|
|
|
|
|
translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function(subject) {
|
|
|
|
|
var data = {
|
|
|
|
|
site_title: title,
|
|
|
|
|
username: username,
|
|
|
|
|
confirm_link: confirm_link,
|
|
|
|
|
confirm_code: confirm_code,
|
|
|
|
|
|
|
|
|
|
subject: subject,
|
|
|
|
|
template: 'welcome',
|
|
|
|
|
uid: uid
|
|
|
|
|
};
|
|
|
|
|
subject: subject,
|
|
|
|
|
template: 'welcome',
|
|
|
|
|
uid: uid
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (plugins.hasListeners('action:user.verify')) {
|
|
|
|
|
plugins.fireHook('action:user.verify', {uid: uid, data: data});
|
|
|
|
|
callback();
|
|
|
|
|
} else if (plugins.hasListeners('action:email.send')) {
|
|
|
|
|
emailer.send('welcome', uid, data, callback);
|
|
|
|
|
} else {
|
|
|
|
|
winston.warn('No emailer to send verification email!');
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (plugins.hasListeners('action:user.verify')) {
|
|
|
|
|
plugins.fireHook('action:user.verify', {uid: uid, data: data});
|
|
|
|
|
next();
|
|
|
|
|
} else if (plugins.hasListeners('action:email.send')) {
|
|
|
|
|
emailer.send('welcome', uid, data, next);
|
|
|
|
|
} else {
|
|
|
|
|
winston.warn('No emailer to send verification email!');
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserEmail.confirm = function(code, callback) {
|
|
|
|
|