diff --git a/index.js b/index.js index 466b3c8..730dd7c 100644 --- a/index.js +++ b/index.js @@ -46,7 +46,7 @@ app.post('/logIn', (req, res) => { const { pseudo, password } = req.body; if (!pseudo || !password) { - return res.status(400).send('pseudo and password are required.'); + return res.status(400).send({message:'pseudo and password are required.'}); } const query = 'SELECT hashed_password FROM users WHERE pseudo = ?'; @@ -75,7 +75,11 @@ app.post('/register', async (req, res) => { const { pseudo, password } = req.body; if (!pseudo || !password) { - return res.status(400).send('Email and password are required.'); + return res.status(400).send({message:'Pseudo and password are required.'}); + } + + if (pseudo.length > 255 || password.length > 255) { + return res.status(403).send({message:'Pseudo and password must be 255 caracters max'}); } const hashedPassword = await bcrypt.hash(password, 10); diff --git a/public/scripts/register.js b/public/scripts/register.js index c905e21..7720b83 100644 --- a/public/scripts/register.js +++ b/public/scripts/register.js @@ -17,7 +17,8 @@ document.getElementById('registerForm').addEventListener('submit', async functio }); const result = await response.json(); - + + if (response.ok) { messageDiv.textContent = 'User registered successfully!'; messageDiv.style.color = 'green'; @@ -49,4 +50,4 @@ document.addEventListener('DOMContentLoaded', async () => { } catch (error) { console.error("Error : ", error) } -}); \ No newline at end of file +});