Aggiornata Chiave Segreta per accesso SIGNCODE.
- Inserito autenticazione MongoDB ai database. -PCB: Aggiunto altri campi a products
This commit is contained in:
@@ -28,6 +28,12 @@ const productSchema = new Schema({
|
||||
code: {
|
||||
type: String,
|
||||
},
|
||||
codice_EAN: {
|
||||
type: String,
|
||||
},
|
||||
barcode: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
@@ -61,6 +67,9 @@ const productSchema = new Schema({
|
||||
weight: {
|
||||
type: Number
|
||||
},
|
||||
vegan: {
|
||||
type: Boolean
|
||||
},
|
||||
unit: {
|
||||
type: Number
|
||||
},
|
||||
@@ -97,6 +106,15 @@ const productSchema = new Schema({
|
||||
img3: {
|
||||
type: String,
|
||||
},
|
||||
ingredienti: {
|
||||
type: String,
|
||||
},
|
||||
valori_nutrizionali: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -512,7 +512,8 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
|
||||
const access = 'auth';
|
||||
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();
|
||||
const date_login = new Date();
|
||||
|
||||
@@ -670,7 +671,7 @@ UserSchema.statics.findByToken = function (token, typeaccess) {
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
'_id': decoded._id,
|
||||
'_id': decoded.smart,
|
||||
'tokens.token': token,
|
||||
'tokens.access': typeaccess,
|
||||
});
|
||||
@@ -687,7 +688,7 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
'_id': decoded._id,
|
||||
'_id': decoded.smart,
|
||||
'tokens.token': token,
|
||||
});
|
||||
};
|
||||
@@ -1290,7 +1291,7 @@ UserSchema.statics.createNewRequestPwd = function (idapp, email, code) {
|
||||
return { ris: false };
|
||||
} else {
|
||||
// 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();
|
||||
user.date_tokenforgot = new Date();
|
||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||
@@ -1316,8 +1317,12 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (ida
|
||||
});
|
||||
|
||||
if (user) {
|
||||
const additionalData = {
|
||||
code: user.username,
|
||||
};
|
||||
const prova = 'dasdas1231#11';
|
||||
// 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();
|
||||
user.date_tokenforgot = new Date();
|
||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||
|
||||
Reference in New Issue
Block a user