From 511ba42b463891903b04146fb7b9a992ea4f825e Mon Sep 17 00:00:00 2001 From: CaramelKat <32065563+caramelkat@users.noreply.github.com> Date: Mon, 25 Jan 2021 11:05:37 -0600 Subject: [PATCH] Redesign of Admin page. Fixed bug with community id's being rounded down. Added Google Analytics disclaimer to first run setup --- src/database.js | 2 +- src/models/communities.js | 1 + src/services/juxt-web/routes/admin/api.js | 37 +++ .../juxt-web/routes/portal/communities.js | 8 +- src/views/admin_audit.ejs | 29 +++ src/views/admin_community.ejs | 132 +++++++++++ src/views/admin_discovery.ejs | 65 +----- src/views/admin_edit_community.ejs | 220 ++++++++++-------- src/views/admin_home.ejs | 61 +---- src/views/admin_login.ejs | 75 +----- src/views/admin_new_community.ejs | 201 ++++++++-------- src/views/admin_posts.ejs | 84 ------- src/views/portal_communities.ejs | 4 +- src/views/portal_communities_ajax.ejs | 4 +- src/views/portal_community.ejs | 110 ++++----- src/views/portal_community_ajax.ejs | 8 +- src/views/portal_first_run.ejs | 9 +- src/views/portal_guest_notice.ejs | 31 ++- src/webfiles/portal/css/juxt.css | 1 - 19 files changed, 514 insertions(+), 568 deletions(-) create mode 100644 src/views/admin_audit.ejs create mode 100644 src/views/admin_community.ejs delete mode 100644 src/views/admin_posts.ejs diff --git a/src/database.js b/src/database.js index 5fec65f..8eb0ef7 100644 --- a/src/database.js +++ b/src/database.js @@ -138,7 +138,7 @@ async function getPostsByCommunityKey(community, numberOfPosts, search_key) { async function getNewPostsByCommunity(community, numberOfPosts) { verifyConnected(); return POST.find({ - title_id: community.title_id + title_id: community.title_ids }).sort({ created_at: -1 }).limit(numberOfPosts); } diff --git a/src/models/communities.js b/src/models/communities.js index 136a0c4..f503b11 100644 --- a/src/models/communities.js +++ b/src/models/communities.js @@ -3,6 +3,7 @@ const { Schema, model } = require('mongoose'); const CommunitySchema = new Schema({ created_at: { type: Date, + default: new Date(), }, empathy_count: { type: Number, diff --git a/src/services/juxt-web/routes/admin/api.js b/src/services/juxt-web/routes/admin/api.js index 362e68f..4d3a5e1 100644 --- a/src/services/juxt-web/routes/admin/api.js +++ b/src/services/juxt-web/routes/admin/api.js @@ -78,6 +78,43 @@ router.get('/communities/:communityID', function (req, res) { }); }); +router.get('/communities/:communityID/delete', function (req, res) { + database.connect().then(async e => { + //let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); + if(req.cookies.token === null) + throw new Error('No service token supplied'); + + let pid = util.data.processServiceToken(req.cookies.token); + + if(pid === null) + throw new Error('Invalid credentials supplied'); + + let user = await database.getUserByPID(pid); + + if(user !== null) + { + if(config.authorized_PNIDs.indexOf(user.pid) === -1) + throw new Error('Invalid credentials supplied'); + + let community = await database.getCommunityByID(req.params.communityID); + community.delete().then(err => function () { + res.send(err); + }); + } + else + throw new Error('Invalid account ID or password'); + + }).catch(error => + { + res.statusCode = 400; + let response = { + error_code: 400, + message: error.message + }; + res.send(response); + }); +}); + router.post('/communities/:communityID/update', upload.fields([{name: 'browserIcon', maxCount: 1}, { name: 'CTRbrowserHeader', maxCount: 1}, { name: 'WiiUbrowserHeader', maxCount: 1}]), function (req, res) { database.connect().then(async e => { //let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); diff --git a/src/services/juxt-web/routes/portal/communities.js b/src/services/juxt-web/routes/portal/communities.js index 749ceb9..838a0ab 100644 --- a/src/services/juxt-web/routes/portal/communities.js +++ b/src/services/juxt-web/routes/portal/communities.js @@ -44,18 +44,16 @@ router.get('/', function (req, res) { }); }); -router.get('/*/new', function (req, res) { +router.get('/:communityID/new', function (req, res) { res.header('X-Nintendo-WhiteList','1|http,youtube.com,,2|https,youtube.com,,2|http,.youtube.com,,2|https,.youtube.com,,2|http,.ytimg.com,,2|https,.ytimg.com,,2|http,.googlevideo.com,,2|https,.googlevideo.com,,2|https,youtube.com,/embed/,6|https,youtube.com,/e/,6|https,youtube.com,/v/,6|https,www.youtube.com,/embed/,6|https,www.youtube.com,/e/,6|https,www.youtube.com,/v/,6|https,youtube.googleapis.com,/e/,6|https,youtube.googleapis.com,/v/,6|http,maps.googleapis.com,/maps/api/streetview,2|https,maps.googleapis.com,/maps/api/streetview,2|http,cbk0.google.com,/cbk,2|https,cbk0.google.com,/cbk,2|http,cbk1.google.com,/cbk,2|https,cbk1.google.com,/cbk,2|http,cbk2.google.com,/cbk,2|https,cbk2.google.com,/cbk,2|http,cbk3.google.com,/cbk,2|https,cbk3.google.com,/cbk,2|https,.cloudfront.net,,2|https,www.google-analytics.com,/,2|https,stats.g.doubleclick.net,,2|https,www.google.com,/ads/,2|https,ssl.google-analytics.com,,2|http,fonts.googleapis.com,,2|fonts.googleapis.com,,2|https,www.googletagmanager.com,,2'); - let community_id = req.originalUrl.replace('/communities/', '').replace('/new','').trim(); var isAJAX = ((req.query.ajax+'').toLowerCase() === 'true') - if(isAJAX) - community_id = community_id.substring(0, community_id.indexOf('?')); database.connect().then(async e => { let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]); if(pid === null) pid = 1000000000; let user = await database.getUserByPID(pid); - let community = await database.getCommunityByID(community_id.substring(0, community_id)); + console.log(req.params.communityID) + let community = await database.getCommunityByID(req.params.communityID.toString()); let newPosts = await database.getNewPostsByCommunity(community, 100); let totalNumPosts = await database.getTotalPostsByCommunity(community); if(isAJAX) { diff --git a/src/views/admin_audit.ejs b/src/views/admin_audit.ejs new file mode 100644 index 0000000..0395b8e --- /dev/null +++ b/src/views/admin_audit.ejs @@ -0,0 +1,29 @@ + + +
+ +|
+ |
+
+ <%= community.description %>+ |
+
|
+
+
+ Followers+<%= community.followers %>+ |
+
+
+
+ Posts+<%=totalNumPosts%>+ |
+
+
+
+ Tags+N/A+ |
+
- Recent posts- |
-
- Popular posts- |
-
- Verified posts- |
-
+ Recent posts+ |
+
+ Popular posts+ |
+
+ Verified posts+ |
+
- By using the console's Parental Controls feature, parents and guardians - can restrict the extent to which children can use Juxt. + Juxtaposition uses Google Analytics in order to track how users are using our service. The data collected + includes but is not limited to time of visit, pages visited, and time spent on the site. This data is + not attached to you in any way, and is not used for advertisements by us or Google.
+ Juxtaposition uses Google Analytics in order to track how users are using our service. The data collected + includes but is not limited to time of visit, pages visited, and time spent on the site. This data is + not attached to you in any way, and is not used for advertisements by us or Google. +
+