From 7d845355a9caa37f4022e32217c763de95585fbe Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Fri, 14 Mar 2025 12:52:44 +0100 Subject: [PATCH] - fix: authenticate_withUser mancava su alcuni... - fix: '/signin' non riproponeva il login nel caso il token fosse invalido --- src/server/populate/populate.js | 1 + src/server/router/booking_router.js | 4 ++-- src/server/router/index_router.js | 16 +++++++++++----- src/server/router/users_router.js | 4 ++-- src/server/version.txt | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/server/populate/populate.js b/src/server/populate/populate.js index b5c6ea6..ffb8000 100644 --- a/src/server/populate/populate.js +++ b/src/server/populate/populate.js @@ -78,6 +78,7 @@ module.exports = { console.log(' ... Non inserito !'); } + } else { // Il documento esiste, lo aggiorniamo const ris = await table.updateOne({ _id: existingDoc._id }, { $set: rec }); diff --git a/src/server/router/booking_router.js b/src/server/router/booking_router.js index a39c2f9..a9139ce 100755 --- a/src/server/router/booking_router.js +++ b/src/server/router/booking_router.js @@ -4,7 +4,7 @@ const router = express.Router(); const tools = require('../tools/general'); const server_constants = require('../tools/server_constants'); -const { authenticate } = require('../middleware/authenticate'); +const { authenticate, authenticate_withUser } = require('../middleware/authenticate'); const { Booking } = require('../models/booking'); @@ -24,7 +24,7 @@ const sendNotifBooking = async (res, idapp, user, recbooking) => { return await sendemail.sendEmail_CancelBooking(res, user.lang, user.email, user, idapp, recbooking); }; -router.post('/', authenticate, (req, res) => { +router.post('/', authenticate_withUser, (req, res) => { // tools.mylog('INIZIO - booking'); // tools.mylog('req.body', req.body); const myrec = _.pick(req.body, tools.allfieldBooking()); diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index a1da18a..7d05d9e 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -1813,11 +1813,11 @@ async function testMongoPerformance(ind, iterations = 20) { if (ind === 1) { await User.findOne({}).lean(); } else { - const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJQUk9WQU1TR0AxQSIsInNtYXJ0IjoiNjIwODAwYWRjMTI5ZDFlYmE3NjBiZWNiIiwiYWNjZXNzIjoiYXV0aCIsInVuIjoic3VyeWExOTc3IiwiaWF0IjoxNzQxODcyMzEwLCJleHAiOjE3NDE4Nzk1MTB9.SXJLmsS6EZVhaU7sUWYMnaqGpiiy8RfE9K43xTdxNuU'; + const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJQUk9WQU1TR0AxQSIsInNtYXJ0IjoiNjIwODAwYWRjMTI5ZDFlYmE3NjBiZWNiIiwiYWNjZXNzIjoiYXV0aCIsInVuIjoic3VyeWExOTc3IiwiaWF0IjoxNzQxODcyMzEwLCJleHAiOjE3NDE4Nzk1MTB9.SXJLmsS6EZVhaU7sUWYMnaqGpiiy8RfE9K43xTdxNuU'; await User.findByToken(token, 'auth', true, true); } - + } catch (err) { log(`Errore nell'iterazione ${i + 1}: ${err.message}`); } @@ -1917,9 +1917,14 @@ async function load(req, res, version = '0') { // Estrazione e validazione degli input const userId = req.user ? req.user._id.toString() : req.params.userId || '0'; const idapp = req.params.idapp; - const status = req.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED + /*const status = req.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED ? server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED - : 200; + : 200;*/ + + let status = req.code; + if (status === server_constants.RIS_CODE_OK) { + status = 200; + } // Determina se l'utente ha determinati permessi const gestoredelSito = req.user && @@ -2118,7 +2123,8 @@ async function load(req, res, version = '0') { catalogs: data.catalogs, catprtotali: data.catprtotali }; - } + } + // console.log(' ... 2) load dati caricati ...'); res.status(status).send(responseData); diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js index 56265b7..11640b2 100755 --- a/src/server/router/users_router.js +++ b/src/server/router/users_router.js @@ -861,7 +861,7 @@ router.post('/groups', authenticate, (req, res) => { }); -router.post('/circuits', authenticate, (req, res) => { +router.post('/circuits', authenticate_withUser, (req, res) => { const username = req.user.username; idapp = req.body.idapp; locale = req.body.locale; @@ -1800,7 +1800,7 @@ router.post('/infomap', authenticate, async (req, res) => { }); -router.post('/mgt', authenticate, async (req, res) => { +router.post('/mgt', authenticate_withUser, async (req, res) => { const mydata = req.body.mydata; idapp = req.body.idapp; diff --git a/src/server/version.txt b/src/server/version.txt index f37ae4a..e54077f 100644 --- a/src/server/version.txt +++ b/src/server/version.txt @@ -1 +1 @@ -1.2.19 \ No newline at end of file +1.2.21 \ No newline at end of file