Compare commits

..

No commits in common. "3c9d92a497bc7ef0b78c1e766498bcc354718ff7" and "1cf5b5a089767502435f24606581a7618f064115" have entirely different histories.

16 changed files with 41 additions and 283 deletions

View File

@ -3,7 +3,7 @@ import { navbar } from '../../utils/navbar.js';
function generateCallHTML(phoneNumber, name, callcount, session) {
const head = `<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><link rel="stylesheet" type="text/css" href="/assets/css/form.css" /><title>AutoCallMenu</title></head>`;
const form = `
<form action="javascript:callFromForm()" id="callForm">
<form action="/api/contacts/call" method="post">
<input type="hidden" name="phone" value="${phoneNumber}">
<label class="switch">
<input type="checkbox" name="vote">
@ -14,31 +14,8 @@ function generateCallHTML(phoneNumber, name, callcount, session) {
<button class="submit" type="submit">CONFIRMER</button>
</form>
`;
const body = `<body>${js}${navbar(session)}<h1>Bienvenue :3</h1><h2>Appel: ${name} - ${phoneNumber}</h2><p>${callcount} appels restants</p>${form}</body>`;
const body = `<body>${navbar(session)}<h1>Bienvenue :3</h1><h2>Appel: ${name} - ${phoneNumber}</h2><p>${callcount} appels restants</p>${form}</body>`;
return `<!DOCTYPE html><html>${head}${body}</html>`;
}
const js = '\
<script>\
function callFromForm() {\
const form = document.getElementById("callForm");\
fetch(`/api/call/${form.phone.value}`, {\
method: "POST",\
body: JSON.stringify({\
vote: form.vote.value == "on" ? 1 : 0,\
}),\
headers: {\
"Content-type": "application/json; charset=UTF-8"\
}\
})\
.then(async (response) => {\
const res = await response.json();\
console.log(res);\
if(!response.ok) return alert(res.message);\
location.reload();\
});\
}\
</script>\
';
export { generateCallHTML };

View File

@ -0,0 +1,22 @@
import { permissionBits } from "../../../../utils/permissions.js";
export default {
path: "/api/contacts(/*)?",
requiresLogin: true,
permissions: permissionBits.CALL,
type: "post",
async execute(request, response) {
const phone = request.originalUrl.split("/")[3];
const operation = request.originalUrl.split("/")[4];
switch(operation) {
case 'call':
global.events.submitEvent.emit("contacts/call", request.body);
response.redirect("/calls");
break
case 'add':
global.events.submitEvent.emit("contacts/add", request.body);
//response.redirect("/");
break
}
},
};

View File

@ -1,14 +0,0 @@
import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/call/:phone",
requiresLogin: true,
permissions: permissionBits.ADMIN,
type: "post",
async execute(request, response) {
const { phone } = request.params;
const { vote } = request.body;
await global.database.contacts.update({ called: 1, vote: vote }, { where: { phone: phone } });
response.status(201).send({ message: `Vote registered` });
},
};

View File

@ -1,26 +0,0 @@
import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/contacts/:phone",
requiresLogin: true,
permissions: permissionBits.ADMIN,
type: "post",
async execute(request, response) {
const { phone } = request.params;
const { firstName, lastName } = request.body;
if (
await global.database.contacts.findOne({
where: { phone: phone },
})
) return response.status(409).send({ message: "Contact already exists" });
const contactParams = {
phone: phone,
firstName: firstName,
lastName: lastName,
};
console.log(`Creating contact ${phone}`);
console.log(contactParams);
await global.database.contacts.create(contactParams);
response.status(201).send(contactParams);
},
};

View File

@ -1,4 +1,4 @@
import { permissionBits } from "../../../../../utils/permissions.js";
import { permissionBits } from "../../../../utils/permissions.js";
export default {
path: "/api/users/:username",

View File

@ -1,4 +1,4 @@
import { permissionBits } from "../../../../../utils/permissions.js";
import { permissionBits } from "../../../../utils/permissions.js";
export default {
path: "/api/users/:username",
@ -12,7 +12,7 @@ export default {
await global.database.users.findOne({
where: { username: username },
})
) return response.status(409).send({ message: "User already exists" });
) return response.status(412).send({ message: "User already exists" });
if (!(permissions & permissionBits.DEFAULT))
permissions ^= permissionBits.DEFAULT;

View File

@ -1,22 +0,0 @@
import { readFile } from "fs/promises";
import { navbar } from "../../../../../utils/navbar.js";
import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/dashboard/contacts/create",
requiresLogin: true,
permissions: permissionBits.ADMIN,
type: "get",
async execute(request, response, args) {
let res = await readFile(
`${process.env.WWW}/dashboard/contacts/create.html`,
"utf8",
);
if (args?.error)
res += `
<script type="text/javascript">
alert("Erreur: ${args.error.replaceAll("%20", " ")}");
</script>`;
response.send(res.replaceAll("<NAVBAR>", navbar(request.session)));
},
};

View File

@ -1,16 +0,0 @@
import { permissionBits } from '../../../../../utils/permissions.js';
import { readFile } from 'fs/promises';
import { navbar } from '../../../../../utils/navbar.js';
export default {
path: "/dashboard/contacts",
requiresLogin: true,
permissions: permissionBits.ADMIN,
type: "get",
async execute(request, response) {
const html = await readFile(`${process.env.WWW}/dashboard/contacts/index.html`);
return await response.send(html.toString()
.replace('<NAVBAR>', navbar(request.session))
);
},
}

View File

@ -1,6 +1,6 @@
import { permissionBits } from '../../../../../utils/permissions.js';
import { permissionBits } from '../../../../utils/permissions.js';
import { readFile } from 'fs/promises';
import { navbar } from '../../../../../utils/navbar.js';
import { navbar } from '../../../../utils/navbar.js';
export default {
path: "/dashboard/users",

View File

@ -1,6 +1,6 @@
import { readFile } from "fs/promises";
import { navbar } from "../../../../../utils/navbar.js";
import { permissionBits } from "../../../../../utils/permissions.js";
import { navbar } from "../../../../utils/navbar.js";
import { permissionBits } from "../../../../utils/permissions.js";
export default {
path: "/dashboard/users/create",

View File

@ -1,6 +1,6 @@
import { navbar } from '../../../../../utils/navbar.js';
import { navbar } from '../../../../utils/navbar.js';
import { readFile } from 'fs/promises';
import { permissionBits, checkPermissions } from '../../../../../utils/permissions.js';
import { permissionBits, checkPermissions } from '../../../../utils/permissions.js';
export default {
path: "/dashboard/users/list",

View File

@ -1,6 +1,6 @@
import { permissionBits, checkPermissions } from '../../../../../utils/permissions.js';
import { permissionBits, checkPermissions } from '../../../../utils/permissions.js';
import { readFile } from 'fs/promises';
import { navbar } from '../../../../../utils/navbar.js';
import { navbar } from '../../../../utils/navbar.js';
export default {
path: "/dashboard/users/:username",

View File

@ -9,20 +9,10 @@ async function genHandler() {
delete: [],
};
let numberOfPages = 0;
const endpointFiles = fs
.readdirSync(pagesPath, { recursive: true })
.filter((file) => file.endsWith(".js"));
console.log(endpointFiles)
for (const file of endpointFiles) {
const { default: endpoint } = await import(`.${pagesPath}/${file}`);
handler[endpoint.type].push(endpoint);
console.log(
`\x1b[32mChargement de POST: ${endpoint.path} !\x1b[0m`,
);
numberOfPages++;
console.log(numberOfPages + " endpoints chargés ! ");
}
/*for (const category of endpointCategories) {
const endpointCategories = fs
.readdirSync(pagesPath)
.filter((file) => !file.includes("."));
for (const category of endpointCategories) {
const endpointFiles = fs
.readdirSync(`${pagesPath}${category}`)
.filter((file) => file.endsWith(".js"));
@ -35,7 +25,7 @@ async function genHandler() {
numberOfPages++;
console.log(numberOfPages + " endpoints chargés ! ");
}
}*/
}
return handler;
}
@ -96,14 +86,4 @@ function parseURL(URL) {
return [path, args];
}
function recursiveFileSearch(directory) {
const files = [];
fs.readdirSync(directory).forEach(File => {
const Absolute = Path.join(directory, File);
if (fs.statSync(Absolute).isDirectory()) return ThroughDirectory(Absolute);
else return files.push(Absolute);
});
return files;
}
export { deployHandler, parseURL };
export { deployHandler };

View File

@ -1,127 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Utilisateurs</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: black;
}
* {
box-sizing: border-box;
}
/* Add padding to containers */
.container {
padding: 16px;
background-color: white;
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Full-width input fields */
input[type=text], input[type=password] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
input[type=text]:focus, input[type=password]:focus {
background-color: #ddd;
outline: none;
}
/* Overwrite default styles of hr */
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
/* Set a style for the submit button */
.registerbtn {
background-color: #04AA6D;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}
/* Add a blue text color to links */
a {
color: dodgerblue;
}
/* Set a grey background color and center the text of the "sign in" section */
.signin {
background-color: #f1f1f1;
text-align: center;
}
</style>
<script>
function createContactFromForm() {
const form = document.getElementById("contactCreateForm");
fetch(`/api/contacts/${form.phone.value}`, {
method: "POST",
body: JSON.stringify({
phone: form.phone.value,
firstName: form.firstName.value,
lastName: form.lastName.value,
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(async (response) => {
const res = await response.json();
console.log(res);
if(!response.ok) return alert(res.message);
form.reset();
});
}
</script>
</head>
<body>
<NAVBAR>
<form action="javascript:createContactFromForm()" id="contactCreateForm">
<div class="container">
<h1>Création de compte</h1>
<p>Formulaire d'ajout de contact.</p>
<hr>
<label for="phone"><b>Numéro de téléphone</b></label>
<input type="tel" placeholder="Entrez le numéro de téléphone" name="phone" id="phone" required>
<label for="firstName"><b>Prénom</b></label>
<input type="text" placeholder="Prénom du contact" name="firstName" id="firstName" required>
<label for="lastName"><b>Nom</b></label>
<input type="text" placeholder="Nom du contact" name="lastName" id="lastName" required>
<hr>
<button type="submit" class="registerbtn">Register</button>
</div>
</form>
</body>
</html>

View File

@ -1,15 +0,0 @@
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title>Contacts</title>
</head>
<body>
<NAVBAR>
<h1>Gestion des contacts</h1>
<p><a href='/dashboard/contacts/list'>Liste des contacts</a></p>
<p><a href='/dashboard/contacts/create'>Ajouter un contact</a></p>
<p><a href='/dashboard'>Retour</a></p>
</body>
</html>

View File

@ -10,7 +10,6 @@
<h1>Dashboard</h1>
<p><a href='/calls'>Phoning</a></p>
<p><a href='/dashboard/users'>Gestion des utilisateurs</a></p>
<p><a href='/dashboard/contacts'>Gestion des contacts</a></p>
<p><a href='/logout'>Déconnexion</a></p>
</body>
</html>