Protetto le password (al load) che vengono settate in settings

This commit is contained in:
paoloar77
2021-12-23 14:13:40 +01:00
parent cbac34bc0e
commit 665680b531
32 changed files with 248 additions and 302 deletions

View File

@@ -39,6 +39,10 @@ const SettingsSchema = new Schema({
serv: {
type: Boolean,
default: false
},
crypted: {
type: Boolean,
default: false
}
});
@@ -63,6 +67,8 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
return myrec.value_num;
else if (myrec.type === tools.FieldType.boolean)
return myrec.value_bool;
else if (myrec.type === tools.FieldType.crypted)
return tools.decryptdata(myrec.value_str);
else
return myrec.value_str;
} else {
@@ -82,18 +88,35 @@ SettingsSchema.statics.DuplicateAllRecords = async function (idapporig, idappdes
};
SettingsSchema.statics.findAllIdApp = function (idapp, serv) {
SettingsSchema.statics.findAllIdApp = async function (idapp, serv, crypted = false) {
const Settings = this;
let myfind = '';
if (serv)
myfind = { idapp, serv };
else
if (serv) {
myfind = {idapp, serv };
} else
myfind = { idapp };
return Settings.find(myfind, (err, arrrec) => {
// myfind = {...myfind, $or: [{ crypted: { $exists: false } }, { crypted: { $exists: true, $eq: crypted } }]};
const arrorig = await Settings.find(myfind, (err, arrrec) => {
return arrrec
});
let myarr = []
if (!crypted) {
arrorig.forEach((rec) => {
if (rec.crypted) {
rec._doc.value_str = ''
}
myarr.push({...rec._doc});
})
} else {
myarr = [...arrorig];
}
return myarr;
};
SettingsSchema.statics.setKeyNum = async function (idapp, key, value) {