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

@@ -39,8 +39,10 @@ userDB = (DB) => {
console.log(err); console.log(err);
return false; return false;
}); });
if (r[0]) userProfileCache[r[0].id] = r[0]; let index = 0;
return r[0]; while(r[index].isGroup) index += 1;
if (r[index]) userProfileCache[r[index].id] = r[index];
return r[index];
} }
//Groups //Groups

View File

@@ -17,6 +17,7 @@ class User {
this.lastUpdate = info.lastUpdate || new Date(); this.lastUpdate = info.lastUpdate || new Date();
this.newsFeedCache = info.newsFeedCache || []; this.newsFeedCache = info.newsFeedCache || [];
this.isGroup = info.isGroup || false; this.isGroup = info.isGroup || false;
this.isCourse = info.isCourse || false;
} }
toObj(){ toObj(){
@@ -30,6 +31,7 @@ class User {
r.lastUpdate = this.lastUpdate; r.lastUpdate = this.lastUpdate;
r.newsFeedCache = this.newsFeedCache; r.newsFeedCache = this.newsFeedCache;
r.isGroup = this.isGroup; r.isGroup = this.isGroup;
r.isCourse = this.isCourse;
return r; return r;
} }

View File

@@ -140,6 +140,19 @@ DB.getDB.then((DB)=>{
return await login(req, res); 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 // route for user logout
const logout = function(req, res){ const logout = function(req, res){
const session_id = getSessionId(req); const session_id = getSessionId(req);

View File

@@ -11,6 +11,15 @@ DB.getDB.then((DB)=>{
return DB.ObjectID(user_sid); return DB.ObjectID(user_sid);
} }
router.get("/mine", async (req, res) => {
let userid = req.cookies.user_sid;
let profiles = await DB.getUserProfiles(userid);
return res.json({
status: "ok",
profiles
});
});
router.get("/new", async (req, res) => { router.get("/new", async (req, res) => {
let profile = { let profile = {
userid: getUserId(req), userid: getUserId(req),