User update
parent
46d54d339f
commit
b3b1a79bee
|
@ -12,27 +12,22 @@ module.exports = (req, res, next) => {
|
||||||
return next({ status: 401, message: 'User does not exists.' });
|
return next({ status: 401, message: 'User does not exists.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.password) {
|
if (req.body.password && req.body.new_password) {
|
||||||
bcrypt.compare(req.body.password, user.password, (error, result) => {
|
bcrypt.compare(req.body.password, user.password, (error, result) => {
|
||||||
if (!result || error) {
|
if (!result || error) {
|
||||||
return next(
|
return next(
|
||||||
{
|
{
|
||||||
status: 401,
|
status: 401,
|
||||||
message: 'Authentication failed. Wrong password.',
|
message: 'Authentication failed. Wrong password.',
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.password === req.body.new_password) {
|
return bcrypt.hash(req.body.new_password, null, null, (hashErr, hash) => {
|
||||||
return next(
|
userObj.password = hash;
|
||||||
{
|
|
||||||
status: 401,
|
|
||||||
message: 'New password must be different than old password.',
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
userObj.password = bcrypt.hashSync(req.body.new_password);
|
return userObj.save(() => res.status(200).json(userObj));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
userObj.firstname = req.body.firstname || userObj.firstname;
|
userObj.firstname = req.body.firstname || userObj.firstname;
|
||||||
|
|
|
@ -28,6 +28,15 @@ module.exports = (req, res, next) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*if (req.body.password && req.body.password === req.body.new_password) {
|
||||||
|
return next(
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
message: 'New password must be different than old password.',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue