- aggiornamento refreshtoken (parte 1)

- PCB: fix listino
This commit is contained in:
Surya Paolo
2024-04-09 21:56:50 +02:00
parent 3221cf8d25
commit 07c210c59e
17 changed files with 280 additions and 112 deletions

View File

@@ -253,14 +253,15 @@ router.post(process.env.LINK_UPDATE_PWD, async (req, res) => {
user.lasttimeonline = new Date();
// Crea token
user.generateAuthToken(req).then(token => {
user.generateAuthToken(req).then(ris => {
user.tokenforgot = ''; // Svuota il tokenforgot perché non ti servirà più...
user.tokenforgot_code = ''; // Svuota il tokenforgot perché non ti servirà più...
// Salva lo User
user.save().then(() => {
res.header('x-auth', token).
send({ code: server_constants.RIS_CODE_OK }); // Ritorna il token di ritorno
res.header('x-auth', ris.token)
.header('x-refrTok', ris.refreshToken)
.send({ code: server_constants.RIS_CODE_OK }); // Ritorna il token di ritorno
});
});
}
@@ -344,7 +345,7 @@ router.post('/settable', authenticate, async (req, res) => {
&& !User.isEditor(req.user.perm)
&& !User.isFacilitatore(req.user.perm))
&&
await !tools.ModificheConsentite(req, params.table, fieldsvalue, mydata ? mydata._id: '')) {
await !tools.ModificheConsentite(req, params.table, fieldsvalue, mydata ? mydata._id : '')) {
// If without permissions, exit
return res.status(404).
send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
@@ -768,14 +769,15 @@ router.post('/getpage', async (req, res) => {
const mypath = params.path;
let found = await MyPage.findOne({ idapp, path: mypath }).then((ris) => {
if (ris)
return res.send({ mypage: ris });
if (ris && ris._doc)
return res.send({ mypage: ris._doc });
else
return null;
}).catch((e) => {
console.log(e.message);
res.status(400).send(e);
});
if (!found) {
// trova quelli con il :
let regexp = new RegExp(`:`, 'ig')
@@ -1415,7 +1417,7 @@ function load(req, res, version) {
let socioresidente = false;
if (!!req.user)
if (req.user)
socioresidente = req.user.profile.socioresidente;
if (userId !== '0') {
@@ -1673,13 +1675,11 @@ function load(req, res, version) {
}
router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
const userId = req.user._id;
router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res) => {
const idapp = req.query.idapp;
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
if (!ObjectID.isValid(userId)) {
if (!req.user) {
return res.status(404).send();
}
@@ -1690,22 +1690,31 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
// ++Add to Log Stat ....
let last_msgs = null;
let last_notifs = null;
let usersList = null;
// const sall = '0';
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
let last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
let usersList = null;
if (req.user) {
// If User is Admin, then send user Lists
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) ||
User.isManager(req.user.perm)) {
// Send UsersList
usersList = User.getUsersList(idapp);
// usersList = null;
const userId = req.user._id;
if (!ObjectID.isValid(userId)) {
return res.status(404).send();
}
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
if (req.user) {
// If User is Admin, then send user Lists
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) ||
User.isManager(req.user.perm)) {
// Send UsersList
usersList = User.getUsersList(idapp);
// usersList = null;
}
}
}