- aggiornamento con proj RISO. postcss, pwa.
This commit is contained in:
@@ -30,7 +30,9 @@ const authenticate = (req, res, next) => {
|
||||
|
||||
const access = 'auth';
|
||||
|
||||
return User.findByToken(token, access, true).then((ris) => {
|
||||
const idapp = getIdApp(req);
|
||||
|
||||
return User.findByToken(token, access, true, idapp).then((ris) => {
|
||||
|
||||
if (ris && ris.user && !!ris.user.deleted) {
|
||||
if (ris.user.deleted)
|
||||
@@ -70,14 +72,26 @@ const authenticate = (req, res, next) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getIdApp = (req) => {
|
||||
let idapp = null;
|
||||
try {
|
||||
idapp = req.query.idapp;
|
||||
} catch (e) {
|
||||
console.log('IDAPP NON TROVATO !');
|
||||
}
|
||||
return idapp;
|
||||
|
||||
}
|
||||
|
||||
const authenticate_noerror = (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('x-auth');
|
||||
const refreshToken = req.header('x-refrtok');
|
||||
|
||||
const access = 'auth';
|
||||
const idapp = getIdApp(req);
|
||||
|
||||
return User.findByToken(token, access, false).then((ris) => {
|
||||
const access = 'auth';
|
||||
return User.findByToken(token, access, false, idapp).then((ris) => {
|
||||
if (ris.code !== server_constants.RIS_CODE_OK) {
|
||||
req.user = null;
|
||||
req.token = null;
|
||||
|
||||
@@ -731,7 +731,7 @@ UserSchema.statics.isFacilitatore = function (perm) {
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.findByToken = async function (token, typeaccess, con_auth) {
|
||||
UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, idapp) {
|
||||
const User = this;
|
||||
let decoded;
|
||||
let code = server_constants.RIS_CODE_HTTP_INVALID_TOKEN;
|
||||
@@ -758,10 +758,15 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth) {
|
||||
}
|
||||
|
||||
if (code === server_constants.RIS_CODE_OK) {
|
||||
|
||||
user = await User.findOne({
|
||||
'_id': decoded.smart,
|
||||
'tokens.token': token,
|
||||
'tokens.access': typeaccess,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token: token,
|
||||
access: typeaccess,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (user) {
|
||||
|
||||
@@ -72,6 +72,7 @@ router.post('/', authenticate, async (req, res) => {
|
||||
// console.log('req.body', req.body)
|
||||
|
||||
if (req.body.options !== null) {
|
||||
// Invia una notifica PUSH (asincrona)
|
||||
tools.sendBackNotif(subscription, req.body.options);
|
||||
}
|
||||
// console.log('Subscription saved... ')
|
||||
|
||||
@@ -852,7 +852,7 @@ module.exports = {
|
||||
return myrec._doc;
|
||||
},
|
||||
|
||||
sendBackNotif: function (subscription, payload) {
|
||||
sendBackNotif: async function (subscription, payload) {
|
||||
const Subscription = require('../models/subscribers');
|
||||
|
||||
// console.log('sendBackNotif:', subscription, payload);
|
||||
|
||||
Reference in New Issue
Block a user