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 @@ + + + + + Juxt Admin Panel + + + + +

Juxt Admin Panel - <%= user.user_id %>

+ +
+
+ +
+ +
+

Posts

+
+
+ + + diff --git a/src/views/admin_community.ejs b/src/views/admin_community.ejs new file mode 100644 index 0000000..66920da --- /dev/null +++ b/src/views/admin_community.ejs @@ -0,0 +1,132 @@ + + + + + Juxt Admin Panel + + + + +

Juxt Admin Panel - <%= user.user_id %>

+ +
+
+ +
+ +
+

<%= community.name %>

+
+ + + + + + + +
+ + +

<%= community.description %>

+
+ +
+ + + + + + + + +
+
+

Followers

+

<%= community.followers %>

+
+
+
+

Posts

+

<%=totalNumPosts%>

+
+
+
+

Tags

+

N/A

+
+
+
+
+ <% newPosts.forEach(function(post) { %> + + <%if(post.screenshot !== '' && post.painting === '' && post.url === '' && post.body === '') {%> +
+ +
+ <% } else if(post.painting !== '' && post.screenshot === '' && post.url === '') {%> +
+ +
+ <% } else if(post.url !== '' && post.screenshot === '' && post.painting === '' && post.body === '') {%> +
+ +
+ <% } else if(post.body !== '' && post.screenshot === '' && post.painting === '' && post.url === '') {%> +
+

<%= post.body %>

+
+ <% } else if(post.screenshot !== '' && post.body !== '' && post.painting === '' && post.url === '') {%> +
+ +
+

<%= post.body %>

+
+
+ <% } else if(post.screenshot !== '' && post.painting !== '' && post.url === '') {%> +
+ + +
+ <% } else if(post.url !== '' && post.body !== '' && post.screenshot === '' && post.painting === '') {%> +
+ +
+

<%= post.body %>

+
+
+ <% } else if(post.url !== '' && post.painting !== '' && post.screenshot === '' && post.body === '') {%> +
+ + +
+ <%}%> +
+
+ <% }); %> +
+
+
+ + + diff --git a/src/views/admin_discovery.ejs b/src/views/admin_discovery.ejs index f102601..55110c7 100644 --- a/src/views/admin_discovery.ejs +++ b/src/views/admin_discovery.ejs @@ -3,73 +3,18 @@ Juxt Admin Panel - + -

Juxt Admin Panel - <%= user.user_id %>

+

Juxt Admin Panel - <%= user.user_id %>

@@ -89,7 +34,9 @@ -
+ +
+
diff --git a/src/views/admin_edit_community.ejs b/src/views/admin_edit_community.ejs index e0a130e..f86f0a0 100644 --- a/src/views/admin_edit_community.ejs +++ b/src/views/admin_edit_community.ejs @@ -2,74 +2,19 @@ - Juxt Admin Panel - + Edit - <%= community.name %> + -

Juxt Admin Panel - <%= user.user_id %>

+

Juxt Admin Panel - <%= user.user_id %>

@@ -78,61 +23,138 @@

Update <%=community.name%>

-
-
+
+ +
+
+ + +
-
-
+
+ + +
-
-
+
+
+ + +
-
-
+
+ + +
-
-
+
+ + +
-
-

+
+ + +
+
+
+
- Browser Icon (512px x 512px)
-
-
+
+ +
+
+
+ Browser Icon (512px x 512px) + +
+
+ +
+
- 3DS Browser Banner
-
-
+
- Wii U Browser Banner (1498px x 328px)
-
-
+
+
+ 3DS Browser Banner + +
+
+ +
+
- Is Recommended? - checked <%}%>> - - checked <%}%>> -
+
- Has Shop Page? - checked <%}%>> - - checked <%}%>> -
+
+ Wii U Browser Banner (1498px x 328px) + + +
- Platform - checked <%}%>> - - checked <%}%>> - - checked <%}%>> -
+
- - +
+ Is Recommended? + checked <%}%>> + + checked <%}%>> + +
+ +
+ Has Shop Page? + checked <%}%>> + + checked <%}%>> + +
+ +
+ Platform + checked <%}%>> + + checked <%}%>> + + checked <%}%>> + +
+
+
+ +
+ +
+
+ + +
+ +
+
+ diff --git a/src/views/admin_home.ejs b/src/views/admin_home.ejs index 8ed0738..b9c1f63 100644 --- a/src/views/admin_home.ejs +++ b/src/views/admin_home.ejs @@ -3,73 +3,18 @@ Juxt Admin Panel - + -

Juxt Admin Panel - <%= user.user_id %>

+

Juxt Admin Panel - <%= user.user_id %>

diff --git a/src/views/admin_login.ejs b/src/views/admin_login.ejs index 4b3cbad..ffa0891 100644 --- a/src/views/admin_login.ejs +++ b/src/views/admin_login.ejs @@ -3,80 +3,7 @@ Juxt Admin Login - +