should work but its not

This commit is contained in:
slawk0
2024-08-19 22:52:57 +02:00
parent ffe1c73dc0
commit a28be01f46
2 changed files with 40 additions and 0 deletions

View File

@@ -33,10 +33,37 @@ client.connect()
.catch((err) => console.log('Error on connecting to database: ', err));
app.post('/auth', function(req, res) {
let username = req.body.username.trim();
let password = req.body.password.trim();
if (username && password) {
client.query('SELECT * FROM accounts WHERE username = $1 AND password = $2', [username, password], function(error, results, fields) {
if (error) throw error;
if (results.length > 0) {
//Authenticate the user
req.session.loggedin = true;
req.session.username = username;
res.redirect('/');
} else {
res.send('Incorrect Username or Password!');
}
res.end();
});
} else {
res.send('Please enter Username and Password!');
res.end();
}
});
app.get('/login', (req, res) => {
res.sendFile(path.join(__dirname, '/public/routes/login.html'));
})
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/public/routes/index.html'));
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)

13
public/routes/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>LOGGED IN!!!</h1>
</body>
</html>