- 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:
@@ -253,11 +253,15 @@ CatalogSchema.statics.getCatalogById = async function (id) {
|
||||
model: 'Gasordine',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// controlla prima se nella lista ci sono dei product che non esistono piu allora li devi rimuovere !
|
||||
for (const catalog of arrrec) {
|
||||
let old_lista = [...catalog.lista_prodotti];
|
||||
|
||||
let nuova_lista = [...catalog.lista_prodotti];
|
||||
|
||||
const originalLength = catalog.lista_prodotti.length;
|
||||
catalog.lista_prodotti = catalog.lista_prodotti.filter(
|
||||
nuova_lista = nuova_lista.filter(
|
||||
(product) =>
|
||||
product.productInfo &&
|
||||
product.productInfo.code &&
|
||||
@@ -266,11 +270,21 @@ CatalogSchema.statics.getCatalogById = async function (id) {
|
||||
product.productInfo.imagefile !== 'noimg.jpg' &&
|
||||
!product.delete
|
||||
);
|
||||
if (catalog.lista_prodotti.length !== originalLength) {
|
||||
await catalog.save();
|
||||
|
||||
// Se la nuova lista è diversa da quella precedente di più del 10%, allora non aggiorna, perché potrebbe esserci un problema
|
||||
let differencePercentage = (100 * Math.abs(originalLength - nuova_lista.length)) / originalLength;
|
||||
if (differencePercentage < 10) {
|
||||
// Aggiorno la lista solo se è cambiata poco
|
||||
// confronta l'array nuova_lista con l'array catalog.lista_prodotti
|
||||
let differents = tools.areDifferentProduct(catalog.lista_prodotti, nuova_lista);
|
||||
|
||||
if (differents) {
|
||||
// aggiorna la lista
|
||||
catalog.lista_prodotti = nuova_lista;
|
||||
await catalog.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const transformedArrRec = arrrec.map((catalog) => ({
|
||||
...catalog.toObject(), // Converte il documento Mongoose in un oggetto JavaScript puro
|
||||
|
||||
@@ -15,7 +15,7 @@ const { MyGroup } = require('./mygroup');
|
||||
const tableModel = shared_consts.TABLES_MYBACHECAS;
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
mongoose.plugin((schema) => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
@@ -43,32 +43,37 @@ const MyBachecaSchema = new Schema({
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
},
|
||||
],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
},
|
||||
],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
},
|
||||
],
|
||||
dateTimeStart: {
|
||||
type: Date,
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
required: false, // non obbligatorio
|
||||
default: null, // valore predefinito esplicito (opzionale)
|
||||
},
|
||||
organisedBy: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
contact_phone: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
contact_email: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
contact_telegram: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
@@ -103,7 +108,8 @@ const MyBachecaSchema = new Schema({
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
},
|
||||
],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
@@ -121,15 +127,17 @@ const MyBachecaSchema = new Schema({
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
link_conference: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions(),
|
||||
...tools.getFieldsForAnnunci()
|
||||
...tools.getFieldsForAnnunci(),
|
||||
});
|
||||
|
||||
MyBachecaSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created) this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
@@ -138,13 +146,9 @@ MyBachecaSchema.pre('save', async function (next) {
|
||||
MyBachecaSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MyBacheca = this;
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
const query = [{ $match: { idapp } }, { $sort: { descr: 1 } }];
|
||||
|
||||
return await MyBacheca.aggregate(query);
|
||||
|
||||
};
|
||||
|
||||
MyBachecaSchema.statics.getFieldsForSearch = function () {
|
||||
@@ -160,7 +164,6 @@ MyBachecaSchema.statics.getFieldsLastForSearch = function () {
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
@@ -184,16 +187,14 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
|
||||
let myparsid = {
|
||||
'_id': id,
|
||||
_id: id,
|
||||
idapp,
|
||||
};
|
||||
|
||||
let query = [
|
||||
{
|
||||
$match:
|
||||
myparsid,
|
||||
$match: myparsid,
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
@@ -202,28 +203,25 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
'myId1': {
|
||||
'$toObjectId': '$userId',
|
||||
myId1: {
|
||||
$toObjectId: '$userId',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'users',
|
||||
'localField': 'myId1',
|
||||
'foreignField': '_id',
|
||||
'as': 'user',
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
localField: 'myId1',
|
||||
foreignField: '_id',
|
||||
as: 'user',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$user',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$user', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -234,22 +232,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'skills',
|
||||
'localField': 'idSkill',
|
||||
'foreignField': '_id',
|
||||
'as': 'recSkill',
|
||||
$lookup: {
|
||||
from: 'skills',
|
||||
localField: 'idSkill',
|
||||
foreignField: '_id',
|
||||
as: 'recSkill',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$recSkill',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$recSkill', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -260,22 +255,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'sectors',
|
||||
'localField': 'idSector',
|
||||
'foreignField': '_id',
|
||||
'as': 'sector',
|
||||
$lookup: {
|
||||
from: 'sectors',
|
||||
localField: 'idSector',
|
||||
foreignField: '_id',
|
||||
as: 'sector',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$sector',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$sector', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -284,10 +276,10 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
'from': 'mygroups',
|
||||
'localField': 'groupname',
|
||||
'foreignField': 'groupname',
|
||||
'as': 'mygrp',
|
||||
from: 'mygroups',
|
||||
localField: 'groupname',
|
||||
foreignField: 'groupname',
|
||||
as: 'mygrp',
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -308,14 +300,11 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},*/
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$MyBacheca',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$MyBacheca', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -326,22 +315,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'cities',
|
||||
'localField': 'idCity',
|
||||
'foreignField': '_id',
|
||||
'as': 'mycities',
|
||||
$lookup: {
|
||||
from: 'cities',
|
||||
localField: 'idCity',
|
||||
foreignField: '_id',
|
||||
as: 'mycities',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$mycities',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$mycities', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -370,20 +356,18 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
return MyBacheca.getMyRecById(idapp, id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
const MyBacheca = mongoose.model('MyBacheca', MyBachecaSchema);
|
||||
|
||||
MyBacheca.createIndexes()
|
||||
.then(() => { })
|
||||
.catch((err) => { throw err; });
|
||||
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
module.exports = { MyBacheca };
|
||||
|
||||
@@ -39,6 +39,8 @@ const MyEventSchema = new Schema({
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
required: false, // non obbligatorio
|
||||
default: null, // valore predefinito esplicito (opzionale)
|
||||
},
|
||||
bgcolor: {
|
||||
type: String,
|
||||
|
||||
@@ -551,7 +551,6 @@ UserSchema.methods.toJSON = function () {
|
||||
};
|
||||
|
||||
UserSchema.methods.generateAuthToken = function (req) {
|
||||
// console.log("GENERA TOKEN : ");
|
||||
const user = this;
|
||||
|
||||
const useragent = req.get('User-Agent');
|
||||
@@ -568,34 +567,37 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
|
||||
if (attiva_scadenza)
|
||||
token = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||
expiresIn: numsec,
|
||||
})
|
||||
.toString();
|
||||
else
|
||||
token = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE)
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE)
|
||||
.toString();
|
||||
|
||||
const refreshToken = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
||||
expiresIn: process.env.REFRESH_TOKEN_LIFE,
|
||||
})
|
||||
.toString();
|
||||
const date_login = new Date();
|
||||
|
||||
// CANCELLA IL PRECEDENTE !
|
||||
user.tokens = user.tokens.filter(function (tok) {
|
||||
return tok.access !== access || (tok.access === access && tok.browser !== browser);
|
||||
});
|
||||
|
||||
user.tokens.push({ access, browser, token, date_login, refreshToken });
|
||||
// Controlla se il token è già presente per la coppia access-browser
|
||||
const idx = user.tokens.findIndex((tok) => tok.access === access && tok.browser === browser);
|
||||
if (idx === -1) {
|
||||
user.tokens.push({ access, browser, token, date_login, refreshToken });
|
||||
} else {
|
||||
// Se il token esiste già, sostituisce il valore vecchio con il nuovo
|
||||
user.tokens[idx] = { access, browser, token, date_login, refreshToken };
|
||||
}
|
||||
|
||||
user.lasttimeonline = new Date();
|
||||
|
||||
return user
|
||||
.save()
|
||||
.then(() => {
|
||||
console.log('########## HO CREATO UN NUOVO TOKEN E REFRESHTOKEN !!!!! ----------- ');
|
||||
return { token, refreshToken };
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -811,7 +813,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
if (withlean) {
|
||||
user = await User.findOne(
|
||||
{
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token,
|
||||
@@ -824,7 +826,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
} else {
|
||||
user = await User.findOne(
|
||||
{
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token,
|
||||
@@ -852,7 +854,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
const start_find = process.hrtime.bigint();
|
||||
user = await User.findOne(
|
||||
{
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token,
|
||||
@@ -893,11 +895,28 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
'tokens.token': token,
|
||||
}).lean();
|
||||
};
|
||||
|
||||
UserSchema.statics.findByRefreshTokenAnyAccess = function (refreshToken) {
|
||||
const User = this;
|
||||
let decoded;
|
||||
|
||||
try {
|
||||
decoded = jwt.verify(refreshToken, process.env.SECRK);
|
||||
} catch (e) {
|
||||
console.error('Err findByRefreshTokenAnyAccess:', e);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
_id: decoded._id,
|
||||
'tokens.refreshToken': refreshToken,
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.findByCredentials = async function (idapp, username, password, pwdcrypted) {
|
||||
const User = this;
|
||||
let pwd = '';
|
||||
@@ -1583,7 +1602,7 @@ UserSchema.statics.createNewRequestPwd = function (idapp, email, code) {
|
||||
} else {
|
||||
// Creo il tokenforgot
|
||||
user.tokenforgot = jwt
|
||||
.sign({ _id: 'prova123##', smart: user._id.toHexString() }, process.env.SIGNCODE)
|
||||
.sign({ _id: user._id.toHexString() }, process.env.SIGNCODE)
|
||||
.toString();
|
||||
user.date_tokenforgot = new Date();
|
||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||
@@ -1621,7 +1640,7 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (ida
|
||||
const prova = 'dasdas1231#11';
|
||||
// Creo il tokenforgot
|
||||
user.tokenforgot = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), ...additionalData }, process.env.SIGNCODE)
|
||||
.sign({ _id: user._id.toHexString(), ...additionalData }, process.env.SIGNCODE)
|
||||
.toString();
|
||||
user.date_tokenforgot = new Date();
|
||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||
|
||||
Reference in New Issue
Block a user