create endpoint for changing username

#68
This commit is contained in:
2020-05-15 21:52:51 +02:00
parent be49c3b06e
commit 7b3c262140

View File

@@ -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);