Fix to index.js to fix code differences after merge

This commit is contained in:
Lucas Patenaude
2024-04-10 23:09:30 -06:00
parent e8760282a6
commit f68c5b0c24
2 changed files with 21 additions and 33 deletions

View File

@@ -158,6 +158,7 @@ app.get('/', (req, res) => {
res.render('pages/register');
});
// Trigger Registration Form to Post
app.post('/register', async (req, res) => {
try {
@@ -170,18 +171,16 @@ app.get('/', (req, res) => {
// Insert username and hashed password into the 'users' table
await db.none('INSERT INTO users (username, password) VALUES ($1, $2)', [req.body.username, hash]);
//res.status(200);
res.json({status: 'success', message: 'Success'});
// Direct user to login screen after data has been inserted successfully
// Redirect user to the login page after successful registration
res.redirect('/login');
} catch (error) {
// If the insert fails, redirect to GET /register route
res.status(400);
//res.json({status: 'success', message: 'Invalid input'});
res.redirect('/register');
// If an error occurs during registration, respond with status 500 and an error message
res.status(500).json({ status: 'error', message: 'An error occurred during registration' });
}
});
/************************
Home Page Routes
*************************/

View File

@@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img src="./img/premie.jpg"
</body>
</html>