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