mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	closes #2971
This commit is contained in:
		| @@ -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.", | ||||
| 	"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.", | ||||
| 	"confirm-email-already-sent": "Confirmation email already sent, please wait %1 minutes to send another one.", | ||||
|  | ||||
| 	"username-too-short": "Username too short", | ||||
| 	"username-too-long": "Username too long", | ||||
|   | ||||
| @@ -220,7 +220,9 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], | ||||
|  | ||||
| 	function handleEmailConfirm() { | ||||
| 		$('#confirm-email').on('click', function() { | ||||
| 			var btn = $(this).attr('disabled', true); | ||||
| 			socket.emit('user.emailConfirm', {}, function(err) { | ||||
| 				btn.removeAttr('disabled'); | ||||
| 				if (err) { | ||||
| 					return app.alertError(err.message); | ||||
| 				} | ||||
|   | ||||
| @@ -105,18 +105,26 @@ module.exports = function(redisClient, module) { | ||||
| 	}; | ||||
|  | ||||
| 	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) { | ||||
| 		redisClient.expireat(key, timestamp, callback); | ||||
| 		redisClient.expireat(key, timestamp, function(err) { | ||||
| 			callback(err); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| 	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) { | ||||
| 		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) { | ||||
| 			if (userData.email && userData.uid) { | ||||
| 				user.email.verify(userData.uid, userData.email, next);		 | ||||
| 				user.email.sendValidationEmail(userData.uid, userData.email, next); | ||||
| 			} else { | ||||
| 				next(); | ||||
| 			} | ||||
|   | ||||
| @@ -53,8 +53,7 @@ SocketUser.emailConfirm = function(socket, data, callback) { | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			user.email.verify(socket.uid, email); | ||||
| 			callback(); | ||||
| 			user.email.sendValidationEmail(socket.uid, email, callback); | ||||
| 		}); | ||||
| 	} | ||||
| }; | ||||
|   | ||||
| @@ -116,7 +116,7 @@ module.exports = function(User) { | ||||
| 							if (userData.email) { | ||||
| 								db.setObjectField('email:uid', userData.email.toLowerCase(), userData.uid, next); | ||||
| 								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 { | ||||
| 								next(); | ||||
|   | ||||
| @@ -27,18 +27,31 @@ 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([ | ||||
| 		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 + ']]')); | ||||
| 				} | ||||
| 				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 | ||||
| @@ -46,16 +59,11 @@ var async = require('async'), | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 2), next); | ||||
| 				} | ||||
| 			], function(err) { | ||||
| 				if (err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
| 				user.getUserField(uid, 'username', function(err, username) { | ||||
| 					if (err) { | ||||
| 						return winston.error(err.stack); | ||||
| 					} | ||||
|  | ||||
| 			}, | ||||
| 			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 = { | ||||
| @@ -71,17 +79,16 @@ var async = require('async'), | ||||
|  | ||||
| 					if (plugins.hasListeners('action:user.verify')) { | ||||
| 						plugins.fireHook('action:user.verify', {uid: uid, data: data}); | ||||
| 							callback(); | ||||
| 						next(); | ||||
| 					} else if (plugins.hasListeners('action:email.send')) { | ||||
| 							emailer.send('welcome', uid, data, callback); | ||||
| 						emailer.send('welcome', uid, data, next); | ||||
| 					} else { | ||||
| 						winston.warn('No emailer to send verification email!'); | ||||
| 							callback(); | ||||
| 						next(); | ||||
| 					} | ||||
| 				}); | ||||
| 				}); | ||||
| 			}); | ||||
| 		}); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
|  | ||||
| 	UserEmail.confirm = function(code, callback) { | ||||
|   | ||||
| @@ -162,7 +162,7 @@ module.exports = function(User) { | ||||
| 					}, | ||||
| 					function(next) { | ||||
| 						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); | ||||
| 					}, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user