From 4ac85df1bb7b4a9a0dce23180c06498088f15a8b Mon Sep 17 00:00:00 2001 From: aeroreyna Date: Thu, 24 Mar 2022 22:58:22 -0700 Subject: [PATCH] set token --- dbTools/profile.js | 13 +++++++++++++ index.js | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/dbTools/profile.js b/dbTools/profile.js index 34f5233..aede2e9 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -215,6 +215,19 @@ userDB = (DB) => { }); } + DB.setProfileToken = (profileid, token)=>{ + const _id = DB.ObjectID(profileid); + let update = { + $set:{ + token + } + } + return DB.profileCols.updateOne({_id}, update).catch((err)=>{ + console.log(err); + return false; + }); + } + DB.addNotification = async (profileid, message, postid, commentIndx) => { const _id = DB.ObjectID(profileid); let update = { diff --git a/index.js b/index.js index 6927a1e..9f130e3 100644 --- a/index.js +++ b/index.js @@ -200,6 +200,15 @@ DB.getDB.then((DB)=>{ }); }); + app.post('/token/', sessionChecker, async (req, res) => { + const profileid = getProfileId(req); + let token = await DB.getProfile(req.body.token); + DB.setProfileToken(profileid, token); + return res.json({ + status: "ok" + }); + }); + // route for user logout const logout = function(req, res){ const session_id = getSessionId(req);