From a31e6b4c66494e63880db304c9a642ede4e3dbce Mon Sep 17 00:00:00 2001 From: xfarrow Date: Sun, 18 Feb 2024 12:14:24 +0100 Subject: [PATCH] check email already in use --- backend/apis/nodejs/api_controller.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/apis/nodejs/api_controller.js b/backend/apis/nodejs/api_controller.js index 7b11561..ba053ca 100644 --- a/backend/apis/nodejs/api_controller.js +++ b/backend/apis/nodejs/api_controller.js @@ -59,6 +59,16 @@ async function registerPerson(req, res){ const hashPasswordPromise = bcrypt.hash(req.body.password, 10); try{ + + // Check whether e-mail exists already (enforced by database constraints) + const existingUser = await knex('Person') + .where('email', req.body.email) + .first(); + + if(existingUser){ + return res.status(409).json({ error: "E-mail already in use" }); + } + // We need to insert either both in the "Person" table // and in the "ActivationLink" one, or in neither await knex.transaction(async (tr) => {