v1.18.x
barisusakli 10 years ago
parent ceba856006
commit fa9fde43fb

@ -26,6 +26,7 @@
"email-not-confirmed-chat": "You are unable to chat until your email is confirmed, please click here to confirm your email.", "email-not-confirmed-chat": "You are unable to chat until your email is confirmed, please click here to confirm your email.",
"no-email-to-confirm": "This forum requires email confirmation, please click here to enter an email", "no-email-to-confirm": "This forum requires email confirmation, please click here to enter an email",
"email-confirm-failed": "We could not confirm your email, please try again later.", "email-confirm-failed": "We could not confirm your email, please try again later.",
"confirm-email-already-sent": "Confirmation email already sent, please wait %1 minutes to send another one.",
"username-too-short": "Username too short", "username-too-short": "Username too short",
"username-too-long": "Username too long", "username-too-long": "Username too long",

@ -220,7 +220,9 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
function handleEmailConfirm() { function handleEmailConfirm() {
$('#confirm-email').on('click', function() { $('#confirm-email').on('click', function() {
var btn = $(this).attr('disabled', true);
socket.emit('user.emailConfirm', {}, function(err) { socket.emit('user.emailConfirm', {}, function(err) {
btn.removeAttr('disabled');
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }

@ -105,18 +105,26 @@ module.exports = function(redisClient, module) {
}; };
module.expire = function(key, seconds, callback) { module.expire = function(key, seconds, callback) {
redisClient.expire(key, seconds, callback); redisClient.expire(key, seconds, function(err) {
callback(err);
});
}; };
module.expireAt = function(key, timestamp, callback) { module.expireAt = function(key, timestamp, callback) {
redisClient.expireat(key, timestamp, callback); redisClient.expireat(key, timestamp, function(err) {
callback(err);
});
}; };
module.pexpire = function(key, ms, callback) { module.pexpire = function(key, ms, callback) {
redisClient.pexpire(key, ms, callback); redisClient.pexpire(key, ms, function(err) {
callback(err);
});
}; };
module.pexpireAt = function(key, timestamp, callback) { module.pexpireAt = function(key, timestamp, callback) {
redisClient.pexpireat(key, timestamp, callback); redisClient.pexpireat(key, timestamp, function(err) {
callback(err);
});
}; };
}; };

@ -144,7 +144,7 @@ User.sendValidationEmail = function(socket, uids, callback) {
async.eachLimit(usersData, 50, function(userData, next) { async.eachLimit(usersData, 50, function(userData, next) {
if (userData.email && userData.uid) { if (userData.email && userData.uid) {
user.email.verify(userData.uid, userData.email, next); user.email.sendValidationEmail(userData.uid, userData.email, next);
} else { } else {
next(); next();
} }

@ -53,8 +53,7 @@ SocketUser.emailConfirm = function(socket, data, callback) {
return; return;
} }
user.email.verify(socket.uid, email); user.email.sendValidationEmail(socket.uid, email, callback);
callback();
}); });
} }
}; };

@ -116,7 +116,7 @@ module.exports = function(User) {
if (userData.email) { if (userData.email) {
db.setObjectField('email:uid', userData.email.toLowerCase(), userData.uid, next); db.setObjectField('email:uid', userData.email.toLowerCase(), userData.uid, next);
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) { if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
User.email.verify(userData.uid, userData.email); User.email.sendValidationEmail(userData.uid, userData.email);
} }
} else { } else {
next(); next();

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

@ -162,7 +162,7 @@ module.exports = function(User) {
}, },
function(next) { function(next) {
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && newEmail) { if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && newEmail) {
User.email.verify(uid, newEmail); User.email.sendValidationEmail(uid, newEmail);
} }
User.setUserField(uid, 'email:confirmed', 0, next); User.setUserField(uid, 'email:confirmed', 0, next);
}, },

Loading…
Cancel
Save