DEV_
This commit is contained in:
@ -10,7 +10,7 @@ router.get('/', function(req, res, next) {
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
|
||||
if(check == false) {
|
||||
if(check.name == false) {
|
||||
|
||||
res.redirect(302, "/login")
|
||||
|
||||
@ -27,7 +27,7 @@ router.post("/", function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
if(check == false) {
|
||||
if(check.name == false) {
|
||||
|
||||
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") {
|
||||
|
||||
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") {
|
||||
|
||||
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 {
|
||||
|
||||
res.send({"result":"failed", "content":"ERROR_REQUEST_NOT_VALID"})
|
||||
|
@ -7,15 +7,15 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
|
||||
if(check == false) {
|
||||
if(check.name == false) {
|
||||
|
||||
res.redirect(302, "/login")
|
||||
|
||||
} 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">' });
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
if(check != false) {
|
||||
if(check.name != false) {
|
||||
|
||||
res.redirect(302, "/")
|
||||
|
||||
|
@ -12,7 +12,7 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
if(check != false) {
|
||||
if(check.name != false) {
|
||||
|
||||
res.redirect(302, "/")
|
||||
|
||||
@ -27,7 +27,7 @@ router.post("/", function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
if(check == false) {
|
||||
if(check.name == false) {
|
||||
|
||||
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
|
||||
|
||||
|
@ -13,7 +13,7 @@ router.get('/', function(req, res, next) {
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
|
||||
if(check == false) {
|
||||
if(check.name == false) {
|
||||
|
||||
res.redirect(302, "/login")
|
||||
|
||||
|
118
routes/upload.js
118
routes/upload.js
@ -13,7 +13,7 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
if(check != false) {
|
||||
if(check.name != false) {
|
||||
|
||||
res.redirect(302, "/")
|
||||
|
||||
@ -28,7 +28,7 @@ router.post("/", function(req, res, next) {
|
||||
|
||||
var check = ntr.checkToken(req, res)
|
||||
|
||||
if(check == false) {
|
||||
if(check.name == false) {
|
||||
|
||||
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
|
||||
|
||||
@ -37,19 +37,118 @@ router.post("/", function(req, res, next) {
|
||||
|
||||
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 uploadDir = __dirname.replace("routes","public" + path.sep + "images" + path.sep + "userspics" + path.sep)
|
||||
|
||||
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") {
|
||||
|
||||
uploadPath = ntr.checkToken(req, res) + ".jpg"
|
||||
uploadPath = ntr.checkToken(req, res).name + ".jpg"
|
||||
}
|
||||
|
||||
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)
|
||||
@ -74,7 +173,7 @@ router.post("/", function(req, res, next) {
|
||||
image.resize(200,200, function(err){
|
||||
if (err) throw err;
|
||||
}).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>",})
|
||||
|
||||
@ -128,6 +227,7 @@ router.post("/", function(req, res, next) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
140
routes/usermanager.js
Normal file
140
routes/usermanager.js
Normal 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;
|
Reference in New Issue
Block a user