Can anyone tell my why my login system isn't working on my server? it just returns user not found even though the users table in my mongo DB contains a valid username and password that I use. here is the code I use to try login.
app.post('/dologin', function (req, res) {
console.log(JSON.stringify(req.body))
var uname = req.body.username;
var pword = req.body.password;
db.collection('users').findOne({
"SignIn.username": uname
}, function (err, result) {
if (err) throw err;
if (!result) {
res.redirect('/SignIn');
console.log("user not found :(")
return
}
if (result.SignIn.password == pword) {
req.session.loggedin = true;
req.session.currentuser = uname;
res.redirect('pages/UserAccount')
console.log("a user was recognised, horay!")
} else {
res.redirect('/SignIn')
console.log("user not found :(")
}
});
});
this is the form used to take in the username and password it is stored in a file called SignIn.ejs:
<form action="/dologin" method="POST">
<input class="UsernameBox" type="text" placeholder="username" name="username">
<input class="PasswordBox" type="password" placeholder="password" name="password">
<button class="LogInButton" type="submit">login</button>
</form>
the MongoDB stores its username and passwords in a table called users
I need to get this going in the next day so any help would be greatly appreciated