From 7b3c2621401b8af53c8900551eddcae1c7cc45fd Mon Sep 17 00:00:00 2001 From: Oliver Boehlk Date: Fri, 15 May 2020 21:52:51 +0200 Subject: [PATCH] create endpoint for changing username #68 --- backend/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/index.js b/backend/index.js index 8b79510..1a6a679 100644 --- a/backend/index.js +++ b/backend/index.js @@ -277,4 +277,19 @@ app.get('/API/resourcelist', function (req, res) { return res.send(resourceList); }); +app.post("/API/user/setname", function (req, res) { + let { email } = req.body; + if (email) { + if (DEBUG) return res.status(status.OK).send(); + connection.query(`UPDATE user SET email = ${mysql.escape(email)} WHERE email = ${mysql.escape(req.user.email)}`, function (err, rows) { + if (err) + return res.status(status.INTERNAL_SERVER_ERROR).send("the username seems invalid or already taken - if you think this is an error contact the sys admin"); + req.user.email = email; + return res.status(status.OK).send("username changed"); + }); + } else { + return res.status(status.BAD_REQUEST).send("invalid data supplied"); + } +}); + app.listen(3001);