- corretto problema ROGNOSO : Risolvere la questione "Sessioni multiple", se apro 2 browser l'ultimo va a cancellare il precedente, e mi da errore di email non valida !
Il problema era sulla fetch nel service worker, gestita in quel modo personalizzato, andava in conflitto, non tenendo le chiamate bloccanti, ma uscivano prima che arrivasse la risposta del server. - Per chi è da tanto che non si collega a RISO, compare "Email non verificata"... (si risolve chiudendo su ESCI e riloggandosi)... però andrebbe sistemata. (stesso problema di prima).
This commit is contained in:
@@ -1858,8 +1858,13 @@ router.post('/duprec/:table/:id', authenticate, async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, (req, res) => {
|
||||
load(req, res, '0');
|
||||
router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, async (req, res) => {
|
||||
try {
|
||||
await load(req, res, '0');
|
||||
} catch (e) {
|
||||
console.error('loadsite error', e);
|
||||
res.status(500).send({ error: 'Impossibile caricare il sito' });
|
||||
}
|
||||
});
|
||||
|
||||
// Funzione di test per misurare le performance di MongoDB
|
||||
@@ -2073,6 +2078,7 @@ async function load(req, res, version = '0') {
|
||||
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
||||
raccoltacataloghis: version >= 91 ? RaccoltaCataloghi.findAllIdApp(idapp) : Promise.resolve([]),
|
||||
myuserextra: req.user ? User.addExtraInfo(idapp, req.user, version) : Promise.resolve(null),
|
||||
statuscode2: version >= 91 ? req.statuscode2 : Promise.resolve([]),
|
||||
};
|
||||
|
||||
// Esecuzione parallela di tutte le promesse
|
||||
@@ -2187,6 +2193,7 @@ async function load(req, res, version = '0') {
|
||||
tipoformato: data.tipoformato,
|
||||
crons: data.crons,
|
||||
raccoltacataloghis: data.raccoltacataloghis,
|
||||
statuscode2: data.statuscode2,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2203,7 +2210,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
||||
|
||||
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
||||
if (!req.user) {
|
||||
return res.status(200).send();
|
||||
return res.status(req.code).send();
|
||||
}
|
||||
|
||||
await CfgServer.find({ idapp })
|
||||
|
||||
@@ -27,11 +27,9 @@ router.post('/', authenticate, async (req, res) => {
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, notif: '' });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const qualinotif = parseInt(req.params.qualinotif);
|
||||
@@ -58,11 +56,9 @@ router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
} catch (e) {
|
||||
res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const _id = req.params._id;
|
||||
const username_call = req.user.username;
|
||||
|
||||
@@ -76,19 +72,14 @@ router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||
return res.send(true);
|
||||
}
|
||||
res.send(false);
|
||||
|
||||
} catch (e) {
|
||||
res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
async function delNotif(res, idapp, username, id, username_call) {
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
|
||||
await SendNotif.findOneAndDelete({ idapp, _id: id });
|
||||
return res.send(true);
|
||||
}
|
||||
@@ -97,22 +88,17 @@ async function delNotif(res, idapp, username, id, username_call) {
|
||||
}
|
||||
|
||||
return res.send(false);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
return delNotif(res, req.params.idapp, req.params.username, req.params.id, req.user.username);
|
||||
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const qualinotif = parseInt(req.params.qualinotif);
|
||||
@@ -128,15 +114,13 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||
}
|
||||
const ris = await SendNotif.deleteMany(query);
|
||||
if (ris)
|
||||
return res.send(true);
|
||||
if (ris) return res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
return res.send(false);
|
||||
|
||||
});
|
||||
|
||||
router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) => {
|
||||
@@ -144,7 +128,6 @@ router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) =
|
||||
});
|
||||
|
||||
async function getNotif(req, res) {
|
||||
|
||||
try {
|
||||
// tools.mylog('GET NotifS : ', req.params);
|
||||
const username = req.params.username;
|
||||
@@ -152,33 +135,54 @@ async function getNotif(req, res) {
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
// var category = req.params.category;
|
||||
if (!req.user) {
|
||||
return res.status(200).send();
|
||||
}
|
||||
|
||||
if (req.user.idapp !== idapp) {
|
||||
// I'm trying to get something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
||||
}
|
||||
|
||||
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
|
||||
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||
username,
|
||||
lastdataread,
|
||||
idapp,
|
||||
shared_consts.LIMIT_NOTIF_FOR_USER,
|
||||
shared_consts.QualiNotifs.OTHERS
|
||||
);
|
||||
let arrnotifcoins_inattesa = null;
|
||||
|
||||
if (await User.isAdminByUsername(idapp, req.user.username)) {
|
||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
|
||||
} else {
|
||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: 0 }]);
|
||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||
username,
|
||||
lastdataread,
|
||||
idapp,
|
||||
shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER,
|
||||
shared_consts.QualiNotifs.CIRCUITS,
|
||||
[{ status: 0 }]
|
||||
);
|
||||
}
|
||||
|
||||
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: {$ne: 0 }}]);
|
||||
|
||||
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||
username,
|
||||
lastdataread,
|
||||
idapp,
|
||||
shared_consts.LIMIT_NOTIFCOINS_FOR_USER,
|
||||
shared_consts.QualiNotifs.CIRCUITS,
|
||||
[{ status: { $ne: 0 } }]
|
||||
);
|
||||
|
||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||
|
||||
return res.send({ arrnotif, arrnotifcoins: [...arrnotifcoins, ...arrnotifcoins_inattesa], userprofile });
|
||||
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -94,13 +94,16 @@ router.delete('/del', authenticate, async (req, res) => {
|
||||
// tools.mylog("TOKENREM = " + req.token);
|
||||
try {
|
||||
|
||||
const browser = req.get('User-Agent');
|
||||
return await Subscription.findOneAndDelete(
|
||||
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
||||
res.status(200).send();
|
||||
}, () => {
|
||||
res.status(400).send();
|
||||
});
|
||||
if (req.user) {
|
||||
const browser = req.get('User-Agent');
|
||||
return await Subscription.findOneAndDelete(
|
||||
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
||||
res.status(200).send();
|
||||
}, () => {
|
||||
res.status(400).send();
|
||||
});
|
||||
}
|
||||
res.status(400).send();
|
||||
} catch (e) {
|
||||
console.error('Err:', e.message);
|
||||
}
|
||||
|
||||
@@ -659,8 +659,8 @@ router.post('/newtok', async (req, res) => {
|
||||
return res.status(400).send({ error: 'Refresh token mancante' });
|
||||
}
|
||||
|
||||
const recFound = await User.findOne({ 'tokens.refreshToken': refreshToken });
|
||||
|
||||
const recFound = await User.findByRefreshTokenAnyAccess(refreshToken);
|
||||
|
||||
if (!recFound) {
|
||||
return res.status(403).send({ error: 'Refresh token non valido' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user