This commit is contained in:
CICD - Pipeline 2023-02-22 13:57:27 +01:00
parent 9764132760
commit 3e2ff38897
22 changed files with 1209 additions and 79 deletions

2
app.js
View File

@ -17,6 +17,7 @@ var signoutRouter = require('./routes/signout');
var getRouter = require('./routes/get'); var getRouter = require('./routes/get');
var setRouter = require('./routes/set'); var setRouter = require('./routes/set');
var uploadRouter = require('./routes/upload'); var uploadRouter = require('./routes/upload');
var userManagerRouter = require('./routes/usermanager');
@ -42,6 +43,7 @@ app.use('/signout', signoutRouter);
app.use('/get', getRouter); app.use('/get', getRouter);
app.use('/set', setRouter) app.use('/set', setRouter)
app.use('/upload', uploadRouter) app.use('/upload', uploadRouter)
app.use('/usermanager', userManagerRouter)
// catch 404 and forward to error handler // catch 404 and forward to error handler

View File

@ -2,22 +2,79 @@ var fs = require("fs")
var uuid = require('uuid') var uuid = require('uuid')
var path = require("path") var path = require("path")
var CryptoJS = require("crypto-js") var CryptoJS = require("crypto-js")
var Jimp = require("jimp")
module.exports.createUser = (name, password) => {
const passcrypt = CryptoJS.AES.encrypt(password, "D*G-KaPdSgVkYp3s");
const userUUID = uuid.v4();
const userData = {
"username":name,
"password": passcrypt.toString(),
"uuid": userUUID,
"token":{
}
module.exports.createUser = (name, password, level, fullname) => {
if(this.getUUID(name) == false) {
const passcrypt = CryptoJS.AES.encrypt(password, "D*G-KaPdSgVkYp3s");
const userUUID = uuid.v4();
const userData = {
"username":name,
"password": passcrypt.toString(),
"uuid": userUUID,
"fullname": fullname,
"permissionLevel":level,
"token":{
},
"lastconnexion":0
}
const src = __dirname + path.sep + "public" + path.sep + "images" + path.sep + "standalone.png"
const dest = __dirname + path.sep + "public" + path.sep + "images" + path.sep + "userspics" + path.sep + name + ".png"
fs.copyFileSync(src, dest)
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + userUUID + ".json", JSON.stringify(userData, null, 2))
return "USER_CREATED"
} else {
return "USER_ALREADY_EXIST"
} }
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + userUUID + ".json", JSON.stringify(userData, null, 2))
}
module.exports.deleteUser = (name) => {
const userUUID = this.getUUID(name)
if(userUUID != false) {
fs.rmSync(__dirname + path.sep + "users" + path.sep + userUUID + ".json")
fs.rmSync(__dirname + path.sep + "public" + path.sep + "images" + path.sep + "userspics"+ path.sep + name+ ".png")
return "USER_DELETED"
} else {
return "USER_ALREADY_DELETED"
}
}
module.exports.deleteToken = (username) => {
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(username) + ".json", 'utf-8'))
userData.token = {}
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(username) + ".json", JSON.stringify(userData, null, 2))
} }
@ -27,15 +84,21 @@ module.exports.checkToken = (req, res) => {
const users = this.getUsers() const users = this.getUsers()
if(req.cookies.tokenID == null) { if(req.cookies.tokenID == null) {
return false; const checkTokenData = {"name":false}
return checkTokenData;
} else if(tokens.has(req.cookies.tokenID)) { } else if(tokens.has(req.cookies.tokenID)) {
const user = tokens.get(req.cookies.tokenID) const user = tokens.get(req.cookies.tokenID)
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + users.get(user) + ".json", 'utf-8')) const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + users.get(user) + ".json", 'utf-8'))
userData.lastconnexion = Date.now()
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + userData.uuid + ".json", JSON.stringify(userData, null, 2))
if(userData.token.livableToken == true) { if(userData.token.livableToken == true) {
return user; const checkTokenData = {"name":user, "permLevel": userData.permissionLevel, "fullname":userData.fullname, "lastconnexion":userData.lastconnexion};
return checkTokenData;
} else { } else {
const tokenDate = new Date(userData.token.createdAt) const tokenDate = new Date(userData.token.createdAt)
@ -43,11 +106,13 @@ module.exports.checkToken = (req, res) => {
if(tokenDate.getDay() == nowDate.getDay() && tokenDate.getMonth() == nowDate.getMonth()) { if(tokenDate.getDay() == nowDate.getDay() && tokenDate.getMonth() == nowDate.getMonth()) {
return user; const checkTokenData = {"name":user, "permLevel": userData.permissionLevel, "fullname":userData.fullname, "lastconnexion":userData.lastconnexion};
return checkTokenData;
} else { } else {
res.clearCookie('tokenID'); res.clearCookie('tokenID');
return false; const checkTokenData = {"name":false}
return checkTokenData;
} }
@ -55,16 +120,20 @@ module.exports.checkToken = (req, res) => {
} }
} else { } else {
return false; const checkTokenData = {"name":false}
return checkTokenData;
} }
return false;
} }
module.exports.getFullName = (username) => { module.exports.getFullName = (username) => {
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(username) + ".json", 'utf-8')) const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(username) + ".json", 'utf-8'))
return userData.fullname return userData.fullname
} }
@ -136,13 +205,23 @@ module.exports.getUUID = (username) => {
users.set(fileData.username, fileData.uuid) users.set(fileData.username, fileData.uuid)
}) })
return users.get(username);
var data = users.get(username);
if(typeof data == "undefined") {
data = false
}
return data;
} }
module.exports.changeFullName = (username, req, res) => { module.exports.changeFullName = (username, req, res) => {
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(this.checkToken(req, res)) + ".json", 'utf-8')) const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(this.checkToken(req, res).name) + ".json", 'utf-8'))
Object.defineProperties(userData, { Object.defineProperties(userData, {
fullname: { fullname: {
@ -187,7 +266,7 @@ module.exports.changePassword = (req, res) => {
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(this.checkToken(req, res)) + ".json", 'utf-8')) const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(this.checkToken(req, res).name) + ".json", 'utf-8'))
const oldp = CryptoJS.AES.encrypt(req.body.additional, "D*G-KaPdSgVkYp3s") const oldp = CryptoJS.AES.encrypt(req.body.additional, "D*G-KaPdSgVkYp3s")
const newp = CryptoJS.AES.encrypt(req.body.value, "D*G-KaPdSgVkYp3s") const newp = CryptoJS.AES.encrypt(req.body.value, "D*G-KaPdSgVkYp3s")
@ -217,3 +296,45 @@ module.exports.changePassword = (req, res) => {
} }
module.exports.getAll = (username) => {
const users = this.getUsers()
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + users.get(username) + ".json", 'utf-8'))
const allData = {"username":username, "permLevel": userData.permissionLevel, "fullname":userData.fullname, "lastconnexion":userData.lastconnexion};
return allData
}
module.exports.editUser = (requestData) => {
if(this.getUUID(requestData.original) != false) {
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(requestData.original) + ".json", 'utf-8'))
userData.token = {};
userData.username = requestData.username;
userData.fullname = requestData.fullname;
userData.permissionLevel = requestData.permLevel;
if(requestData.password != "") {
userData.password = CryptoJS.AES.encrypt(requestData.password, "D*G-KaPdSgVkYp3s").toString()
}
fs.renameSync(__dirname + path.sep + "public" + path.sep + "images" + path.sep + "userspics" + path.sep + requestData.original + ".png",__dirname + path.sep + "public" + path.sep + "images" + path.sep + "userspics" + path.sep + requestData.username + ".png")
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + this.getUUID(requestData.original) + ".json", JSON.stringify(userData, null, 2))
return true;
} else {
return false;
}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "neutral", "name": "neutral",
"version": "DEV_2.0", "version": "DEV_3.0",
"private": true, "private": true,
"nodemonConfig": { "nodemonConfig": {
"ext": "js", "ext": "js",

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 17 KiB

File diff suppressed because one or more lines are too long

View File

@ -288,7 +288,7 @@ body {
.sidebar-content { .sidebar-content {
text-align: center; text-align: center;
height: 85%; height: 83%;
padding-top: 50%; padding-top: 50%;
padding-bottom: 50%; padding-bottom: 50%;
@ -308,7 +308,7 @@ body {
.sidebar-footer { .sidebar-footer {
height: 5%; height: 10%;
text-align: center; text-align: center;
} }
@ -328,12 +328,13 @@ body {
vertical-align: center; vertical-align: center;
align-items: center; align-items: center;
align-self: center; align-self: center;
transform: scale(1.7);
} }
.sidebar:hover .sidebar-image { .sidebar:hover .sidebar-image {
display: unset; display: unset;
transform: scale(1);
} }

View File

@ -55,6 +55,7 @@
</div> </div>
<div class="hbox col-lg"> <div class="hbox col-lg">
<h1>EcoleDirecte</h1> <h1>EcoleDirecte</h1>
<!-- <iframe width="100%" height="90%" src="https://ecoledirecte.com"></iframe> -->
</div> </div>
</div> </div>
<div class="row w-100"> <div class="row w-100">

View File

@ -1,4 +1,4 @@
<div class="home"> <div class="settings">
<h1>Paramètres du compte</h1> <h1>Paramètres du compte</h1>
</br> </br>
<div class="homepanel"> <div class="homepanel">
@ -125,7 +125,7 @@
} }
}
if(user_oldp.value != "" | user_newp.value != "") { if(user_oldp.value != "" | user_newp.value != "") {
@ -176,15 +176,15 @@
} }
if(user_fullname.value.length >= 18) { if(user_fullname.value.length >= 18) {
user_finfo.innerHTML = "<p>Le nom complet ne doit pas dépasser 18 caractères</p>" user_finfo.innerHTML = "<p>Le nom complet ne doit pas dépasser 18 caractères</p>"
} else if(user_fullname.value != "") { } else if(user_fullname.value != "") {
fetch('/set', { fetch('/set', {
method: 'POST', method: 'POST',
@ -218,7 +218,7 @@
} }
}
} }

View File

@ -1,33 +1,655 @@
<div class="home"> <div class="users">
<h1>Gestion des utilisateurs</h1> <h1>Gestionnnaire des utilisateurs</h1>
</br> </br>
<div class="homepanel"> <div class="homepanel">
<div class="row w-100"> <div class="row w-100">
<div class="hbox col"> <div class="hbox col">
<h1><i class="fa fa-users"></i> Utilisateurs</h1> <h1><i class="fa fa-users"></i> Utilisateurs</h1>
<div id="gus_panel" class="gus_users">
</div>
<button id="gus_add" class="gus_add"><i class="fa fa-plus"></i> Ajouter un utilisateur</button>
<div id="gus_info"></div>
</div> </div>
</div> </div>
</div>
</div> </div>
<dialog class="gus_adduser" id="gus_adduser">
<h1><i class="fa fa-plus"></i> Ajouter un utilisateur</h1>
<div class="gus_add_imagediv">
<img width="200" height="200" id="gus_add_image" class="gus_add_image" src="/images/standalone.png">
<br>
<input class="gus_image_upload" accept="image/png, image/jpeg" name="apic" type="file" id="gus_image_upload"/>
<br>
<div style="color: rgb(255, 76, 76);" id="gus_add_image_info"></div>
</div>
<div class="form">
<p>Nom d'utilisateur</p>
<input class="inp" id="gus_add_username" type="text">
<p>Nom complet :</p>
<input class="inp" id="gus_add_fullname" type="text">
<p>Mot de passe :</p>
<input class="inp" id="gus_add_password" type="password">
<p>Niveau de permission :</p>
<select class="inp" id="gus_add_perm">
<option>Niveau 1 : (Utilisateur)</option>
<option>Niveau 2 : (Editeur)</option>
<option>Niveau 3 : (Operateur)</option>
<option>Niveau 4 : (Administrateur)</option>
</select>
<div style="color: rgb(255, 76, 76);" id="gus_add_info"></div>
</div>
<button onclick="getPage('users.html')" id="gus_add_close" class="gus_add_close">Annuler</button>
<button id="gus_add_confirm" class="gus_add_confirm">Ajouter</button>
</dialog>
<div id="gus_dialoguser">
</div> </div>
<script>
if(typeof adduserform == 'undefined'){
const panel = document.getElementById("gus_panel")
const dialogUserall = document.getElementById("gus_dialoguser")
showUsers()
/* EXAMPLE OF A LINE
<div class="gus_line row w-100">
<div class="col-lg">
<p><img width="200" class="gus_image" src="images/userspics/' + user + '.png"> <span id="' + user + "_fullname" + '"></span></p>
</div>
<div class="col-lg">
<p>Dernière connexion : <span id="' + user + "_lastco" + '"></span></p>
</div>
<div class="col-lg">
<p>Niveau de permissions : <span id="' + user + "_permLevel" + '"></span></p>
</div>
<div class="col-lg">
<button id="' + user + "_edit" + '" class="gus_edit"><i class="fa fa-pen"></i></button>
<button id="' + user + "_deco" + '" class="gus_signout"><i class="fa-solid fa-arrow-right-from-bracket"></i></button>
<button id="' + user + "_del" + '" class="gus_delete"><i class="fa fa-trash"></i></button>
</div>
</div>
*/
function showUsers() {
var number = Date.now()
var dialogtoshow = new Array()
var usertoshow = new Array()
fetch('/usermanager', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"get", "value": ""})
})
.then(response => response.json())
.then(response => load(response))
function load(response) {
if(response.result == "failed") {
content.innerHTML = ' <h1 style="color:red;"><i style="color:yellow; font-size: 2vw;" class="fa fa-warning"></i> Erreur de chargement des données - Erreur : ' + response.content + '</h1>'
console.log("FAILED")
} else if(response.result == "success") {
var fullname;
var lastco;
var permLevel;
for(var user of response.content) {
usertoshow.push('<div class="gus_line row w-100"><div class="col-lg"><p><img width="200" class="gus_image" src="images/userspics/'+ user +'.png?' + number + '"> <span id="' + user + "_fullname"+'"></span></p></div><div class="col-lg"><p>Dernière connexion : <span id="' + user + "_lastco"+'"></span></p></div><div class="col-lg"><p>Niveau de permissions : <span id="'+user+"_permLevel"+'"></span></p></div><div class="col-lg"><button id="'+user+"_edit"+'" class="gus_edit"><i class="fa fa-pen"></i></button><button id="'+user+"_deco"+'" class="gus_signout"><i class="fa-solid fa-arrow-right-from-bracket"></i></button><button id="'+user+"_del"+'" class="gus_delete"><i class="fa fa-trash"></i></button></div></div>')
dialogtoshow.push('<dialog class="gus_adduser" id="' + user + '_editDialog"> <h1><i class="fa fa-pen"></i> Editer un utilisateur</h1> <div class="gus_add_imagediv"> <img width="200" height="200" id="gus_add_image" class="gus_add_image" src="/images/userspics/' + user + '.png?' + number + '"> <br> <input class="gus_image_upload" accept="image/png, image/jpeg" name="apic" type="file" id="' + user + '_image_upload"/> <br> <div style="color: rgb(255, 76, 76);" id="' + user + '_add_image_info"></div> </div> <div class="form"> <p>Nom d\'utilisateur</p> <input class="inp" id="' + user + '_add_username" type="text"> <p>Nom complet :</p> <input class="inp" id="' + user + '_add_fullname" type="text"> <p>Mot de passe :</p> <input class="inp" id="' + user + '_add_password" type="password"> <p>Niveau de permission :</p> <select class="inp" id="' + user + '_add_perm"> <option>Niveau 1 : (Utilisateur)</option> <option>Niveau 2 : (Editeur)</option> <option>Niveau 3 : (Operateur)</option> <option>Niveau 4 : (Administrateur)</option> </select> <div style="color: rgb(255, 76, 76);" id="' + user + '_add_info"></div> </div> <button onclick="getPage(\'users.html\')" id="' + user + '_add_close" class="gus_add_close">Annuler</button> <button id="' + user + '_add_confirm" class="gus_add_confirm">Editer</button> </dialog> ')
panel.innerHTML = usertoshow.join("")
dialogUserall.innerHTML = dialogtoshow.join("")
fetch('/get', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"all", "name": user, "additional": ""})
})
.then(response => response.json())
.then(response => after(response))
function after(response) {
const date = new Date(response.content.lastconnexion)
var gmonth = date.getMonth()
var gday = date.getDate()
var gHour = date.getHours()
var gMinute = date.getMinutes()
var gSecondes = date.getSeconds()
if(date.getMonth() + 1 <= 9) {
gmonth = "0" + (date.getMonth() + 1)
}
if(date.getDate() + 1 <= 9) {
gday = "0" + date.getDate()
}
if(date.getHours() + 1 <= 9) {
gHour = "0" + date.getHours()
}
if(date.getMinutes() + 1 <= 9) {
gMinute = "0" + date.getMinutes()
}
if(date.getSeconds() + 1 <= 9) {
gSecondes = "0" + date.getSeconds()
}
var currentDate = gday + "-" + gmonth + "-" + date.getFullYear() + " - " + gHour + ":" + gMinute
fullname = document.getElementById(response.content.username + "_fullname")
lastco = document.getElementById(response.content.username + "_lastco")
permLevel = document.getElementById(response.content.username + "_permLevel")
fullname.innerHTML = response.content.fullname
permLevel.innerHTML = response.content.permLevel
lastco.innerHTML = currentDate
const editBtn = document.getElementById(response.content.username + "_edit")
const decoBtn = document.getElementById(response.content.username +"_deco")
const delBtn = document.getElementById(response.content.username + "_del")
delBtn.addEventListener("click", () => {
fetch('/usermanager', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"del", "value": response.content.username})
})
getPage("users.html")
})
decoBtn.addEventListener("click", () => {
fetch('/usermanager', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"deco", "value": response.content.username})
})
gusInfo.innerHTML = "<p style='color: rgb(130, 255, 163); padding: 1vw;'>Le Token de l'utilisateur <strong>" + response.content.username + "</strong> a été supprimé</p>"
})
editBtn.addEventListener("click", () => {
const editDialog = document.getElementById(response.content.username + "_editDialog")
const edituserUsername = document.getElementById(response.content.username + "_add_username")
const edituserPassword = document.getElementById(response.content.username + "_add_password")
const edituserFullname = document.getElementById(response.content.username + "_add_fullname")
const edituserPerm = document.getElementById(response.content.username + "_add_perm")
const edituserInfo = document.getElementById(response.content.username + "_add_info")
const edituserImage = document.getElementById(response.content.username + "_image_upload")
const edituserConfirm = document.getElementById(response.content.username + "_add_confirm")
edituserUsername.value = response.content.username;
edituserFullname.value = response.content.fullname;
if(response.content.permLevel == 1) {
edituserPerm.value = "Niveau 1 : (Utilisateur)";
} else if(response.content.permLevel == 2) {
edituserPerm.value = "Niveau 2 : (Editeur)";
} else if(response.content.permLevel == 3) {
edituserPerm.value = "Niveau 3 : (Operateur)";
} else if(response.content.permLevel == 4) {
edituserPerm.value = "Niveau 4 : (Administrateur)";
}
edituserConfirm.addEventListener("click", () => {
edituserInfo.innerHTML = ""
if(edituserUsername.value != "" && edituserFullname.value != "") {
var level = 1;
if(edituserPerm.value == 'Niveau 1 : (Utilisateur)') {
level = 1
} else if(edituserPerm.value == 'Niveau 2 : (Editeur)') {
level = 2
} else if(edituserPerm.value == 'Niveau 3 : (Operateur)') {
level = 3
} else if(edituserPerm.value == 'Niveau 4 : (Administrateur)') {
level = 4
}
const requestData = {
"original":response.content.username,
"username":edituserUsername.value,
"fullname":edituserFullname.value,
"permLevel": level,
"password": edituserPassword.value
}
fetch('/usermanager', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"edit", "value": requestData})
})
.then(response => response.json())
.then(response => editresp(response))
function editresp(eresponse) {
if(eresponse.result == "failed") {
content.innerHTML = ' <h1 style="color:red;"><i style="color:yellow; font-size: 2vw;" class="fa fa-warning"></i> Erreur de chargement des données - Erreur : ' + eresponse.content + '</h1>'
console.log("FAILED")
} else if(eresponse.result == "success") {
if(eresponse.content != "DATA_VALID") {
edituserInfo.innerHTML = "L'édition de l'utilisateur a échoué."
} else {
if(edituserImage.files[0] != null) {
const image_acc = new FormData();
image_acc.append("apic", edituserImage.files[0])
fetch('/upload', {
method: 'POST',
mode:"cors",
cache:"no-cache",
credentials:"same-origin",
headers: {
"uploadforuser": requestData.username
},
referrerPolicy:"no-referrer",
redirect: 'follow',
body: image_acc
}).then(response => getPage("users.html"))
} else {
getPage("users.html")
}
}
}
}
} else {
edituserInfo.innerHTML = "<p>L'utilisateur ne peut pas ne pas avoir de nom d'utilisateur et de nom complet</p>"
}
})
editDialog.showModal()
})
}
}
}
}
}
const imgInput = document.getElementById("gus_image_upload")
const imgEl = document.getElementById("gus_add_image")
const imgInfo = document.getElementById("gus_add_image_info")
imgInput.addEventListener("change", (event) => {
imgInfo.innerHTML = ""
const nowImage = event.target.files
const nowImageLength = event.target.files
if(nowImage[0].type == "image/jpeg" | nowImage[0].type == "image/png") {
const imageSrc = URL.createObjectURL(nowImage[0]);
imgEl.src = imageSrc;
} else {
imgInput.value = ""
imgInfo.innerHTML = '<p>Seul les images (JPEG et PNG) sont acceptés.</p>'
}
})
const adduserForm = document.getElementById("gus_adduser")
const adduserBtn = document.getElementById("gus_add")
const adduserConfirm = document.getElementById("gus_add_confirm")
const adduserUsername = document.getElementById("gus_add_username")
const adduserPassword = document.getElementById("gus_add_password")
const adduserFullname = document.getElementById("gus_add_fullname")
const adduserPerm = document.getElementById("gus_add_perm")
const addInfo = document.getElementById("gus_add_info")
const gusInfo = document.getElementById("gus_info")
adduserBtn.addEventListener("click", () => {
adduserUsername.value = ""
adduserPassword.value = ""
adduserFullname.value = ""
adduserPerm.value = "Niveau 1 : (Utilisateur)"
addInfo.value = ""
gusInfo.innerHTML = ""
imgEl.src = "/images/standalone.png" ;
adduserForm.showModal()
})
adduserConfirm.addEventListener("click", () => {
addInfo.innerHTML = ""
imgInfo.innerHTML = ""
if(adduserUsername.value != "" && adduserPassword.value != "" && adduserFullname.value != "") {
const addUserData = {"username":adduserUsername.value, "password":adduserPassword.value, "fullname":adduserFullname.value, "permLevel":adduserPerm.value }
const addUserImage = document.getElementById("gus_image_upload")
fetch('/usermanager', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"add", "value": addUserData})
})
.then(response => response.json())
.then(response => load(response))
function load(response) {
if(response.result == "failed") {
content.innerHTML = ' <h1 style="color:red;"><i style="color:yellow; font-size: 2vw;" class="fa fa-warning"></i> Erreur de chargement des données - Erreur : ' + response.content + '</h1>'
console.log("FAILED")
} else if(response.result == "success") {
if(response.content == "VALID") {
if(addUserImage.files[0] != null) {
const image_acc = new FormData();
image_acc.append("apic", addUserImage.files[0])
fetch('/upload', {
method: 'POST',
mode:"cors",
cache:"no-cache",
credentials:"same-origin",
headers: {
"uploadforuser": adduserUsername.value
},
referrerPolicy:"no-referrer",
redirect: 'follow',
body: image_acc
})
}
gusInfo.innerHTML = "<p style='color:rgb(130, 255, 163); padding: 1vw;'>Ajout de l'utilisateur <strong>" + adduserUsername.value + "</strong> avec succès.</p>"
adduserForm.close()
getPage("users.html")
} else {
addInfo.innerHTML = '<p>' + response.content + '</p>'
}
}
}
} else {
addInfo.innerHTML = '<p">Tous les champs doivent être remplis</p>'
}
})
}
</script>
<!-- Style--> <!-- Style-->
<style> <style>
.home { .gus_adduser p {
margin-top: 0.5vw;
}
.gus_add_imagediv {
text-align: center;
justify-items: center;
}
.inp {
border-style: hidden;
border-radius: 1vw;
padding: 0.2vw;
padding-left: 1vw;
transition: all 0.2s ease 0s;
} }
.gus_adduser .gus_image_upload {
margin-top: 1vw;
margin-bottom: 1vw;
}
select.inp {
margin-bottom: 0.5vw;
}
.inp:hover {
box-shadow: 2px 2px 5px rgba(255, 255, 255, 0.477) ;
}
.inp:focus {
box-shadow: 5px 5px 5px rgba(0, 174, 255, 0.477) ;
}
.gus_adduser {
border-radius: 1vw;
border-color: transparent;
background-color: rgb(80, 80, 80);
color: white;
text-align: center;
}
.gus_add_image {
border-radius: 100%;
}
.gus_add_close {
border-radius: 1vw;
border-color: rgb(255, 48, 48);
border-width: 1%;
border-style: solid;
color: white;
background-color: transparent;
transition: all 0.2s ease 0s;
margin: 0.5vw;
padding: 0.5vw;
font-size: 1vw;
}
.gus_add_close:hover {
box-shadow: 1px 1px 10px rgb(255, 48, 48);
background-color: rgb(255, 48, 48);
color: black;
}
.gus_add_close:active {
box-shadow: none;
}
.gus_add_confirm {
border-radius: 1vw;
border-color: rgb(0, 174, 255);
border-width: 1%;
border-style: solid;
color: white;
background-color: transparent;
transition: all 0.2s ease 0s;
margin: 0.5vw;
padding: 0.5vw;
font-size: 1vw;
}
.gus_add_confirm:hover {
box-shadow: 1px 1px 10px rgb(0, 174, 255);
background-color: rgb(0, 174, 255);
color: black;
}
.gus_add_confirm:active {
box-shadow: none;
}
.hbox h1 { .hbox h1 {
@ -41,6 +663,137 @@ table {
} }
.gus_line {
margin: 1vw;
text-align: center;
display: flex;
vertical-align: middle;
align-items: center;
}
.gus_image {
width: 10%;
border-radius: 100%;
}
.gus_users {
margin: 1%;
padding: 1%;
background-color: rgb(80, 80, 80);
border-radius: 1vw;
box-shadow: 5px 5px 5px rgba(80, 80, 80, 0.477) ;
}
.gus_edit {
border-radius: 100%;
border-color: rgb(0, 174, 255);
border-width: 1%;
border-style: solid;
color: white;
background-color: transparent;
transition: all 0.2s ease 0s;
width: 2.5vw;
height: 2.5vw;
margin-left: 0.5vw;
margin-right: 0.5vw;
font-size: 1vw;
}
.gus_edit:hover {
box-shadow: 1px 1px 10px rgb(0, 174, 255);
background-color: rgb(0, 174, 255);
color: black;
}
.gus_edit:active {
box-shadow: none;
}
.gus_signout {
border-radius: 100%;
border-color: rgb(254, 254, 74);
border-width: 1%;
border-style: solid;
color: white;
background-color: transparent;
transition: all 0.2s ease 0s;
width: 2.5vw;
height: 2.5vw;
margin-left: 0.5vw;
margin-right: 0.5vw;
font-size: 1vw;
}
.gus_signout:hover {
box-shadow: 1px 1px 10px rgb(254, 254, 74);
background-color: rgb(254, 254, 74);
color: black;
}
.gus_signout:active {
box-shadow: none;
}
.gus_delete {
border-radius: 100%;
border-color: rgb(255, 48, 48);
border-width: 1%;
border-style: solid;
color: white;
background-color: transparent;
transition: all 0.2s ease 0s;
width: 2.5vw;
height: 2.5vw;
margin-left: 0.5vw;
margin-right: 0.5vw;
font-size: 1vw;
}
.gus_delete:hover {
box-shadow: 1px 1px 10px rgb(255, 48, 48);
background-color: rgb(255, 48, 48);
color: black;
}
.gus_delete:active {
box-shadow: none;
}
.gus_add {
border-radius: 1vw;
border-color: rgb(0, 174, 255);
border-width: 1%;
border-style: solid;
color: white;
background-color: transparent;
transition: all 0.2s ease 0s;
padding: 0.5vw;
}
.gus_add:hover {
box-shadow: 1px 1px 10px rgb(0, 174, 255);
background-color: rgb(0, 174, 255);
color: black;
}
.gus_add:active {
box-shadow: none;
}
.hbox { .hbox {

View File

@ -10,7 +10,7 @@ router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check == false) { if(check.name == false) {
res.redirect(302, "/login") res.redirect(302, "/login")
@ -27,7 +27,7 @@ router.post("/", function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check == false) { if(check.name == false) {
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"}) res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
@ -69,14 +69,27 @@ router.post("/", function(req, res, next) {
} else if(req.body.request == "username") { } else if(req.body.request == "username") {
res.send({"result":"success", "content": ntr.checkToken(req, res)}) res.send({"result":"success", "content": ntr.checkToken(req, res).name})
} else if(req.body.request == "fullname") { } else if(req.body.request == "fullname") {
res.send({"result":"success", "content": ntr.getFullName(ntr.checkToken(req, res))}) res.send({"result":"success", "content": ntr.getFullName(ntr.checkToken(req, res).name)})
} else if(req.body.request == "all") {
if(check.permLevel == 4) {
res.send({"result":"success", "content": ntr.getAll(req.body.name)})
} else {
res.send({"result":"failed", "content":"ERROR_USER_PERMISSION_TOO_LOW"})
}
} else { } else {
res.send({"result":"failed", "content":"ERROR_REQUEST_NOT_VALID"}) res.send({"result":"failed", "content":"ERROR_REQUEST_NOT_VALID"})

View File

@ -7,15 +7,15 @@ router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check.name == false) {
if(check == false) {
res.redirect(302, "/login") res.redirect(302, "/login")
} else { } else {
console.log(ntr.getFullName(check.name))
res.render('index', { title: ntr.getFullName(check), username: ntr.getFullName(check), accountpic: '<img width="200" class="w-25 sidebar-image noside" src="images/userspics/' + check + '.png">' }); res.render('index', { title: ntr.getFullName(check.name), username: ntr.getFullName(check.name), accountpic: '<img width="200" class="w-25 sidebar-image noside" src="images/userspics/' + check.name + '.png">' });
} }

View File

@ -12,7 +12,7 @@ router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check != false) { if(check.name != false) {
res.redirect(302, "/") res.redirect(302, "/")

View File

@ -12,7 +12,7 @@ router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check != false) { if(check.name != false) {
res.redirect(302, "/") res.redirect(302, "/")
@ -27,7 +27,7 @@ router.post("/", function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check == false) { if(check.name == false) {
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"}) res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})

View File

@ -13,7 +13,7 @@ router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check == false) { if(check.name == false) {
res.redirect(302, "/login") res.redirect(302, "/login")

View File

@ -13,7 +13,7 @@ router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check != false) { if(check.name != false) {
res.redirect(302, "/") res.redirect(302, "/")
@ -28,7 +28,7 @@ router.post("/", function(req, res, next) {
var check = ntr.checkToken(req, res) var check = ntr.checkToken(req, res)
if(check == false) { if(check.name == false) {
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"}) res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
@ -37,19 +37,118 @@ router.post("/", function(req, res, next) {
const image = req.files.apic const image = req.files.apic
if(req.files.apic.mimetype == "image/png" | req.files.apic.mimetype == "image/jpeg" ) { if(req.headers.uploadforuser != null) {
if(check.permLevel == 4) {
if(req.files.apic.mimetype == "image/png" | req.files.apic.mimetype == "image/jpeg" ) {
var uploadPath = "";
var uploadDir = __dirname.replace("routes","public" + path.sep + "images" + path.sep + "userspics" + path.sep)
if(req.files.apic.mimetype == "image/png") {
uploadPath = req.headers.uploadforuser + ".png"
}
if(req.files.apic.mimetype == "image/jpeg") {
uploadPath = req.headers.uploadforuser+ ".jpg"
}
image.mv(uploadPath, function(err) {
if(err) {
res.send({"result":"success", "content": "La photo de profil n'a pas pu être chargé."})
console.log(err)
} else {
if(fs.existsSync(uploadDir + req.headers.uploadforuser + ".png") | fs.existsSync(uploadDir + req.headers.uploadforuser + ".jpg")) {
if(fs.existsSync(uploadDir + req.headers.uploadforuser+ ".png")) {
fs.rmSync(uploadDir + req.headers.uploadforuser + ".png")
}
fs.renameSync(__dirname.replace("routes", "") + uploadPath , uploadDir + uploadPath)
if(req.files.apic.mimetype == "image/jpeg") {
Jimp.read(uploadDir + uploadPath, function (err, image) {
image.resize(200,200, function(err){
if (err) throw err;
}).write(uploadDir + uploadPath.replace("jpg", "png"))
fs.rmSync(uploadDir + req.headers.uploadforuser + ".jpg")
res.send({"result":"success", "content": "<span style='color:rgb(130, 255, 163);'>La photo de profil a été changé avec succès.</span>",})
})
} else if(req.files.apic.mimetype == "image/png") {
Jimp.read(uploadDir + uploadPath, function (err, image) {
image.resize(200,200, function(err){
if (err) throw err;
}).write(uploadDir + uploadPath)
res.send({"result":"success", "content": "<span style='color:rgb(130, 255, 163);'>La photo de profil a été changé avec succès.</span>",})
})
} else {
res.send({"result":"success", "content": "<span style='color:rgb(130, 255, 163);'>La photo de profil a été changé avec succès.</span>",})
}
} else {
console.log(uploadDir + uploadPath)
res.send({"result":"success", "content": "La photo de profil n'a pas pu être chargé."})
console.log("ERROR - UPLOAD NOT WORK CORRECYLT")
}
}
})
} else {
res.send({"result":"success", "content": "Seul les images (JPEG et PNG) sont acceptés."})
}
}
} else {
if(req.files.apic.mimetype == "image/png" | req.files.apic.mimetype == "image/jpeg" ) {
var uploadPath = ""; var uploadPath = "";
var uploadDir = __dirname.replace("routes","public" + path.sep + "images" + path.sep + "userspics" + path.sep) var uploadDir = __dirname.replace("routes","public" + path.sep + "images" + path.sep + "userspics" + path.sep)
if(req.files.apic.mimetype == "image/png") { if(req.files.apic.mimetype == "image/png") {
uploadPath = ntr.checkToken(req, res) + ".png" uploadPath = ntr.checkToken(req, res).name + ".png"
} }
if(req.files.apic.mimetype == "image/jpeg") { if(req.files.apic.mimetype == "image/jpeg") {
uploadPath = ntr.checkToken(req, res) + ".jpg" uploadPath = ntr.checkToken(req, res).name + ".jpg"
} }
image.mv(uploadPath, function(err) { image.mv(uploadPath, function(err) {
@ -60,11 +159,11 @@ router.post("/", function(req, res, next) {
if(fs.existsSync(uploadDir + ntr.checkToken(req, res) + ".png") | fs.existsSync(uploadDir + ntr.checkToken(req, res) + ".jpg")) { if(fs.existsSync(uploadDir + ntr.checkToken(req, res).name + ".png") | fs.existsSync(uploadDir + ntr.checkToken(req, res).name + ".jpg")) {
if(fs.existsSync(uploadDir + ntr.checkToken(req, res) + ".png")) { if(fs.existsSync(uploadDir + ntr.checkToken(req, res).name + ".png")) {
fs.rmSync(uploadDir + ntr.checkToken(req, res) + ".png") fs.rmSync(uploadDir + ntr.checkToken(req, res).name + ".png")
} }
fs.renameSync(__dirname.replace("routes", "") + uploadPath , uploadDir + uploadPath) fs.renameSync(__dirname.replace("routes", "") + uploadPath , uploadDir + uploadPath)
@ -74,7 +173,7 @@ router.post("/", function(req, res, next) {
image.resize(200,200, function(err){ image.resize(200,200, function(err){
if (err) throw err; if (err) throw err;
}).write(uploadDir + uploadPath.replace("jpg", "png")) }).write(uploadDir + uploadPath.replace("jpg", "png"))
fs.rmSync(uploadDir + ntr.checkToken(req, res) + ".jpg") fs.rmSync(uploadDir + ntr.checkToken(req, res).name + ".jpg")
res.send({"result":"success", "content": "<span style='color:rgb(130, 255, 163);'>La photo de profil a été changé avec succès.</span>",}) res.send({"result":"success", "content": "<span style='color:rgb(130, 255, 163);'>La photo de profil a été changé avec succès.</span>",})
@ -128,6 +227,7 @@ router.post("/", function(req, res, next) {
} }
}
} }

140
routes/usermanager.js Normal file
View File

@ -0,0 +1,140 @@
var express = require('express');
var router = express.Router();
var ntr = require("../neutral-functions.js")
/* GET home page. */
router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res)
if(check.name != false) {
res.redirect(302, "/")
} else {
res.render('login', {error: ""});
}
});
router.post("/", function(req, res, next) {
var check = ntr.checkToken(req, res)
if(check.name == false) {
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
} else {
if(check.permLevel == 4) {
const bod = req.body
if(bod.request == "add") {
var level = 1;
if(bod.value.permLevel == 'Niveau 1 : (Utilisateur)') {
level = 1
} else if(bod.value.permLevel == 'Niveau 2 : (Editeur)') {
level = 2
} else if(bod.value.permLevel == 'Niveau 3 : (Operateur)') {
level = 3
} else if(bod.value.permLevel == 'Niveau 4 : (Administrateur)') {
level = 4
}
const resp = ntr.createUser(bod.value.username, bod.value.password, level, bod.value.fullname)
if(resp == "USER_ALREADY_EXIST") {
res.send({"result":"success", "content":"L'utilisateur existe déjà."})
} else if(resp == 'USER_CREATED') {
res.send({"result":"success", "content":"VALID"})
} else {
res.send({"result":"failed", "content":"ERROR_USER_NOT_WORK", "additional": "REQUEST_MISSING"})
}
} else if(bod.request == "get") {
var users = []
for(var element of ntr.getUsers().keys()) {
users.push(element)
};
res.send({"result": "success", "content": users})
} else if(bod.request == "del") {
const resp = ntr.deleteUser(bod.value)
if(resp == "USER_ALREADY_DELETED") {
res.send({"result":"success", "content":"L'utilisateur n'existe déjà plus."})
} else if(resp == 'USER_DELETED') {
res.send({"result":"success", "content":"VALID"})
} else {
res.send({"result":"failed", "content":"ERROR_USER_NOT_WORK", "additional": "REQUEST_MISSING"})
}
} else if(bod.request == "deco") {
ntr.deleteToken(bod.value)
res.send({"result":"success", "content":"VALID"})
} else if(bod.request == "edit") {
const resp = ntr.editUser(bod.value)
if(resp == true) {
res.send({"result":"success","content":"DATA_VALID"})
} else {
res.send({"result":"success","content":"EDIT_USER_FAILED"})
}
}else {
res.send({"result":"failed", "content":"ERROR_REQUEST_MISSING_FIELDS", "additional": "REQUEST_MISSING"})
}
} else {
res.send({"result":"failed", "content":"ERROR_USER_PERMISSION_TOO_LOW"})
}
}
})
module.exports = router;

View File

@ -1,11 +1,10 @@
// Import our custom CSS // Import our custom CSS
import '../scss/styles.scss'
import '@fortawesome/fontawesome-free/css/all.css' import '@fortawesome/fontawesome-free/css/all.css'
import '../scss/styles.scss'
// Import all of Bootstrap's JS // Import all of Bootstrap's JS
import * as bootstrap from 'bootstrap' import * as bootstrap from 'bootstrap'
import * as jquery from 'jquery' import JQuery from 'jquery';
window.$ = window.JQuery = JQuery;
console.log("Webpack Loaded"); console.log("Webpack Loaded");

View File

@ -1,11 +0,0 @@
{
"username": "root",
"password": "U2FsdGVkX183RDwFR0hVxkFizv9rTwppNiaWkUVowis=",
"uuid": "24a17fe1-32c3-4269-b83b-88b6bcd66cef",
"fullname": "Admin",
"token": {
"tokenID": "5aefa3fc-1e35-4195-89ab-b1603e867a51",
"livableToken": true,
"createdAt": 1676914169253
}
}

View File

@ -1,11 +1,13 @@
{ {
"username": "raphix", "username": "raphix",
"password": "U2FsdGVkX195kOSeYbWRWFD3ys/5ubkaNSm9XacK0OE=", "password": "U2FsdGVkX1+y5WFBRAA0GITGyxl0AOq2lygx7XDu6BU=",
"uuid": "9ace80e0-1ee3-4eed-924f-8a55fc55822b", "uuid": "9ace80e0-1ee3-4eed-924f-8a55fc55822b",
"permissionLevel": 4,
"fullname": "Raphael PICOT", "fullname": "Raphael PICOT",
"token": { "token": {
"tokenID": "1679485c-2139-4939-a429-56480bba0336", "tokenID": "43b6f1bf-29be-4801-83f2-b1e85dcb3981",
"livableToken": true, "livableToken": true,
"createdAt": 1676925451610 "createdAt": 1677070566103
} },
"lastconnexion": 1677070621299
} }

View File

@ -0,0 +1,9 @@
{
"username": "root",
"password": "U2FsdGVkX18KoGGTPqZw/E9PiLQaUuEZxyHdbdAErO0=",
"uuid": "aca3c9aa-5b42-477f-b179-f33211a425d3",
"fullname": "Administrateur",
"permissionLevel": 3,
"token": {},
"lastconnexion": 0
}