Aggiornata Chiave Segreta per accesso SIGNCODE.
- Inserito autenticazione MongoDB ai database. -PCB: Aggiunto altri campi a products
This commit is contained in:
30
.env.prod.pcb
Normal file
30
.env.prod.pcb
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
DATABASE=PiuCheBuono
|
||||||
|
UDB=paofreeplanet
|
||||||
|
PDB=suerteFreePlanet@1A
|
||||||
|
SEND_EMAIL=1
|
||||||
|
PORT=3000
|
||||||
|
appTelegram_TEST=["17"]
|
||||||
|
appTelegram=["17"]
|
||||||
|
ENABLE_PUSHNOTIFICATION=1
|
||||||
|
DIRECTORY_SERVER=freeplanet_serverside
|
||||||
|
SERVERDIR_WEBSITE=www.freeplanet_server
|
||||||
|
PORT_APP1="0"
|
||||||
|
DOMAIN=mongodb://localhost:32001/
|
||||||
|
AUTH_MONGODB=true
|
||||||
|
MONGODB_USER=admin
|
||||||
|
MONGODB_PWD=mypwadminREAL@1A
|
||||||
|
SIGNCODE=SU2134hncaskjdbo231oihJSDNHEI$1@AB
|
||||||
|
DEBUG=0
|
||||||
|
LOCALE=0
|
||||||
|
DELAY_SENDEMAIL=1000
|
||||||
|
VAPI_KEY_SUBJECT="mailto:surya@riso.app"
|
||||||
|
PUBLIC_VAPI_KEY="BJgo8XR_upbnbMLWgCAUELo6DK7dRXffYAnFOxbaMMz5favBgcQBKT-eISqouO-jRad4Sw8l5nd2wCF6KorGiTc"
|
||||||
|
PRIVATE_VAPI_KEY="LVpFDJuKscdHuQr5pe20dFuYuWX1-ZRb6x72PP-Pp4I"
|
||||||
|
GCM_API_KEY="AIzaSyD7w1jztfVV05mX1iyxoI-r1pZWxuxdUK8"
|
||||||
|
PATH_CERT_KEY=key.pem
|
||||||
|
PATH_SERVER_CRT=cert.pem
|
||||||
|
PATH_SSL_ROOT_PEM=root.pem
|
||||||
|
PATH_SSL_CHAIN_PEM=chain.pem
|
||||||
|
PROD=0
|
||||||
|
PROJECT_DESCR_MAIN='__PROJECTS'
|
||||||
|
SECRK=iUUb38v23jjDFaosWj92axkBOXCQ
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
DATABASE=FreePlanet
|
DATABASE=test_PiuCheBuono
|
||||||
UDB=paofreeplanet
|
UDB=paofreeplanet
|
||||||
PDB=suerteFreePlanet@1A
|
PDB=suerteFreePlanet@1A
|
||||||
SEND_EMAIL=1
|
SEND_EMAIL=1
|
||||||
PORT=3001
|
PORT=3001
|
||||||
|
appTelegram_TEST=["17"]
|
||||||
|
appTelegram=["17"]
|
||||||
ENABLE_PUSHNOTIFICATION=1
|
ENABLE_PUSHNOTIFICATION=1
|
||||||
DIRECTORY_SERVER=freeplanet_serverside
|
DIRECTORY_SERVER=freeplanet_serverside
|
||||||
SERVERDIR_WEBSITE=test.freeplanet_server
|
SERVERDIR_WEBSITE=test.freeplanet_server
|
||||||
PORT_APP1="0"
|
PORT_APP1="0"
|
||||||
DOMAIN=mongodb://localhost:27018/
|
DOMAIN=mongodb://localhost:32002/
|
||||||
SIGNCODE=abc123
|
AUTH_MONGODB=true
|
||||||
|
MONGODB_USER=admin
|
||||||
|
MONGODB_PWD=mypwadmin@1A
|
||||||
|
SIGNCODE=SU2134hncaskjdbo231oihJSDNHEI$1@AB
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
LOCALE=0
|
LOCALE=0
|
||||||
DELAY_SENDEMAIL=1000
|
DELAY_SENDEMAIL=1000
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ DIRECTORY_SERVER=freeplanet_serverside
|
|||||||
SERVERDIR_WEBSITE=test.freeplanet_server
|
SERVERDIR_WEBSITE=test.freeplanet_server
|
||||||
PORT_APP1="0"
|
PORT_APP1="0"
|
||||||
DOMAIN=mongodb://localhost:27018/
|
DOMAIN=mongodb://localhost:27018/
|
||||||
SIGNCODE=abc123
|
SIGNCODE=SU2134hncaskjdbo231oihJSDNHEI$1@AB
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
LOCALE=0
|
LOCALE=0
|
||||||
DELAY_SENDEMAIL=1000
|
DELAY_SENDEMAIL=1000
|
||||||
|
|||||||
@@ -38,22 +38,30 @@ const options = {
|
|||||||
// keepAliveInitialDelay: 300000 // keepAliveInitialDelay is the number of milliseconds to wait before initiating keepAlive on the socket.
|
// keepAliveInitialDelay: 300000 // keepAliveInitialDelay is the number of milliseconds to wait before initiating keepAlive on the socket.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (process.env.AUTH_MONGODB) {
|
||||||
|
options.auth = {
|
||||||
|
authSource: "admin",
|
||||||
|
poolSize: 10,
|
||||||
|
user: process.env.MONGODB_USER,
|
||||||
|
password: process.env.MONGODB_PWD,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const db = mongoose.connection;
|
const db = mongoose.connection;
|
||||||
|
|
||||||
|
|
||||||
// mongoose.connect(process.env.MONGODB_URI + '?authSource=admin', { options })
|
|
||||||
// console.log(' -> PASSAGGIO PARAMETRI MONGOOSE')
|
|
||||||
console.log('Node Version ' + process.version);
|
console.log('Node Version ' + process.version);
|
||||||
console.log('Mongoose Version ' + mongoose.version);
|
console.log('Mongoose Version ' + mongoose.version);
|
||||||
console.log('Connessione a ' + process.env.MONGODB_URI + ' in corso...');
|
|
||||||
mongoose.connect(process.env.MONGODB_URI, options);
|
connectionUrl = process.env.MONGODB_URI;
|
||||||
|
|
||||||
|
console.log('Connessione a ' + connectionUrl + ' in corso...');
|
||||||
|
mongoose.connect(connectionUrl, options);
|
||||||
|
|
||||||
db.on('error', console.error.bind(console, 'connection error:'));
|
db.on('error', console.error.bind(console, 'connection error:'));
|
||||||
db.once('open', function() {
|
db.once('open', function () {
|
||||||
// we're connected!
|
// we're connected!
|
||||||
console.log('*** CONNESSIONE EFFETTUATA ! ' + process.env.MONGODB_URI + ' db: ' + process.env.DATABASE)
|
console.log('*** CONNESSIONE EFFETTUATA ! ' + process.env.MONGODB_URI + ' db: ' + process.env.DATABASE)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {mongoose};
|
module.exports = { mongoose };
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ const productSchema = new Schema({
|
|||||||
code: {
|
code: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
codice_EAN: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
barcode: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -61,6 +67,9 @@ const productSchema = new Schema({
|
|||||||
weight: {
|
weight: {
|
||||||
type: Number
|
type: Number
|
||||||
},
|
},
|
||||||
|
vegan: {
|
||||||
|
type: Boolean
|
||||||
|
},
|
||||||
unit: {
|
unit: {
|
||||||
type: Number
|
type: Number
|
||||||
},
|
},
|
||||||
@@ -97,6 +106,15 @@ const productSchema = new Schema({
|
|||||||
img3: {
|
img3: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
ingredienti: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
valori_nutrizionali: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
note: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ mongoose.level = "F";
|
|||||||
|
|
||||||
mongoose.set('debug', false);
|
mongoose.set('debug', false);
|
||||||
|
|
||||||
|
const {ObjectID} = require('mongodb');
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
mongoose.plugin(schema => {
|
mongoose.plugin(schema => {
|
||||||
schema.options.usePushEach = true
|
schema.options.usePushEach = true
|
||||||
@@ -239,3 +241,37 @@ module.exports.findAllIdApp = async function (idapp) {
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.createFirstUserAdmin = async function () {
|
||||||
|
|
||||||
|
const { User } = require('../models/user');
|
||||||
|
const telegrambot = require('../telegram/telegrambot');
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let arrSite = await Site.find({ idapp: { $exists: true } }).lean();
|
||||||
|
|
||||||
|
for (const mysite of arrSite) {
|
||||||
|
if (mysite.idapp > 0) {
|
||||||
|
const numusers = await User.countDocuments({ idapp: mysite.idapp });
|
||||||
|
if (numusers === 0) {
|
||||||
|
// Non esistono utenti, quindi creo quello di Admin
|
||||||
|
const utenteadmin = await User.findOne({ idapp: '13', username: telegrambot.ADMIN_USER_SERVER }).lean()
|
||||||
|
|
||||||
|
const newuser = new User(utenteadmin);
|
||||||
|
newuser._id = new ObjectID();
|
||||||
|
newuser.idapp = mysite.idapp;
|
||||||
|
newuser.profile.mygroups = [];
|
||||||
|
newuser.profile.mycircuits = [];
|
||||||
|
|
||||||
|
await newuser.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error ', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
@@ -512,7 +512,8 @@ UserSchema.methods.generateAuthToken = function (req) {
|
|||||||
|
|
||||||
const access = 'auth';
|
const access = 'auth';
|
||||||
const browser = useragent;
|
const browser = useragent;
|
||||||
const token = jwt.sign({ _id: user._id.toHexString(), access },
|
const prova = 'PROVAMSG@1A'
|
||||||
|
const token = jwt.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username },
|
||||||
process.env.SIGNCODE).toString();
|
process.env.SIGNCODE).toString();
|
||||||
const date_login = new Date();
|
const date_login = new Date();
|
||||||
|
|
||||||
@@ -670,7 +671,7 @@ UserSchema.statics.findByToken = function (token, typeaccess) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return User.findOne({
|
return User.findOne({
|
||||||
'_id': decoded._id,
|
'_id': decoded.smart,
|
||||||
'tokens.token': token,
|
'tokens.token': token,
|
||||||
'tokens.access': typeaccess,
|
'tokens.access': typeaccess,
|
||||||
});
|
});
|
||||||
@@ -687,7 +688,7 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return User.findOne({
|
return User.findOne({
|
||||||
'_id': decoded._id,
|
'_id': decoded.smart,
|
||||||
'tokens.token': token,
|
'tokens.token': token,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -1290,7 +1291,7 @@ UserSchema.statics.createNewRequestPwd = function (idapp, email, code) {
|
|||||||
return { ris: false };
|
return { ris: false };
|
||||||
} else {
|
} else {
|
||||||
// Creo il tokenforgot
|
// Creo il tokenforgot
|
||||||
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
user.tokenforgot = jwt.sign({_id: 'prova123##', smart: user._id.toHexString()}, process.env.SIGNCODE).
|
||||||
toString();
|
toString();
|
||||||
user.date_tokenforgot = new Date();
|
user.date_tokenforgot = new Date();
|
||||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||||
@@ -1316,8 +1317,12 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (ida
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
const additionalData = {
|
||||||
|
code: user.username,
|
||||||
|
};
|
||||||
|
const prova = 'dasdas1231#11';
|
||||||
// Creo il tokenforgot
|
// Creo il tokenforgot
|
||||||
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
user.tokenforgot = jwt.sign({_id: prova, smart: user._id.toHexString(), ...additionalData}, process.env.SIGNCODE).
|
||||||
toString();
|
toString();
|
||||||
user.date_tokenforgot = new Date();
|
user.date_tokenforgot = new Date();
|
||||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ router.get('/:userId', authenticate, async function (req, res, next) {
|
|||||||
if (cart)
|
if (cart)
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, cart });
|
return res.send({ code: server_constants.RIS_CODE_OK, cart });
|
||||||
else
|
else
|
||||||
return res.status(400).send(e);
|
return res.send({ code: server_constants.RIS_CODE_OK, cart: null });
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error('Err', err);
|
console.error('Err', err);
|
||||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ require('./db/mongoose');
|
|||||||
|
|
||||||
const { Settings } = require('./models/settings');
|
const { Settings } = require('./models/settings');
|
||||||
|
|
||||||
|
const Site = require('./models/site');
|
||||||
|
|
||||||
// test
|
// test
|
||||||
|
|
||||||
const i18n = require('i18n');
|
const i18n = require('i18n');
|
||||||
@@ -494,6 +496,8 @@ async function inizia() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Site.createFirstUserAdmin();
|
||||||
|
|
||||||
/*const {Circuit} = require('./models/circuit');
|
/*const {Circuit} = require('./models/circuit');
|
||||||
|
|
||||||
await Circuit.setDeperimentoOff();
|
await Circuit.setDeperimentoOff();
|
||||||
|
|||||||
@@ -705,7 +705,21 @@ const MyTelegramBot = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAppTelegram: function () {
|
getAppTelegram: function () {
|
||||||
return appTelegram;
|
if (process.env.appTelegram) {
|
||||||
|
return JSON.parse(process.env.appTelegram);
|
||||||
|
} else {
|
||||||
|
return appTelegram;
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
getAppTelegramTest: function () {
|
||||||
|
if (process.env.appTelegram_TEST) {
|
||||||
|
return JSON.parse(process.env.appTelegram_TEST);
|
||||||
|
} else {
|
||||||
|
return appTelegram_TEST;
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
local_sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text,
|
local_sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text,
|
||||||
@@ -4045,11 +4059,11 @@ function getclTelegByidapp(idapp) {
|
|||||||
|
|
||||||
//if (!tools.testing() || true) {
|
//if (!tools.testing() || true) {
|
||||||
if (true) {
|
if (true) {
|
||||||
let arrTeleg = appTelegram;
|
let arrTeleg = MyTelegramBot.getAppTelegram();
|
||||||
if (process.env.NODE_ENV === 'development')
|
if (process.env.NODE_ENV === 'development')
|
||||||
arrTeleg = appTelegram_DEVELOP;
|
arrTeleg = appTelegram_DEVELOP;
|
||||||
else if (process.env.NODE_ENV === 'test')
|
else if (process.env.NODE_ENV === 'test')
|
||||||
arrTeleg = appTelegram_TEST;
|
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
||||||
|
|
||||||
var internetAvailable = require('internet-available');
|
var internetAvailable = require('internet-available');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user