diff --git a/backend/mongo-todo.md b/backend/mongo-todo.md index 9864d6017..1f3021d05 100644 --- a/backend/mongo-todo.md +++ b/backend/mongo-todo.md @@ -1,17 +1,21 @@ # Mongo todo +## Todo + +Make sure that the branch is ready for deployment + +- Add deploy script(s) to package.json +- Make sure that firebase hosted app can connect to api when deployed +- Create a plan for apache/nginx server + - Api should probably be accessible via api.monkeytype.com or monkeytype.com/api + - Probably the previous since firebase might not work with seperate linux server + ## Bugs -- Graph bugs out when new result is added but page is not refreshed - - Graph loops back from earliest point to the new points - - Results list isn't updated either - - Result is added to end of list instead of front I think - - Could be fixed if list wasn't reversed and results were just rendered backwards - Some methods in functions/index.js may be broken - I think bot commands like lbUpdate and such -- Leaderboard entries that should be hidden are not -- If you are in first place and you place on the leaderboard but not above yourself, you get glb undefined error - - Might also occur if you are simply on the leaderboard and make the leaderboard but not above your current position + - Make sure discord can work + - Might just want to call the api from discord bot instead of firebase functions ### Minor/efficiency bugs @@ -24,7 +28,15 @@ - Can't navigate to user until page is refreshed - After refresh, pr is not saved - Can't induce this error and doesn't occur often so adding it as minor bug -- Does lbMemory work exactly like it did before +- lbmemory undefined if page not refreshed after user sign up? +- If you are in first place and you place on the leaderboard but not above yourself, you get glb undefined error + - Might also occur if you are simply on the leaderboard and make the leaderboard but not above your current position + - Doesn't happen all the time +- Hidden property of leaderboard is unused +- Verified property of user is unused, set at false by default + - Can't find where the property would be set in the code + - Is this discord verified, if so, why do you need discord verified to be on leaderboard? + - Temporarily removed from leaderboard requirements ### Possibilities @@ -33,3 +45,4 @@ - After an hour without a new request they can be removed from memory - Create a backup system to prevent loss of data - Users should be able to export their data themselves + - Pretty much is just the user snap but without uid diff --git a/backend/server.js b/backend/server.js index da2fd0698..7a57b2a93 100644 --- a/backend/server.js +++ b/backend/server.js @@ -625,7 +625,6 @@ app.post("/api/passwordReset", (req, res) => { app.get("/api/fetchSnapshot", authenticateToken, (req, res) => { /* Takes token and returns snap */ - console.log("UID: " + req.uid); User.findOne({ uid: req.uid }, (err, user) => { if (err) res.status(500).send({ error: err }); if (!user) res.status(200).send({ message: "No user found" }); //client doesn't do anything with this @@ -1394,34 +1393,64 @@ app.post("/api/attemptAddToLeaderboards", authenticateToken, (req, res) => { const result = req.body.result; let retData = {}; User.findOne({ uid: req.uid }, (err, user) => { - Leaderboard.find( - { - mode: result.mode, - mode2: result.mode2, - }, - (err, lbs) => { - //for all leaderboards queried, determine if it qualifies, and add if it does - lbs.forEach((lb) => { - if ( - lb.board.length == 0 || - lb.board.length < lb.size || - result.wpm > lb.board.slice(-1)[0].wpm - ) { - lb, (lbPosData = addToLeaderboard(lb, result, user.name)); //should uid be added instead of name? - console.log(user.lbMemory[lb.mode + lb.mode2][lb.type]); - //lbPosData.foundAt = user.lbMemory[lb.mode+lb.mode2][lb.type]; - retData[lb.type] = lbPosData; - lb.save(); - user.lbMemory[lb.mode + lb.mode2][lb.type] = - retData[lb.type].insertedAt; + admin + .auth() + .getUser(req.uid) + .then((fbUser) => { + return fbUser.emailVerified; + }) + .then((emailVerified) => { + if (user.emailVerified === false) { + if (emailVerified === true) { + user.emailVerified = true; + } else { + res.status(200).send({ needsToVerifyEmail: true }); + return; } + } + if (user.name === undefined) { + //cannot occur since name is required, why is this here? + res.status(200).send({ noName: true }); + return; + } + if (user.banned) { + res.status(200).send({ banned: true }); + return; + } + /* + if (user.verified === false) { + res.status(200).send({ needsToVerify: true }); + return; + }*/ + Leaderboard.find( + { + mode: result.mode, + mode2: result.mode2, + }, + (err, lbs) => { + //for all leaderboards queried, determine if it qualifies, and add if it does + lbs.forEach((lb) => { + if ( + lb.board.length == 0 || + lb.board.length < lb.size || + result.wpm > lb.board.slice(-1)[0].wpm + ) { + lb, (lbPosData = addToLeaderboard(lb, result, user.name)); //should uid be added instead of name? + console.log(user.lbMemory[lb.mode + lb.mode2][lb.type]); + //lbPosData.foundAt = user.lbMemory[lb.mode+lb.mode2][lb.type]; + retData[lb.type] = lbPosData; + lb.save(); + user.lbMemory[lb.mode + lb.mode2][lb.type] = + retData[lb.type].insertedAt; + } + }); + } + ).then((e) => { + retData.status = 2; + user.save(); + res.json(retData); }); - } - ).then((e) => { - retData.status = 2; - user.save(); - res.json(retData); - }); + }); }); res.status(200); }); diff --git a/src/js/account-controller.js b/src/js/account-controller.js index cf8218838..424e89eda 100644 --- a/src/js/account-controller.js +++ b/src/js/account-controller.js @@ -171,11 +171,6 @@ function signUp() { }) .then(async function () { // Update successful. - await firebase - .firestore() - .collection("users") - .doc(usr.uid) - .set({ name: nname }, { merge: true }); usr.sendEmailVerification(); AllTimeStats.clear(); Notifications.add("Account created", 1, 3); diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index 6af9b5526..89cf44fbc 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -1616,7 +1616,7 @@ export function finish(difficultyFailed = false) { DB.getSnapshot() !== null && DB.getSnapshot().results !== undefined ) { - DB.getSnapshot().results.unshift(completedEvent); + DB.getSnapshot().results.push(completedEvent); if (DB.getSnapshot().globalStats.time == undefined) { DB.getSnapshot().globalStats.time = testtime +