|
|
@ -8,10 +8,17 @@ if (!fs.existsSync(prankPath)) { |
|
|
fs.writeFileSync(prankPath, "{}"); |
|
|
fs.writeFileSync(prankPath, "{}"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var activityPath = "activitydata.txt"; |
|
|
|
|
|
if (!fs.existsSync(activityPath)) { |
|
|
|
|
|
fs.writeFileSync(activityPath, "{}"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let PrankData = JSON.parse(fs.readFileSync(prankPath)); |
|
|
let PrankData = JSON.parse(fs.readFileSync(prankPath)); |
|
|
|
|
|
let ActivityData = JSON.parse(fs.readFileSync(activityPath)); |
|
|
let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy", "remi", "pierre", "matmaz", "", "", ""]; |
|
|
let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy", "remi", "pierre", "matmaz", "", "", ""]; |
|
|
let UsersToken = {}; |
|
|
let UsersToken = {}; |
|
|
let TokenDurationSecond = 3600; |
|
|
let TokenDurationSecond = 3600; |
|
|
|
|
|
let MaxAmountCrepe = 10; |
|
|
|
|
|
|
|
|
var ldapConf = JSON.parse(fs.readFileSync("ldap-conf.json")); |
|
|
var ldapConf = JSON.parse(fs.readFileSync("ldap-conf.json")); |
|
|
var LDAP = new LdapAuth({ |
|
|
var LDAP = new LdapAuth({ |
|
|
@ -86,31 +93,56 @@ fastify.post('/addPrank', async (request, reply) => { |
|
|
let auth = checkAuthetification(content); |
|
|
let auth = checkAuthetification(content); |
|
|
if (auth.success) { |
|
|
if (auth.success) { |
|
|
if ("type" in content) { |
|
|
if ("type" in content) { |
|
|
|
|
|
let prankUid = makeid(16); |
|
|
|
|
|
if ("prankUid" in content) { |
|
|
|
|
|
let prankExists = checkPrank(content) |
|
|
|
|
|
if (prankExists.success) { |
|
|
|
|
|
if (PrankData[prankUid].state != "Pending") { |
|
|
|
|
|
return { |
|
|
|
|
|
success: false, |
|
|
|
|
|
why: "You cannot edit already accepted prank request" |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
prankUid = content.prankUid; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return prankExists; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
let note = ("note" in content) ? content.note : "N/A"; |
|
|
let note = ("note" in content) ? content.note : "N/A"; |
|
|
switch (content.type) { |
|
|
switch (content.type) { |
|
|
case "crêpe": |
|
|
case "crêpe": |
|
|
if ("where" in content |
|
|
if ("where" in content |
|
|
&& "amount" in content) { |
|
|
&& "amount" in content |
|
|
let prankUid = makeid(16); |
|
|
&& "supplement" in content) { |
|
|
PrankData[prankUid] = { |
|
|
if (amound < MaxAmountCrepe) { |
|
|
creator: content.uid, |
|
|
let prankUid = makeid(16); |
|
|
type: content.type, |
|
|
PrankData[prankUid] = { |
|
|
where: content.where, |
|
|
creator: content.uid, |
|
|
amount: content.amount, |
|
|
type: content.type, |
|
|
note: content.note, |
|
|
where: content.where, |
|
|
state: "Pending", |
|
|
amount: content.amount, |
|
|
manageBy: null |
|
|
supplement: content.supplement, |
|
|
} |
|
|
note: content.note, |
|
|
saveData(); |
|
|
state: "Pending", |
|
|
return { |
|
|
manageBy: null |
|
|
sucess: true, |
|
|
} |
|
|
uid: prankUid, |
|
|
saveData(prankPath, PrankData); |
|
|
newPrank: PrankData[prankUid] |
|
|
return { |
|
|
|
|
|
sucess: true, |
|
|
|
|
|
uid: prankUid, |
|
|
|
|
|
prank: PrankData[prankUid] |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return { |
|
|
|
|
|
success: false, |
|
|
|
|
|
why: "Too much" |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return { |
|
|
return { |
|
|
success: false, |
|
|
success: false, |
|
|
why: "Missing amount or where" |
|
|
why: "Missing amount, where or supplement" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
@ -127,11 +159,11 @@ fastify.post('/addPrank', async (request, reply) => { |
|
|
state: "Pending", |
|
|
state: "Pending", |
|
|
manageBy: null |
|
|
manageBy: null |
|
|
} |
|
|
} |
|
|
saveData(); |
|
|
saveData(prankPath, PrankData); |
|
|
return { |
|
|
return { |
|
|
sucess: true, |
|
|
sucess: true, |
|
|
uid: prankUid, |
|
|
uid: prankUid, |
|
|
newPrank: PrankData[prankUid] |
|
|
prank: PrankData[prankUid] |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return { |
|
|
return { |
|
|
@ -230,14 +262,85 @@ fastify.post('/refusePrank', async (request, reply) => { |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
fastify.post('/getPrank', async (request, reply) => { |
|
|
fastify.post('/get', async (request, reply) => { |
|
|
let content = request.body; |
|
|
let content = request.body; |
|
|
let auth = checkAuthetification(content); |
|
|
let auth = checkAuthetification(content); |
|
|
if (auth.success) { |
|
|
if (auth.success) { |
|
|
if (AdminUsersUid.includes(content.uid)) { |
|
|
if ("type" in content) { |
|
|
|
|
|
switch (content.type) { |
|
|
|
|
|
case "prank": |
|
|
|
|
|
if (AdminUsersUid.includes(content.uid)) { |
|
|
|
|
|
return { |
|
|
|
|
|
sucess: true, |
|
|
|
|
|
prankData: PrankData |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return { |
|
|
|
|
|
success: false, |
|
|
|
|
|
why: "Not Allowed" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case "activity": |
|
|
|
|
|
return { |
|
|
|
|
|
sucess: true, |
|
|
|
|
|
prankData: ActivityData |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
return { |
|
|
|
|
|
success: false, |
|
|
|
|
|
why: "Unknown type" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
return { |
|
|
return { |
|
|
sucess: true, |
|
|
success: false, |
|
|
prankData: PrankData |
|
|
why: "Missing type" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return auth |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
fastify.post('/addActivity', async (request, reply) => { |
|
|
|
|
|
let content = request.body; |
|
|
|
|
|
let auth = checkAuthetification(content); |
|
|
|
|
|
if (auth.success) { |
|
|
|
|
|
if (AdminUsersUid.includes(content.uid)) { |
|
|
|
|
|
if ("title" in content |
|
|
|
|
|
&& "desc" in content |
|
|
|
|
|
&& "start" in content |
|
|
|
|
|
&& "end" in content |
|
|
|
|
|
&& "where" in content) { |
|
|
|
|
|
let activityUid = makeid(16); |
|
|
|
|
|
if ("activityUid" in content) { |
|
|
|
|
|
let activityExists = checkActivity(content) |
|
|
|
|
|
if (activityExists.success) { |
|
|
|
|
|
activityUid = content.activityUid; |
|
|
|
|
|
} else { |
|
|
|
|
|
return activityExists; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
ActivityData[activityUid] = { |
|
|
|
|
|
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: "Missing title, desc, start, end or where" |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return { |
|
|
return { |
|
|
@ -245,14 +348,34 @@ fastify.post('/getPrank', async (request, reply) => { |
|
|
why: "Not Allowed" |
|
|
why: "Not Allowed" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
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" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return auth |
|
|
return auth |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function saveData() { |
|
|
function saveData(path, data) { |
|
|
fs.writeFileSync(prankPath, JSON.stringify(PrankData)); |
|
|
fs.writeFileSync(path, JSON.stringify(data)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function authenticate(user, pwd) { |
|
|
function authenticate(user, pwd) { |
|
|
@ -318,6 +441,26 @@ function checkPrank(content) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 checkManagePrank(content) { |
|
|
let auth = checkAuthetification(content); |
|
|
let auth = checkAuthetification(content); |
|
|
if (auth.success) { |
|
|
if (auth.success) { |
|
|
|