Fixed Login error in RegisterLogin.js

This commit is contained in:
Matthew Patrick 2021-11-16 12:51:52 +07:00
parent fc12e1fe65
commit e73910b8a0

View file

@ -126,45 +126,52 @@ exports.register = async function (req, res) {
}; };
exports.login = async function (req, res) { exports.login = async function (req, res) {
if ( if (!req.body.email || !req.body.password) {
!req.body.email || // Empty fields
!req.body.password
) {
// Empty Fields
res.render("pages/login-error"); res.render("pages/login-error");
} else { } else {
db_connect.query( var email = req.body.email;
"SELECT * FROM users WHERE email = ?", var password = req.body.password;
[email], db_connect.query(
async function (error, response, fields) { "SELECT * FROM users WHERE email = ?",
const passCheck = await bcrypt.compare(password, response[0].password); [email],
if (error) { async function (error, response, fields) {
// Error const passCheck = await bcrypt.compare(password, response[0].password);
res.render("pages/login-error"); if (error) {
} else { res.send({
if (response.length > 0) { code: 400,
if (passCheck) { failed: "An error has occured...",
if (response[0].verify == 0) { });
res.render("pages/login-error"); } else {
if (response.length > 0) {
if (passCheck) {
if (response[0].verify == 0) {
res.send({
code: 204,
success: "Sorry You havent verified your email",
});
} else {
res.send({
code: 200,
success: "Login Successful!!",
});
}
} else { } else {
res.render("pages/index"); res.send({
code: 204,
success: "Sorry Email and password does not match",
});
} }
} else { } else {
res.send({ res.send({
code: 204, code: 204,
success: "Sorry Email and password does not match", success: "Sorry Email does not exits",
}); });
} }
} else {
res.send({
code: 204,
success: "Sorry Email does not exits",
});
} }
} }
} );
); }
};
}; };
/* verification email link */ /* verification email link */