Updated codes for user controller login and check email

master
parent 2c7c371615
commit 040dbf8dd4

@ -14,12 +14,12 @@ module.exports.checkEmailExists = (request, response, next) => {
User.find({email : reqBody.email}) User.find({email : reqBody.email})
.then(result => { .then(result => {
if(result.length > 0){ if(result.length > 0){
return response.send(`User already exist!`); return response.send(false);
}else{ }else{
next(); next();
} }
}) })
.catch(error => response.send("Error occurred!")); .catch(error => response.send(false));
} }
// Register user controller // Register user controller
@ -44,7 +44,7 @@ module.exports.loginUser = (request, response) => {
User.findOne({email : reqBody.email}).then(result => { User.findOne({email : reqBody.email}).then(result => {
if(result === null) { if(result === null) {
return response.send((`Email does not exist. Register first before logging in!`)); return response.send(false);
}else{ }else{
const isPasswordCorrect = bcrypt.compareSync(reqBody.password, result.password); const isPasswordCorrect = bcrypt.compareSync(reqBody.password, result.password);
@ -56,7 +56,7 @@ module.exports.loginUser = (request, response) => {
return response.send({accessToken: token}); return response.send({accessToken: token});
}else{ }else{
return response.send(`You incorrect password. Please try again!`); return response.send(false);
} }
} }
}) })

Loading…
Cancel
Save