Merge branch 'master' of git.rezo-rm.fr:BDEMetz/bde-liste

This commit is contained in:
johan 2022-12-20 22:00:45 +01:00
commit d6aa41af93
32 changed files with 382 additions and 107 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@ node_modules/
package-lock.json
prankdata.txt
activitydata.txt
treasuredata.txt
goldenusers.txt
ldap-conf.json

354
index.js
View file

@ -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';

View file

@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
static/img/icon/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View file

@ -5,15 +5,31 @@
<meta charset="utf-8"/>
<title>OSS 110'Metz</title>
<meta name="description" content="Le site web du BDE Metz pour 2025, fait avec beaucoup d'amour" />
<meta name="author" content="VP geeks aka le REZO (cf rezo-rm.fr pour plus de détail)" />
<meta name="keyword" content="caca" />
<link rel="icon" href="img/favicon.ico">
<link rel="stylesheet" href="css/main.css" />
</head>
<link rel="apple-touch-icon" sizes="57x57" href="img/icon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="img/icon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="img/icon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="img/icon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="img/icon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="img/icon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="img/icon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="img/icon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="img/icon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="img/icon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="img/icon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="img/icon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="img/icon/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ff6600">
<meta name="msapplication-TileImage" content="/img/iconms-icon-144x144.png">
<meta name="theme-color" content="#ff6600">
</head>
<body>
<div class="bg-full"></div>
<div class="container">
@ -95,10 +111,10 @@
Copyright © OSS 110'Metz
</footer>
</div>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script src="https://unpkg.com/typeit@8.7.0/dist/index.umd.js"></script>
<script src="js/main.js" defer></script>
<script src="js/anim.js" defer></script>
</body>
</html>
</html>

View file

@ -10,6 +10,11 @@ function show_page(id) {
$(window).on("load", function() {
/* Register the Service Worker */
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./js/sw.js');
}
/* load timer */
window.setInterval(function() {
var time = $("#timer").text();

40
static/manifest.json Normal file
View file

@ -0,0 +1,40 @@
{
"name": "OSS110METZ",
"short_name": "O1M",
"icons": [{
"src": "img/icon/android-icon-36x36.png",
"sizes": "36x36",
"type": "image\/png",
"density": "0.75"
}, {
"src": "img/icon/android-icon-48x48.png",
"sizes": "48x48",
"type": "image\/png",
"density": "1.0"
}, {
"src": "img/icon/android-icon-72x72.png",
"sizes": "72x72",
"type": "image\/png",
"density": "1.5"
}, {
"src": "img/icon/android-icon-96x96.png",
"sizes": "96x96",
"type": "image\/png",
"density": "2.0"
}, {
"src": "img/icon/android-icon-144x144.png",
"sizes": "144x144",
"type": "image\/png",
"density": "3.0"
}, {
"src": "img/icon/android-icon-192x192.png",
"sizes": "192x192",
"type": "image\/png",
"density": "4.0"
}],
"lang": "fr-FR",
"start_url": "/",
"display": "standalone",
"background_color": "black",
"theme_color": "black"
}

21
static/sw.js Normal file
View file

@ -0,0 +1,21 @@
var cacheName = 'o1m';
var filesToCache = [
'/',
'/index.html'
];
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(filesToCache);
})
);
});
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
});