users and profiles working

This commit is contained in:
Adolfo Reyna
2021-09-02 09:59:58 -07:00
parent a7ca68e6df
commit ba2b0bcbd6
4 changed files with 28 additions and 2 deletions

View File

@@ -140,6 +140,19 @@ DB.getDB.then((DB)=>{
return await login(req, res);
});
app.post('/changeProfile', sessionChecker, async (req, res) => {
const user_sid = getUserId(req);
let profile = await DB.getProfile(req.body.profileid);
if(!profile || profile.userid != user_sid) return res.json({
status: "profile does not belong to the logged user",
});
res.cookie('profile_id', profile._id, cookiesOptions);
return res.json({
status: "ok",
...profile
});
});
// route for user logout
const logout = function(req, res){
const session_id = getSessionId(req);