mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Update email check exist (#7899)
* throw a 401 error if user tries to update his/her email to an email that exists already * Make error message generic so we don't violate users' privacy. Added test case. * Syntax fixes * select only the _id field when searching for users with the same email. Return found document as javascript object.
This commit is contained in:
committed by
Blade Barringer
parent
02545ae439
commit
12f1aae2dd
@@ -545,6 +545,9 @@ api.updateEmail = {
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let emailAlreadyInUse = await User.findOne({'auth.local.email': req.body.newEmail}).select({_id: 1}).lean().exec();
|
||||
if (emailAlreadyInUse) throw new NotAuthorized(res.t('cannotFulfillReq'));
|
||||
|
||||
let candidatePassword = passwordUtils.encrypt(req.body.password, user.auth.local.salt);
|
||||
if (candidatePassword !== user.auth.local.hashed_password) throw new NotAuthorized(res.t('wrongPassword'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user