diff --git a/backend/apis/nodejs/api_controller.js b/backend/apis/nodejs/api_controller.js index fd935c4..8cd417c 100644 --- a/backend/apis/nodejs/api_controller.js +++ b/backend/apis/nodejs/api_controller.js @@ -37,7 +37,11 @@ async function registerPerson(req, res){ // Ensure that the required fields are present before proceeding if (!req.body.display_name || !req.body.email || !req.body.password) { - return res.status(400).json({ error : "Invalid request"}); + return res.status(400).json({ error : "Some or all required fields are missing"}); + } + + if(!validateEmail(req.body.email)){ + return res.status(400).json({ error : "The email is not in a valid format"}); } // Generate activation link token @@ -377,6 +381,11 @@ function verifyToken(req, res, next) { }); } +function validateEmail(email) { + const regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/; + return regex.test(email); +} + // Exporting a function // means making a JavaScript function defined in one // module available for use in another module. diff --git a/frontend/html/html/register.html b/frontend/html/html/register.html index a41678a..7d716f9 100644 --- a/frontend/html/html/register.html +++ b/frontend/html/html/register.html @@ -52,15 +52,18 @@ }, body: JSON.stringify({ display_name, email, password }), }; + fetch('http://localhost:3000/blinkapi/register', options) .then(response => { if (response.ok) { - alert("Congratulations! You've successfully registered to Blink. Please click on the e-mail we sent you to confirm your account"); - // Redirect to a different page on the same domain using a relative path - window.location.href = '/newpage.html'; + alert("Congratulations! You've successfully registered to Blink." + + " Please click on the e-mail we sent you to confirm your account"); + + window.location.href = '/login.html'; } }) .catch(err => { + alert("An error has occured :-( please try again later") console.error(err); }); }