diff --git a/src/gameplay/game.ts b/src/gameplay/game.ts index 65c42b9ee..ff448c49a 100644 --- a/src/gameplay/game.ts +++ b/src/gameplay/game.ts @@ -422,7 +422,7 @@ class Game extends Room { // assign them the sockets but with shuffled. this.playersInGame[i].username = this.socketsOfPlayers[i].request.user.username; - this.playersInGame[i].userId = this.socketsOfPlayers[i].request.user._id; + this.playersInGame[i].userId = this.socketsOfPlayers[i].request.user.id; this.playersInGame[i].request = this.socketsOfPlayers[i].request; diff --git a/src/gameplay/types.ts b/src/gameplay/types.ts index c531cda94..9a3d3e7d7 100644 --- a/src/gameplay/types.ts +++ b/src/gameplay/types.ts @@ -34,6 +34,7 @@ export interface See { } export interface IUser { + id: string; username: string; usernameLower?: string; password?: string; @@ -75,7 +76,7 @@ export interface IUser { matchmakingBlacklist?: string[]; // Mongoose methods - save: () => Promise; + save: () => Promise; markModified: (path: string) => void; } diff --git a/src/routes/forum.ts b/src/routes/forum.ts index 2849c2ea6..1facdc2a4 100644 --- a/src/routes/forum.ts +++ b/src/routes/forum.ts @@ -70,15 +70,15 @@ router.get( if (!found.whoLikedId) found.whoLikedId = []; // person has already liked it, so unlike it and remove their name - if (found.whoLikedId.includes(req.user._id)) { - const i = found.whoLikedId.indexOf(req.user._id); + if (found.whoLikedId.includes(req.user.id)) { + const i = found.whoLikedId.indexOf(req.user.id); // remove their id found.whoLikedId.splice(i, 1); found.likes -= 1; res.status(200).send('unliked'); } else { // add a like - found.whoLikedId.push(req.user._id); + found.whoLikedId.push(req.user.id); found.likes += 1; res.status(200).send('liked'); diff --git a/src/routes/forum/forumThreadCommentReplyRoutes.js b/src/routes/forum/forumThreadCommentReplyRoutes.js index 9166c329a..90b05162f 100644 --- a/src/routes/forum/forumThreadCommentReplyRoutes.js +++ b/src/routes/forum/forumThreadCommentReplyRoutes.js @@ -75,7 +75,7 @@ async function createCommentReply(req, res) { allowedAttributes: sanitizeHtmlAllowedAttributesForumThread, }), - author: { id: req.user._id, username: req.user.username }, + author: { id: req.user.id, username: req.user.username }, timeCreated: d, timeLastEdit: d, diff --git a/src/routes/forum/forumThreadCommentRoutes.js b/src/routes/forum/forumThreadCommentRoutes.js index 2b7420c24..73389c2c6 100644 --- a/src/routes/forum/forumThreadCommentRoutes.js +++ b/src/routes/forum/forumThreadCommentRoutes.js @@ -44,7 +44,7 @@ router.post( allowedTags: sanitizeHtml.defaults.allowedTags.concat(allowedHtmlTags), allowedAttributes: allowedHtmlAttributes, }), - author: { id: req.user._id, username: req.user.username }, + author: { id: req.user.id, username: req.user.username }, timeCreated: new Date(), timeLastEdit: new Date(), likes: 0, diff --git a/src/routes/forum/forumThreadRoutes.js b/src/routes/forum/forumThreadRoutes.js index 3ff553618..e9197e338 100644 --- a/src/routes/forum/forumThreadRoutes.js +++ b/src/routes/forum/forumThreadRoutes.js @@ -40,7 +40,7 @@ router.get( }); }); - const userIdString = req.user._id.toString().replace(' ', ''); + const userIdString = req.user.id.toString().replace(' ', ''); const idsOfLikedPosts = []; const addToLikedPosts = (item) => { @@ -189,7 +189,7 @@ router.post( timeLastEdit: new Date(), whoLastEdit: req.user.username, author: { - id: req.user._id, + id: req.user.id, username: req.user.username, }, comments: [], diff --git a/src/routes/index.js b/src/routes/index.js index ac79905ff..e70edb8dd 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -914,7 +914,7 @@ router.get('/ajax/hideNotification', (req, res) => { router.get('/ajax/hideAllNotifications', (req, res) => { // console.log("hide all nofications"); - User.findById(req.user._id) + User.findById(req.user.id) .populate('notifications') .exec(async (err, foundUser) => { if (err) { diff --git a/src/routes/middleware.ts b/src/routes/middleware.ts index 1e864c9b9..f21328f68 100644 --- a/src/routes/middleware.ts +++ b/src/routes/middleware.ts @@ -74,7 +74,7 @@ export const isLoggedIn = asyncMiddleware(async (req, res, next) => { res.locals.bansChecked = true; // Check bans const ban = await Ban.findOne({ - 'bannedPlayer.id': user._id, // User ID match + 'bannedPlayer.id': user.id, // User ID match whenRelease: { $gt: new Date() }, // Unexpired ban userBan: true, // User ban disabled: false, // Ban must be active @@ -158,7 +158,7 @@ const checkOwnership = (name, model, query, isOwner) => [ next(); } else { console.log( - `${req.user._id} ${req.user.username} has attempted to do something bad`, + `${req.user.id} ${req.user.username} has attempted to do something bad`, ); req.flash('error', 'You are not the owner!'); res.redirect('back'); @@ -181,7 +181,7 @@ export const checkForumThreadOwnership = checkOwnership( (req) => ({ _id: req.params.id, }), - (req, thread) => thread.author.id && thread.author.id.equals(req.user._id), + (req, thread) => thread.author.id && thread.author.id.equals(req.user.id), ); export const checkForumThreadCommentOwnership = checkOwnership( @@ -190,7 +190,7 @@ export const checkForumThreadCommentOwnership = checkOwnership( (req) => ({ _id: req.params.comment_id, }), - (req, comment) => comment.author.id && comment.author.id.equals(req.user._id), + (req, comment) => comment.author.id && comment.author.id.equals(req.user.id), ); export const checkForumThreadCommentReplyOwnership = checkOwnership( @@ -199,7 +199,7 @@ export const checkForumThreadCommentReplyOwnership = checkOwnership( (req) => ({ _id: req.params.reply_id, }), - (req, reply) => reply.author.id && reply.author.id.equals(req.user._id), + (req, reply) => reply.author.id && reply.author.id.equals(req.user.id), ); export const isModMiddleware = (req, res, next) => { diff --git a/src/routes/mod.js b/src/routes/mod.js index 06910a78e..90a19ccbb 100644 --- a/src/routes/mod.js +++ b/src/routes/mod.js @@ -55,7 +55,7 @@ router.post('/ban', async (req, res) => { const userIsPercy = isPercival(req.user.username); if ((userIsMod ^ userIsPercy) !== 1) { - throw Error("Expected requesting user to either be a mod or a Percy."); + throw Error('Expected requesting user to either be a mod or a Percy.'); } try { @@ -186,13 +186,13 @@ router.post('/ban', async (req, res) => { singleIPBan: req.body['SingleIPBanCheckbox'] === 'on' ? true : false, userBan: req.body['userBanCheckbox'] === 'on' ? true : false, bannedPlayer: { - id: banUser._id, + id: banUser.id, username: banUser.username, usernameLower: banUser.usernameLower, }, bannedIPs: ipsToBan, modWhoBanned: { - id: modUser._id, + id: modUser.id, username: modUser.username, usernameLower: modUser.usernameLower, }, @@ -210,7 +210,7 @@ router.post('/ban', async (req, res) => { await ModLog.create({ type: 'ban', modWhoMade: { - id: modUser._id, + id: modUser.id, username: modUser.username, usernameLower: modUser.usernameLower, }, @@ -218,10 +218,16 @@ router.post('/ban', async (req, res) => { dateCreated: new Date(), }); - sendToDiscordMods(`${userIsMod ? "Moderator" : "Percival"} "${req.user.usernameLower}" banned "${banUser.usernameLower}" for \ -${req.body['duration']} ${req.body['duration_units']} for reason "${req.body.reason}" with description \ -"${req.body['descriptionByMod']}".` - , false); + sendToDiscordMods( + `${userIsMod ? 'Moderator' : 'Percival'} "${ + req.user.usernameLower + }" banned "${banUser.usernameLower}" for \ +${req.body['duration']} ${req.body['duration_units']} for reason "${ + req.body.reason + }" with description \ +"${req.body['descriptionByMod']}".`, + false, + ); // Delete all the sessions associated with this username const dbResult = await MongoClient.connect(process.env.DATABASEURL); @@ -355,10 +361,10 @@ router.post('/report', async (req, res) => { reason: req.body.reason, reportedPlayer: { username: reportedUser.username.toLowerCase(), - id: reportedUser._id, + id: reportedUser.id, }, playerWhoReported: { - id: userWhoReported._id, + id: userWhoReported.id, username: userWhoReported.username.toLowerCase(), }, description: req.body.desc, diff --git a/src/routes/profile/index.tsx b/src/routes/profile/index.tsx index 8507ea34e..0a7688a08 100644 --- a/src/routes/profile/index.tsx +++ b/src/routes/profile/index.tsx @@ -258,7 +258,7 @@ router.post('/mod/deleteuseravatar', isModMiddleware, async (req, res) => { await ModLog.create({ type: 'avatarDelete', modWhoMade: { - id: modWhoProcessed._id, + id: modWhoProcessed.id, username: modWhoProcessed.username, usernameLower: modWhoProcessed.usernameLower, }, @@ -329,7 +329,7 @@ router.post( let str = `Your avatar request was approved by ${modWhoProcessed.username}! Their comment was: "${modComment}"`; createNotification( - userRequestingAvatar._id, + userRequestingAvatar.id, str, '#', modWhoProcessed.username, @@ -342,7 +342,7 @@ router.post( let str = `Your avatar request was rejected by ${modWhoProcessed.username}. Their comment was: "${modComment}"`; createNotification( - userRequestingAvatar._id, + userRequestingAvatar.id, str, '#', modWhoProcessed.username, @@ -353,7 +353,7 @@ router.post( ModLog.create({ type: 'avatar', modWhoMade: { - id: modWhoProcessed._id, + id: modWhoProcessed.id, username: modWhoProcessed.username, usernameLower: modWhoProcessed.usernameLower, }, diff --git a/src/sockets/commands/mod/miplinkedaccs.ts b/src/sockets/commands/mod/miplinkedaccs.ts index f025893ed..f9cf3730a 100644 --- a/src/sockets/commands/mod/miplinkedaccs.ts +++ b/src/sockets/commands/mod/miplinkedaccs.ts @@ -93,7 +93,7 @@ export const miplinkedaccs: Command = { ModLog.create({ type: 'miplinkedaccs', modWhoMade: { - id: modUser._id, + id: modUser.id, username: modUser.username, usernameLower: modUser.usernameLower, }, diff --git a/src/sockets/commands/mod/mnotify.ts b/src/sockets/commands/mod/mnotify.ts index 37d3704b8..1871ec121 100644 --- a/src/sockets/commands/mod/mnotify.ts +++ b/src/sockets/commands/mod/mnotify.ts @@ -27,7 +27,7 @@ export const mnotify: Command = { classStr: 'server-text', }); } else if (foundUser) { - const userIdTarget = foundUser._id; + const userIdTarget = foundUser.id; const stringToSay = str; const link = '#'; @@ -43,7 +43,7 @@ export const mnotify: Command = { }, data: { targetUser: { - id: foundUser._id, + id: foundUser.id, username: foundUser.username, usernameLower: foundUser.usernameLower, }, diff --git a/src/sockets/commands/mod/munban.ts b/src/sockets/commands/mod/munban.ts index 3e3efd234..e83eb3184 100644 --- a/src/sockets/commands/mod/munban.ts +++ b/src/sockets/commands/mod/munban.ts @@ -33,7 +33,7 @@ export const munban: Command = { ModLog.create({ type: 'munban', modWhoMade: { - id: modUser._id, + id: modUser.id, username: modUser.username, usernameLower: modUser.usernameLower, },