mirror of
https://github.com/PretendoNetwork/juxtaposition-ui.git
synced 2026-09-09 09:55:33 -05:00
Actually fixed Access Token decryption
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
32
src/models/conversation.js
Normal file
32
src/models/conversation.js
Normal file
@@ -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
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
@@ -21,7 +21,26 @@
|
||||
<div id="main">
|
||||
<h1 id="title" class="page-header"><%= lang.global.messages %></h1>
|
||||
<div class="community-page-posts-wrapper">
|
||||
<p class="no-posts-text"><%= lang.messages.coming_soon %></p>
|
||||
<table cellspacing="0">
|
||||
<tbody id="messages-list">
|
||||
<tr class="message-wrapper" onclick="showMessage(' + notificationObj.messages[i].id + ')">
|
||||
<td class="messages-unread-badge-wrapper">
|
||||
<div class="unread-badge"></div>
|
||||
</td>
|
||||
<td>
|
||||
<%if(true) {%>
|
||||
<img class="community-page-post-user-icon verified" >
|
||||
<span class="community-page-verified-user-badge community-page-verified" style=""></span>
|
||||
<%} else {%>
|
||||
<img class="community-page-post-user-icon" >
|
||||
<span class="community-page-verified-user-badge community-page-verified" style="display: none;"></span>
|
||||
<%}%>
|
||||
<h2 class="community-page-post-username" >UserName</h2>
|
||||
<h4 class="community-page-post-time-stamp"><%= moment(new Date()).fromNow() %></h4>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<img src="" onerror="wiiuBrowser.showLoadingIcon(!1);window.scroll(0, 0);">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user