diff --git a/.gitignore b/.gitignore index 4c36317..8b2611b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ node_modules/ package-lock.json prankdata.txt activitydata.txt +treasuredata.txt +goldenusers.txt ldap-conf.json diff --git a/index.js b/index.js index 56d59f6..f4e368b 100644 --- a/index.js +++ b/index.js @@ -4,17 +4,16 @@ const path = require('path') var LdapAuth = require('ldapauth-fork'); var prankPath = "prankdata.txt"; -if (!fs.existsSync(prankPath)) { - fs.writeFileSync(prankPath, "{}"); -} - var activityPath = "activitydata.txt"; -if (!fs.existsSync(activityPath)) { - fs.writeFileSync(activityPath, "{}"); -} +var treasurePath = "treasuredata.txt"; +var goldenUsersPath = "goldenusers.txt"; + +initFs(); let PrankData = JSON.parse(fs.readFileSync(prankPath)); let ActivityData = JSON.parse(fs.readFileSync(activityPath)); +let TreasureData = JSON.parse(fs.readFileSync(treasurePath)); +let GoldenUsers = JSON.parse(fs.readFileSync(goldenUsersPath)); let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy", "remi", "pierre", "matmaz", "", "", ""]; let UsersToken = {}; let TokenDurationSecond = 3600; @@ -96,7 +95,7 @@ fastify.post('/addPrank', async (request, reply) => { if ("type" in content) { let prankUid = makeid(16); if ("prankUid" in content) { - let prankExists = checkPrank(content) + let prankExists = check(content, "prankUid", PrankData) if (prankExists.success) { if (PrankData[prankUid].state != "Pending") { return { @@ -209,17 +208,19 @@ fastify.post('/delPrank', async (request, reply) => { let content = request.body; let auth = checkAuthetification(content); if (auth.success) { - let prankExists = checkPrank(content) + let prankExists = check(content, "prankUid", PrankData) if (prankExists.success) { - if (PrankData[content.prankUid].creator === content.uid) { + if (PrankData[content.prankUid].creator === content.uid + && PrankData[content.prankUid].state === "Pending") { delete PrankData[content.prankUid]; + saveData(prankPath, PrankData); return { success: true, } } else { return { success: false, - why: "Not allowed" + why: "You can't delete prank that aren't yours or those already Accepted or Refused" } } } else { @@ -232,10 +233,11 @@ fastify.post('/delPrank', async (request, reply) => { fastify.post('/acceptPrank', async (request, reply) => { let content = request.body; - let prankExists = checkManagePrank(content) + let prankExists = checkManage(content, "prankUid", PrankData) if (prankExists.success) { PrankData[content.prankUid].state = "Accepted"; PrankData[content.prankUid].manageBy = content.uid; + saveData(prankPath, PrankData); return { success: true, } @@ -246,10 +248,11 @@ fastify.post('/acceptPrank', async (request, reply) => { fastify.post('/donePrank', async (request, reply) => { let content = request.body; - let prankExists = checkManagePrank(content) + let prankExists = checkManage(content, "prankUid", PrankData) if (prankExists.success) { if (PrankData[content.prankUid].manageBy == content.uid) { PrankData[content.prankUid].state = "Done"; + saveData(prankPath, PrankData); return { success: true, } @@ -266,10 +269,11 @@ fastify.post('/donePrank', async (request, reply) => { fastify.post('/refusePrank', async (request, reply) => { let content = request.body; - let prankExists = checkManagePrank(content) + let prankExists = checkManage(content, "prankUid", PrankData) if (prankExists.success) { PrankData[content.prankUid].state = "Refused"; PrankData[content.prankUid].manageBy = content.uid; + saveData(prankPath, PrankData); return { success: true, } @@ -291,9 +295,15 @@ fastify.post('/get', async (request, reply) => { prankData: PrankData } } else { + let prankData = {}; + for (prank in PrankData) { + if (PrankData[prank].creator == content.uid) { + prankData[prank] = PrankData[prank]; + } + } return { - success: false, - why: "Not Allowed" + success: true, + prankData: prankData } } break; @@ -303,6 +313,25 @@ fastify.post('/get', async (request, reply) => { activityData: ActivityData } break; + case "treasure": + if (AdminUsersUid.includes(content.uid)) { + return { + sucess: true, + prankData: TreasureData + } + } else { + let treasureData = {}; + for (treasure in TreasureData) { + if (TreasureData[treasure].creator == content.uid) { + treasureData[treasure] = TreasureData[treasure]; + } + } + return { + success: true, + treasureData: treasureData + } + } + break; default: return { success: false, @@ -329,37 +358,61 @@ fastify.post('/addActivity', async (request, reply) => { && "title" in content && "desc" in content && "start" in content - && "end" in content && "where" in content) { - if (["event", "treasure"].contains(content.type)) { - let activityUid = makeid(16); - if ("activityUid" in content) { - let activityExists = checkActivity(content) - if (activityExists.success) { - activityUid = content.activityUid; + let activityUid = makeid(16); + if ("activityUid" in content) { + let activityExists = check(content, "activityUid", ActivityData) + if (activityExists.success) { + activityUid = content.activityUid; + } else { + return activityExists; + } + } + switch (content.type) { + case "event": + if ("end" in content) { + ActivityData[activityUid] = { + type: content.type, + title: content.title, + desc: content.desc, + start: content.start, + end: content.end, + where: content.where, + } + saveData(activityPath, ActivityData); + return { + sucess: true, + uid: activityUid, + activity: ActivityData[activityUid] + } } else { - return activityExists; + return { + success: false, + why: "Missing end" + } + } + break; + case "treasure": + ActivityData[activityUid] = { + type: content.type, + title: content.title, + desc: content.desc, + start: content.start, + where: content.where, + treasureState: "Pending" + } + saveData(activityPath, ActivityData); + return { + sucess: true, + uid: activityUid, + activity: ActivityData[activityUid] + } + break; + default: + return { + success: false, + why: "Unkonw type" } - } - ActivityData[activityUid] = { - type: content.type, - title: content.title, - desc: content.desc, - start: content.start, - end: content.end, - where: content.where - } - saveData(activityPath, ActivityData); - return { - sucess: true, - uid: activityUid, - activity: ActivityData[activityUid] - } - } else { - return { - success: false, - why: "Unkonw type" - } } } else { return { @@ -378,23 +431,15 @@ fastify.post('/addActivity', async (request, reply) => { fastify.post('/delActivity', async (request, reply) => { let content = request.body; - let auth = checkAuthetification(content); - if (auth.success) { - if (AdminUsersUid.includes(content.uid)) { - let activityExists = checkActivity(content) - if (activityExists.success) { - delete ActivityData[content.activityUid] - } else { - return activityExists - } - } else { - return { - success: false, - why: "Not allowed" - } + let activityExists = checkManage(content, "activityUid", ActivityData) + if (activityExists.success) { + delete ActivityData[content.activityUid] + saveData(activityPath, ActivityData); + return { + success: true, } } else { - return auth + return activityExists } }) @@ -402,9 +447,56 @@ fastify.post('/sendTreasure', async (request, reply) => { let content = request.body; let auth = checkAuthetification(content); if (auth.success) { - let activityExists = checkActivity(content) + let activityExists = check(content, "activityUid", ActivityData) if (activityExists.success) { - + if ("image" in content + && "desc" in content + && "activityUid" in content) { + let treasureUid = makeid(16); + if ("treasureUid" in content) { + let treasureExists = check(content, "activityUid", ActivityData) + if (treasureExists.success) { + if (treasureData[treasureUid].state != "Pending" + && treasureData[treasureUid].creator == content.uid) { + return { + success: false, + why: "You cannot edit already accepted or refused treasure request, or request form other people" + } + } else { + treasureUid = content.prankUid; + } + } else { + return treasureExists; + } + } + let activityExists = check(content, "activityUid", ActivityData) + if (activityExists.success) { + if (ActivityData[content.activityUid].type == "treasure") { + let imageUid = makeid(128); + fs.writeFileSync("static/images/"+imageUid, content.image); + TreasureData[treasureUid] = { + creator: content.uid, + image: imageUid, + desc: content.desc, + activity: content.activityUid, + state: "Pending" + } + saveData(treasurePath, TreasureData); + } else { + return { + success: false, + why: "The given activityUid refers to an event and not a treasure quest" + } + } + } else { + return activityExists + } + } else { + return { + success: false, + why: "Missing image, desc or activityUid" + } + } } else { return activityExists } @@ -413,6 +505,88 @@ fastify.post('/sendTreasure', async (request, reply) => { } }) +fastify.post('/delTreasure', async (request, reply) => { + let content = request.body; + let auth = checkAuthetification(content); + if (auth.success) { + let treasureExists = check(content, "treasureUid", TreasureData) + if (treasureExists.success) { + if (TreasureData[content.treasureUid].creator === content.uid + && TreasureData[content.treasureUid].state == "Pending") { + delete TreasureData[content.treasureUid]; + saveData(treasurePath, TreasureData); + return { + success: true, + } + } else { + return { + success: false, + why: "You can't delete treasure that aren't yours or those already Accepted or Refused" + } + } + } else { + return treasureExists + } + } else { + return auth + } +}) + +fastify.post('/acceptTreasure', async (request, reply) => { + let content = request.body; + let treasureExists = checkManage(content, "treasureUid", TreasureData); + if (treasureExists.success) { + TreasureData[content.treasureUid].state = "Accepted"; + saveData(treasurePath, TreasureData); + ActivityData[GoldenUsers[activityUid].activityUid].treasureState = "Accepted"; + saveData(activityPath, ActivityData); + GoldenUsers[TreasureData[content.treasureUid].activityUid] = { + userUid: TreasureData[content.treasureUid].creator, + activityUid: TreasureData[content.treasureUid].activityUid + } + saveData(goldenUsersPath, GoldenUsers); + return { + success: true, + } + } else { + return treasureExists + } +}) + +fastify.post('/refuseTreasure', async (request, reply) => { + let content = request.body; + let treasureExists = checkManage(content, "treasureUid", TreasureData); + if (treasureExists.success) { + TreasureData[content.treasureUid].state = "Refused"; + saveData(treasurePath, TreasureData); + return { + success: true, + } + } else { + return treasureExists + } +}) + +fastify.post('/isGolden', async (request, reply) => { + let content = request.body; + let auth = checkAuthetification(content); + if (auth.success) { + for (activityUid in GoldenUsers) { + if (GoldenUsers[activityUid].userUid === content.uid) { + return { + success: true, + userUid: content.uid, + activity: ActivityData[GoldenUsers[activityUid].activityUid] + } + } + } + return { + sucess: false + } + } else { + return auth + } +}) function saveData(path, data) { fs.writeFileSync(path, JSON.stringify(data)); @@ -458,60 +632,45 @@ function checkAuthetification(content) { why: "Not authentificated" } } + } else { + return { + success: false, + why: "Missing uid or token" + } } } -function checkPrank(content) { - if ("prankUid" in content) { - if (content.prankUid in PrankData) { +function check(content, input, data) { + if (input in content) { + if (content[input] in data) { return { success: true, } } else { return { success: false, - why: "Unknow prankUid" + why: "Unknow "+input } } } else { return { success: false, - why: "Missing prankUid" + why: "Missing "+input } } } -function checkActivity(content) { - if ("activityUid" in content) { - if (content.activityUid in ActivityData) { - return { - success: true, - } - } else { - return { - success: false, - why: "Unknow activityUid" - } - } - } else { - return { - success: false, - why: "Missing activityUid" - } - } -} - -function checkManagePrank(content) { +function checkManage(content, input, data) { let auth = checkAuthetification(content); if (auth.success) { if (AdminUsersUid.includes(content.uid)) { - let prankExists = checkPrank(content) - if (prankExists.success) { + let exists = check(content, input, data) + if (exists.success) { return { success: true } } else { - return prankExists + return exists } } else { return { @@ -524,6 +683,21 @@ function checkManagePrank(content) { } } +function initFs() { + if (!fs.existsSync(prankPath)) { + fs.writeFileSync(prankPath, "{}"); + } + if (!fs.existsSync(activityPath)) { + fs.writeFileSync(activityPath, "{}"); + } + if (!fs.existsSync(treasurePath)) { + fs.writeFileSync(treasurePath, "{}"); + } + if (!fs.existsSync(goldenUsersPath)) { + fs.writeFileSync(goldenUsersPath, "{}"); + } +} + function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; diff --git a/static/css/main.css b/static/css/main.css index c95ca8d..6ffc3a5 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,4 +1,4 @@ - @import url('https://fonts.cdnfonts.com/css/modern-typewriter'); +@import url('https://fonts.cdnfonts.com/css/modern-typewriter'); * { box-sizing: border-box; @@ -63,7 +63,8 @@ h1 { } .logo>img { - height: 9vw; + height: 220px; + margin-left: 3vw; } .row { @@ -94,7 +95,7 @@ p { a { text-decoration: none; - color: #d75b00; + color: #d75b00; } @@ -169,9 +170,31 @@ img { padding-left: 5vw; } -@media screen and (max-width: 800px) { +.activite-temps { + font-size: 40px; + color: red; + text-align: center; +} + +@media screen and (max-width: 600px) { + .bg-full { + display: none; + } + .container { + margin: 0px; + width: 100%; + border-radius: 0px; + box-shadow: none; + } + body { + margin: 0px; + } + .logo>img { + height: 150px; + margin-left: calc(50% - 75px); + } .row { - flex-direction: column; + flex-direction: column; } .col { @@ -187,9 +210,3 @@ img { font-size: 40px; } } - -.activite-temps { - font-size: 40px; - color: red; - text-align: center; -} \ No newline at end of file diff --git a/static/img/icon/android-icon-144x144.png b/static/img/icon/android-icon-144x144.png new file mode 100644 index 0000000..a1a7d28 Binary files /dev/null and b/static/img/icon/android-icon-144x144.png differ diff --git a/static/img/icon/android-icon-192x192.png b/static/img/icon/android-icon-192x192.png new file mode 100644 index 0000000..6519844 Binary files /dev/null and b/static/img/icon/android-icon-192x192.png differ diff --git a/static/img/icon/android-icon-36x36.png b/static/img/icon/android-icon-36x36.png new file mode 100644 index 0000000..dee1685 Binary files /dev/null and b/static/img/icon/android-icon-36x36.png differ diff --git a/static/img/icon/android-icon-48x48.png b/static/img/icon/android-icon-48x48.png new file mode 100644 index 0000000..6d72ceb Binary files /dev/null and b/static/img/icon/android-icon-48x48.png differ diff --git a/static/img/icon/android-icon-72x72.png b/static/img/icon/android-icon-72x72.png new file mode 100644 index 0000000..895a5cb Binary files /dev/null and b/static/img/icon/android-icon-72x72.png differ diff --git a/static/img/icon/android-icon-96x96.png b/static/img/icon/android-icon-96x96.png new file mode 100644 index 0000000..fd954d8 Binary files /dev/null and b/static/img/icon/android-icon-96x96.png differ diff --git a/static/img/icon/apple-icon-114x114.png b/static/img/icon/apple-icon-114x114.png new file mode 100644 index 0000000..7e27c80 Binary files /dev/null and b/static/img/icon/apple-icon-114x114.png differ diff --git a/static/img/icon/apple-icon-120x120.png b/static/img/icon/apple-icon-120x120.png new file mode 100644 index 0000000..44e3051 Binary files /dev/null and b/static/img/icon/apple-icon-120x120.png differ diff --git a/static/img/icon/apple-icon-144x144.png b/static/img/icon/apple-icon-144x144.png new file mode 100644 index 0000000..a1a7d28 Binary files /dev/null and b/static/img/icon/apple-icon-144x144.png differ diff --git a/static/img/icon/apple-icon-152x152.png b/static/img/icon/apple-icon-152x152.png new file mode 100644 index 0000000..9057e04 Binary files /dev/null and b/static/img/icon/apple-icon-152x152.png differ diff --git a/static/img/icon/apple-icon-180x180.png b/static/img/icon/apple-icon-180x180.png new file mode 100644 index 0000000..0f9a41a Binary files /dev/null and b/static/img/icon/apple-icon-180x180.png differ diff --git a/static/img/icon/apple-icon-57x57.png b/static/img/icon/apple-icon-57x57.png new file mode 100644 index 0000000..e2e0985 Binary files /dev/null and b/static/img/icon/apple-icon-57x57.png differ diff --git a/static/img/icon/apple-icon-60x60.png b/static/img/icon/apple-icon-60x60.png new file mode 100644 index 0000000..046759b Binary files /dev/null and b/static/img/icon/apple-icon-60x60.png differ diff --git a/static/img/icon/apple-icon-72x72.png b/static/img/icon/apple-icon-72x72.png new file mode 100644 index 0000000..895a5cb Binary files /dev/null and b/static/img/icon/apple-icon-72x72.png differ diff --git a/static/img/icon/apple-icon-76x76.png b/static/img/icon/apple-icon-76x76.png new file mode 100644 index 0000000..2f4fdc4 Binary files /dev/null and b/static/img/icon/apple-icon-76x76.png differ diff --git a/static/img/icon/apple-icon-precomposed.png b/static/img/icon/apple-icon-precomposed.png new file mode 100644 index 0000000..4092aae Binary files /dev/null and b/static/img/icon/apple-icon-precomposed.png differ diff --git a/static/img/icon/apple-icon.png b/static/img/icon/apple-icon.png new file mode 100644 index 0000000..4092aae Binary files /dev/null and b/static/img/icon/apple-icon.png differ diff --git a/static/img/icon/favicon-16x16.png b/static/img/icon/favicon-16x16.png new file mode 100644 index 0000000..a962911 Binary files /dev/null and b/static/img/icon/favicon-16x16.png differ diff --git a/static/img/icon/favicon-32x32.png b/static/img/icon/favicon-32x32.png new file mode 100644 index 0000000..f3f835d Binary files /dev/null and b/static/img/icon/favicon-32x32.png differ diff --git a/static/img/icon/favicon-96x96.png b/static/img/icon/favicon-96x96.png new file mode 100644 index 0000000..fd954d8 Binary files /dev/null and b/static/img/icon/favicon-96x96.png differ diff --git a/static/img/icon/favicon.ico b/static/img/icon/favicon.ico new file mode 100644 index 0000000..310fe28 Binary files /dev/null and b/static/img/icon/favicon.ico differ diff --git a/static/img/icon/ms-icon-144x144.png b/static/img/icon/ms-icon-144x144.png new file mode 100644 index 0000000..a1a7d28 Binary files /dev/null and b/static/img/icon/ms-icon-144x144.png differ diff --git a/static/img/icon/ms-icon-150x150.png b/static/img/icon/ms-icon-150x150.png new file mode 100644 index 0000000..5cebc01 Binary files /dev/null and b/static/img/icon/ms-icon-150x150.png differ diff --git a/static/img/icon/ms-icon-310x310.png b/static/img/icon/ms-icon-310x310.png new file mode 100644 index 0000000..aaf0bd6 Binary files /dev/null and b/static/img/icon/ms-icon-310x310.png differ diff --git a/static/img/icon/ms-icon-70x70.png b/static/img/icon/ms-icon-70x70.png new file mode 100644 index 0000000..8f8aea2 Binary files /dev/null and b/static/img/icon/ms-icon-70x70.png differ diff --git a/static/index.html b/static/index.html index 16a7a32..9dbbb1a 100644 --- a/static/index.html +++ b/static/index.html @@ -5,15 +5,31 @@