This commit is contained in:
xfarrow
2023-10-18 15:17:04 +02:00
parent 0cb7adef30
commit 55c2d889e8
2 changed files with 16 additions and 4 deletions

View File

@ -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.