Aggiornata Chiave Segreta per accesso SIGNCODE.

- Inserito autenticazione MongoDB ai database.
-PCB: Aggiunto altri campi a products
This commit is contained in:
Surya Paolo
2023-12-07 08:34:24 +01:00
parent d5bc76335f
commit 4871c2d868
10 changed files with 140 additions and 20 deletions

View File

@@ -8,6 +8,8 @@ mongoose.level = "F";
mongoose.set('debug', false);
const {ObjectID} = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
@@ -239,3 +241,37 @@ module.exports.findAllIdApp = async function (idapp) {
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);
}
};