<%= lang.global.messages %>
<%= lang.messages.coming_soon %>
+From fd3031b4edf232b07964a4c350abb0f0e2582f7c Mon Sep 17 00:00:00 2001 From: CaramelKat <32065563+caramelkat@users.noreply.github.com> Date: Sun, 17 Oct 2021 11:21:10 -0500 Subject: [PATCH] Actually fixed Access Token decryption --- src/authentication.js | 9 +++--- src/database.js | 22 ++++++++++++- src/models/conversation.js | 32 +++++++++++++++++++ src/models/post.js | 10 ++++-- .../juxt-web/routes/console/messages.js | 6 ++-- src/webfiles/portal/messages.ejs | 21 +++++++++++- 6 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 src/models/conversation.js diff --git a/src/authentication.js b/src/authentication.js index 286b81c..11df5a3 100644 --- a/src/authentication.js +++ b/src/authentication.js @@ -112,12 +112,12 @@ let methods = { } catch(e) { + console.log(e) return null; } }, decryptToken: function(token) { - // Access and refresh tokens use a different format since they must be much smaller // Assume a small length means access or refresh token if (token.length <= 32) { @@ -133,6 +133,7 @@ let methods = { return decryptedBody; } + const cryptoPath = `${__dirname}/certs/access`; const cryptoOptions = { @@ -170,7 +171,7 @@ let methods = { const hmac = crypto.createHmac('sha1', cryptoOptions.hmac_secret).update(decryptedBody); const calculatedSignature = hmac.digest(); - if (calculatedSignature !== signature) { + if (Buffer.compare(calculatedSignature, signature) !== 0) { console.log('Token signature did not match'); return null; } @@ -222,9 +223,7 @@ let methods = { Buffer.from('\x02\x65\x43\x46'), Buffer.from(password) ]); - const hashed = crypto.createHash('sha256').update(unpacked).digest().toString('hex'); - - return hashed; + return crypto.createHash('sha256').update(unpacked).digest().toString('hex'); }, getCommunityHash: function() { return communityMap; diff --git a/src/database.js b/src/database.js index 892837b..c85d1ea 100644 --- a/src/database.js +++ b/src/database.js @@ -5,6 +5,7 @@ const { ENDPOINT } = require('./models/endpoint'); const { COMMUNITY } = require('./models/communities'); const { POST } = require('./models/post'); const { USER } = require('./models/user'); +const { CONVERSATION } = require('./models/conversation'); const { uri, database, options } = mongooseConfig; let connection; @@ -303,6 +304,23 @@ async function getNewsFeedAfterTimestamp(user, numberOfPosts, post) { }).limit(numberOfPosts).sort({ created_at: -1}); } +async function getConversations(pid) { + verifyConnected(); + return CONVERSATION.find({ + pids: pid + }); +} + +async function getConversation(pid, pid2) { + verifyConnected(); + return CONVERSATION.find({ + $and: [ + {pids: pid}, + {pids: pid2} + ], + }); +} + module.exports = { connect, getCommunities, @@ -337,5 +355,7 @@ module.exports = { getNewsFeed, getNewsFeedAfterTimestamp, getFollowingUsers, - getFollowedUsers + getFollowedUsers, + getConversations, + getConversation, }; \ No newline at end of file diff --git a/src/models/conversation.js b/src/models/conversation.js new file mode 100644 index 0000000..1237438 --- /dev/null +++ b/src/models/conversation.js @@ -0,0 +1,32 @@ +const { Schema, model } = require('mongoose'); + +const ConversationSchema = new Schema({ + created_at: { + type: Date, + default: new Date(), + }, + id: { + type: String, + default: 0 + }, + pids: [Number], +}); + +ConversationSchema.methods.addUser = async function(pid) { + const conversation = this.get('pids'); + conversation.addToSet(pid); + await this.save(); +} + +ConversationSchema.methods.removeUser = async function(pid) { + const conversation = this.get('pids'); + conversation.pull(pid); + await this.save(); +} + +const CONVERSATION = model('CONVERSATION', ConversationSchema); + +module.exports = { + ConversationSchema: ConversationSchema, + CONVERSATION: CONVERSATION +}; \ No newline at end of file diff --git a/src/models/post.js b/src/models/post.js index 568ea94..487375a 100644 --- a/src/models/post.js +++ b/src/models/post.js @@ -1,5 +1,5 @@ const { Schema, model } = require('mongoose'); -//just testing pull requests + const PostSchema = new Schema({ title_id: String, screen_name: String, @@ -23,8 +23,8 @@ const PostSchema = new Schema({ feeling_id: Number, id: String, is_autopost: { - type: Number, - default: 0 + type: Number, + default: 0 }, is_community_private_autopost: { type: Number, @@ -67,6 +67,10 @@ const PostSchema = new Schema({ parent: { type: String, default: null + }, + message_to_pid: { + type: String, + default: null } }); diff --git a/src/services/juxt-web/routes/console/messages.js b/src/services/juxt-web/routes/console/messages.js index 9927b57..9afc0aa 100644 --- a/src/services/juxt-web/routes/console/messages.js +++ b/src/services/juxt-web/routes/console/messages.js @@ -8,17 +8,19 @@ var router = express.Router(); router.get('/', async function (req, res) { let user = await database.getUserByPID(req.pid); + let conversations = await database.getConversations(user.pid) res.render(req.directory + '/messages.ejs', { moment: moment, user: user, + conversations: conversations, cdnURL: config.CDN_domain, lang: req.lang, mii_image_CDN: config.mii_image_CDN }); - user.notification_list.filter(noti => noti.read === false).forEach(function(notification) { + /*user.notification_list.filter(noti => noti.read === false).forEach(function(notification) { notification.read = true; }); - user.markModified('notification_list'); + user.markModified('notification_list');*/ user.save(); }); diff --git a/src/webfiles/portal/messages.ejs b/src/webfiles/portal/messages.ejs index 60cc29c..1953163 100644 --- a/src/webfiles/portal/messages.ejs +++ b/src/webfiles/portal/messages.ejs @@ -21,7 +21,26 @@
<%= lang.messages.coming_soon %>
+