Rely on userId, not email address

This commit is contained in:
Felix Albrigtsen 2022-04-24 13:56:34 +02:00
parent 42123fb41a
commit d49fedf24f
1 changed files with 11 additions and 25 deletions

View File

@ -56,7 +56,6 @@ app.use('/static/*', express.static(path.join(__dirname, 'clientbuild/static')))
// #region PASSPORT / OAUTH // #region PASSPORT / OAUTH
const passport = require('passport'); const passport = require('passport');
const { getUserByEmail } = require("./tmdb.js");
var userProfile; var userProfile;
app.use(passport.initialize()); app.use(passport.initialize());
@ -503,44 +502,31 @@ api.post("/users/createBlank", async (req, res) => {
}); });
}); });
api.post("/users/changeManagerStatus", async (req, res) => { api.post("/users/:asuraId/changeManagerStatus", async (req, res) => {
if (!(await isManager(req.session))) { if (!(await isManager(req.session))) {
res.json({"status": "error", "data": "Not authorized"}); res.json({"status": "error", "data": "Not authorized"});
return return
} }
let emailAddress = req.body.emailAddress; let asuraId = req.params.asuraId;
let isManager = req.body.isManager; let isManager = req.body.isManager;
console.log(asuraId, isManager);
tmdb.changeManagerStatus(asuraId, isManager)
tmdb.getUserByEmail(emailAddress)
.then(user => {
tmdb.changeManagerStatus(user.id, isManager)
.then(msg => res.json({"status": "OK", "data": msg})) .then(msg => res.json({"status": "OK", "data": msg}))
.catch(err => res.json({"status": "error", "data": err})); .catch(err => res.json({"status": "error", "data": err}));
})
.catch(err => {
console.log(err);
res.json({"status": "error", "data": "Could not update the specified user"});
});
}); });
api.post("/deleteUser", async (req, res) => { api.delete("/users/:asuraId", async (req, res) => {
if (!(await isManager(req.session))) { if (!(await isManager(req.session))) {
res.json({"status": "error", "data": "Not authorized"}); res.json({"status": "error", "data": "Not authorized"});
return return
} }
let emailAddress = req.body.emailAddress; let asuraId = req.params.asuraId;
tmdb.getUserByEmail(emailAddress) tmdb.deleteUser(asuraId)
.then(user => {
tmdb.deleteUser(user.id)
.then(msg => res.json({"status": "OK", "data": msg})) .then(msg => res.json({"status": "OK", "data": msg}))
.catch(err => res.json({"status": "error", "data": err})); .catch(err => res.json({"status": "error", "data": err}));
})
.catch(err => {
console.log(err);
res.json({"status": "error", "data": "Could not update the specified user"});
});
}); });