Merge pull request #502 from andrewhayward/passwords

Resolving password resetting confusions
This commit is contained in:
Chris McAvoy 2013-06-06 10:10:21 -07:00
Родитель 9ad976a4a4 ec94905607
Коммит e7ff9fd22c
1 изменённых файлов: 29 добавлений и 17 удалений

Просмотреть файл

@ -559,6 +559,24 @@ module.exports = function (app) {
}); });
} }
function updateUserPassword (user) {
bcrypt.hash(password, BCRYPT_SEED_ROUNDS, function(err, hash) {
if (err || !hash)
return finalize(err || 'Failed to generate new password - please try again.');
user.updateAttributes({
password: hash
}).complete(function(err) {
if (err)
return finalize(err);
sendConfirmationEmail(user);
finalize();
});
});
}
if (!validatePassword(password)) { if (!validatePassword(password)) {
req.flash('error', 'This is not a valid password'); req.flash('error', 'This is not a valid password');
return res.redirect('/login/password/' + token.token); return res.redirect('/login/password/' + token.token);
@ -572,28 +590,22 @@ module.exports = function (app) {
return finalize(err); return finalize(err);
token.getUser(function (err, user) { token.getUser(function (err, user) {
if (user.email !== username && user.username !== normalizeUsername(username)) if (user.email === username || user.username === normalizeUsername(username))
return updateUserPassword(user);
if (!user.GuardianId)
return finalize('Invalid nickname or email address'); return finalize('Invalid nickname or email address');
if (user.underage) { // Make allowances for situations where guardians have entered their
password = generatedPassword; // own email address when resetting their child's password
}
bcrypt.hash(password, BCRYPT_SEED_ROUNDS, function(err, hash) { user.getGuardian()
if (err || !hash) .complete(function (err, guardian) {
return finalize(err || 'Failed to generate new password - please try again.'); if (err || !guardian)
return finalize('Invalid nickname or email address');
user.updateAttributes({ updateUserPassword(user);
password: hash
}).complete(function(err) {
if (err)
return finalize(err);
sendConfirmationEmail(user);
finalize();
}); });
});
}); });
}); });
}); });