Lista Amici

Richieste di Fiducia
Accettati
Rifiutati
This commit is contained in:
paoloar77
2022-01-07 01:18:01 +01:00
parent 181af3c895
commit 3b6218d2ba
11 changed files with 1254 additions and 663 deletions

View File

@@ -35,12 +35,18 @@ const SiteSchema = new Schema({
host: {
type: String,
},
host_test: {
type: String,
},
portapp: {
type: String,
},
dir: {
type: String,
},
dir_test: {
type: String,
},
email_from: {
type: String,
},
@@ -53,9 +59,18 @@ const SiteSchema = new Schema({
telegram_bot_name: {
type: String,
},
telegram_key_test: {
type: String,
},
telegram_bot_name_test: {
type: String,
},
pathreg_add: {
type: String,
},
ask_to_verify_reg: {
type: Boolean,
},
who: {
type: String
},

View File

@@ -137,7 +137,6 @@ const UserSchema = new mongoose.Schema({
},
verified_by_aportador: {
type: Boolean,
default: false,
},
aportador_iniziale: {
type: String,
@@ -158,6 +157,15 @@ const UserSchema = new mongoose.Schema({
sospeso: {
type: Boolean,
},
blocked: {
type: Boolean,
},
username_who_block: {
type: String,
},
date_blocked: {
type: Date,
},
non_voglio_imbarcarmi: {
type: Boolean,
},
@@ -303,6 +311,7 @@ const UserSchema = new mongoose.Schema({
description: {type: String},
rating: {type: Number},
}],
friends: [], // username
},
})
@@ -1193,6 +1202,109 @@ UserSchema.statics.getUserProfileByUsername = async function(idapp, username) {
};
UserSchema.statics.getUsernameFriendsByUsername = async function(
idapp, username) {
return User.findOne({
idapp, 'username': username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'profile.friends': 1}).then((rec) => rec ? rec._doc.profile.friends : []);
};
UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameDest, cmd, value) {
let ris = null;
let update = { };
if (cmd === shared_consts.FRIENDSCMD.SETTRUST) {
return User.updateOne({idapp, username: usernameDest},
{ $set: { verified_by_aportador: value } }, { new: false } );
} else if (cmd === shared_consts.FRIENDSCMD.SETFRIEND) {
// Aggiungo l'Amicizia a me
const foundIfAlreadyFriend = await User.findOne({
idapp,
members: {
$elemMatch: { 'profile.friends': usernameOrig }
}
});
update = { $push: { 'profile.friends': [usernameOrig] } };
if (!foundIfAlreadyFriend) {
ris = await User.updateOne({idapp, username: usernameOrig}, update);
}
// Controlla se lui aveva già la mia amicizia
const foundIfAlreadyFriend2 = await User.findOne({
members: {
$elemMatch: { 'profile.friends': usernameOrig }
}
});
update = { $push: { 'profile.friends': [usernameOrig] } };
if (!foundIfAlreadyFriend) {
ris = await User.updateOne({idapp, username: usernameOrig}, update);
}
} else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS) {
// Rimuovo l'Amicizia da lui
await User.updateOne({idapp, username: usernameDest}, { $pullAll: { 'profile.friends': [usernameOrig] } });
// Rimuovo l'Amicizia da me
ris = await User.updateOne({idapp, username: usernameOrig}, { $pullAll: { 'profile.friends': [usernameDest] } });
} else if (cmd === shared_consts.FRIENDSCMD.BLOCK_USER) {
// Rimuovo l'Amicizia da lui
await User.updateOne({idapp, username: usernameDest}, { $pullAll: { 'profile.friends': [usernameOrig] } });
// Rimuovo l'Amicizia da me
await User.updateOne({idapp, username: usernameOrig}, { $pullAll: { 'profile.friends': [usernameDest] } });
// Blocco la persona
ris = await User.updateOne({idapp, username: usernameDest}, { $set: { blocked: true, sospeso: true, username_who_block: usernameOrig, date_blocked: new Date() } });
}
return ris;
};
UserSchema.statics.getFriendsByUsername = async function(idapp, username) {
const whatToShow = {
username: 1,
aportador_solidario: 1,
name: 1,
surname: 1,
deleted: 1,
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
'profile.nationality': 1,
'profile.biografia': 1,
'profile.username_telegram': 1,
'profile.img': 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city': 1,
'profile.born_province': 1,
'profile.born_country': 1,
email: 1,
date_reg: 1,
};
const arrUsernameFriends = await User.getUsernameFriendsByUsername(idapp, username);
const listFriends = await User.find({
idapp,
username: {$in: arrUsernameFriends},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, whatToShow);
const listTrusted = await User.find({
idapp, aportador_solidario: username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, whatToShow);
return ({listFriends, listTrusted});
};
UserSchema.statics.getAportadorSolidarioByUsername = async function(
idapp, username) {
const User = this;

View File

@@ -17,4 +17,18 @@ router.get('/:idapp/:email', (req, res) => {
});
});
router.post('/ck', (req, res) => {
const idapp = req.body.idapp;
var email = req.body.email;
User.findByEmail(idapp, email).then((user) => {
if (!user) {
return res.status(404).send();
}
res.status(200).send();
}).catch((e) => {
res.status(400).send();
});
});
module.exports = router;

View File

@@ -455,7 +455,7 @@ router.post('/gettable', authenticate, (req, res) => {
return res.send(ris);
}).catch((e) => {
console.log(e.message);
console.log('gettable: ' + e.message);
res.status(400).send(e);
});
@@ -601,6 +601,13 @@ router.patch('/chval', authenticate, async (req, res) => {
}
if (mydata.table === shared_consts.TAB_SITES) {
if (shared_consts.SITES_KEY_TO_CRYPTED in fieldsvalue) {
fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED] = tools.cryptdata(fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED]);
}
}
await mytable.findByIdAndUpdate(id, {$set: fieldsvalue}).then(async (rec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);
if (!rec) {
@@ -1559,8 +1566,9 @@ function uploadFile(req, res, version) {
form.parse(req);
let dirmain = '/statics';
console.log('process.env.PROD', process.env.PROD);
if (version > 0) {
if (process.env.PROD === 1) {
if (process.env.PROD === '1') {
dirmain = '';
} else {
dirmain = '/public';

View File

@@ -107,6 +107,12 @@ router.post('/', async (req, res) => {
user.lasttimeonline = new Date();
user.date_reg = new Date();
user.aportador_iniziale = user.aportador_solidario;
if (!tools.getAskToVerifyReg(body.idapp)) {
// Se non devo chiedere di verificare all'Invitato, allora lo verifico direttamente
user.verified_by_aportador = true;
}
/* if (user.idapp === tools.AYNI) {
user.profile.paymenttypes = ['paypal'];
} */
@@ -319,7 +325,7 @@ router.patch('/:id', authenticate, (req, res) => {
});
});
router.post('/profile', (req, res) => {
router.post('/profile', authenticate, (req, res) => {
const username = req.body['username'];
idapp = req.body.idapp;
locale = req.body.locale;
@@ -470,6 +476,45 @@ router.post('/import_extralist', async (req, res) => {
res.send(ris);
});
router.post('/friends', authenticate, (req, res) => {
const username = req.user.username;
idapp = req.body.idapp;
locale = req.body.locale;
return User.getFriendsByUsername(idapp, username).then((ris) => {
res.send(ris);
}).catch((e) => {
tools.mylog('ERRORE IN Profile: ' + e.message);
res.status(400).send();
});
});
router.post('/friends/cmd', authenticate, (req, res) => {
const usernameLogged = req.user.username;
const idapp = req.body.idapp;
const locale = req.body.locale;
const usernameOrig = req.body.usernameOrig;
const usernameDest = req.body.usernameDest;
const cmd = req.body.cmd;
const value = req.body.value;
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
// If without permissions, exit
if (usernameOrig !== usernameLogged) {
return res.status(404).send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
}
}
return User.setFriendsCmd(idapp, usernameOrig, usernameDest, cmd, value).then((ris) => {
res.send(ris);
}).catch((e) => {
tools.mylog('ERRORE IN Friends/cmd: ' + e.message);
res.status(400).send();
});
});
async function eseguiDbOp(idapp, mydata, locale) {
let ris = await User.DbOp(idapp, mydata);

View File

@@ -553,7 +553,8 @@ module.exports = {
try {
mylocalsconf.dataemail.disclaimer_out = !!mylocalsconf.dataemail.disclaimer ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disclaimer) : '';
mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom) : '';
mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail) : '';
if (mylocalsconf.dataemail.templ)
mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail) : '';
} catch (e) {
console.error('Error replacefields: ' + e)
}
@@ -872,29 +873,34 @@ module.exports = {
const myarrevents = await MyEvent.getLastEvents(idapp);
const myemail = await Settings.getValDbSettings(idapp, 'EMAIL_TEST');
mylocalsconf = {
idapp,
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
arrevents: myarrevents,
name: 'TestNome',
surname: 'TestCognome',
emailto: myemail,
baseurl: tools.getHostByIdApp(idapp),
hashemail: tools.getHash(myemail),
};
if (myemail) {
mylocalsconf = {
idapp,
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
arrevents: myarrevents,
name: 'TestNome',
surname: 'TestCognome',
subject: '',
emailto: myemail,
baseurl: tools.getHostByIdApp(idapp),
hashemail: tools.getHash(myemail),
};
console.log('myarrevents');
console.table(mylocalsconf.arrevents);
console.log('myarrevents');
console.table(mylocalsconf.arrevents);
mylocalsconf.dataemail = await this.getdataemail(idapp);
mylocalsconf.dataemail = await this.getdataemail(idapp);
this.replacefields(mylocalsconf);
this.replacefields(mylocalsconf);
const smtpTransport = this.getTransport(mylocalsconf);
const smtpTransport = this.getTransport(mylocalsconf);
console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly', previewonly);
return this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, '', smtpTransport, previewonly);
console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly',
previewonly);
return this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto,
mylocalsconf, '', smtpTransport, previewonly);
}
},

View File

@@ -227,7 +227,7 @@ async function mystart() {
// tools.sendNotifToAdmin('Riparti', 'Riparti');
// sendemail.testemail('2', 'it');
let miapass = '';
@@ -378,16 +378,12 @@ async function inizia() {
if (process.env.NODE_ENV === 'development') {
await telegrambot.sendMsgTelegram(tools.FREEPLANET, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET, telegrambot.ADMIN_IDTELEGRAM_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` + `🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
} else {
// if (process.env.NODE_ENV === 'production') {
await telegrambot.sendMsgTelegram(tools.CNM, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
await telegrambot.sendMsgTelegramByIdTelegram(tools.CNM, telegrambot.ADMIN_IDTELEGRAM_SERVER, `Il Server ${process.env.DATABASE} è appena ripartito!`);
// await telegrambot.sendMsgTelegramByIdTelegram('2', telegrambot.ADMIN_IDTELEGRAM_SERVER, `Il Server ${process.env.DATABASE} è appena ripartito!`);
testo = 'Ciao Paolo!';
myid = await telegrambot.sendMsgTelegramByIdTelegram(tools.CNM, telegrambot.ADMIN_IDTELEGRAM_SERVER, testo);
// await telegrambot.sendMsgTelegram(tools.FREEPLANET, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET, telegrambot.ADMIN_IDTELEGRAM_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` + `🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
}
}
@@ -409,7 +405,7 @@ async function inizia() {
// }
async function faitest() {
console.log('Fai Test:')
// console.log('Fai Test:')
const testfind = false;
@@ -424,6 +420,21 @@ async function faitest() {
console.log('ris', ris);
}
if (false) {
// const {User} = require('./models/user');
/*
const user = await User.findOne({
idapp: 12,
username: 'paoloar77',
});
await sendemail.sendEmail_Registration('it', 'paolo@freeplanet.app', user,
'12', '');
*/
}
if (false) {
const { User } = require('./models/user');

File diff suppressed because it is too large Load Diff

View File

@@ -384,6 +384,7 @@ module.exports = {
FREEPLANET: '1',
AYNI: '7',
CNM: '10',
PDNM: '12',
HELP_CHAT: '',
TYPECONF_ZOOM: 'zoom',
@@ -918,7 +919,7 @@ module.exports = {
const myapp =
this.getApps().find(item => item.idapp === idapp);
if (myapp)
return myapp.name;
return ((process.env.NODE_ENV === 'test') ? 'Test: ' : '') + myapp.name;
else
return '';
},
@@ -928,9 +929,13 @@ module.exports = {
const myapp =
this.getApps().find(item => item.idapp === idapp);
if (myapp) {
let siteport = (myapp.portapp !== '0') ? (':' + myapp.portapp) : '';
let siteport = (myapp.portapp && myapp.portapp !== '0') ? (':' + myapp.portapp) : '';
if (process.env.NODE_ENV === 'test')
return myapp.host_test + siteport;
else
return myapp.host + siteport;
return myapp.host + siteport;
} else
return '';
},
@@ -945,7 +950,10 @@ module.exports = {
const myapp =
this.getApps().find(item => item.idapp === idapp);
if (myapp) {
return myapp.dir;
if (process.env.NODE_ENV === 'test')
return (myapp) ? myapp.dir_test : '';
else
return (myapp) ? myapp.dir : '';
} else
return '';
},
@@ -977,6 +985,15 @@ module.exports = {
}
},
getAskToVerifyReg: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
if (myapp) {
return myapp.ask_to_verify_reg;
} else {
return false;
}
},
isManagAndAdminDifferent(idapp) {
const manag = this.getManagerEmailByIdApp(idapp);
return (manag !== this.getAdminEmailByIdApp(idapp)) && (manag !== '');
@@ -1002,13 +1019,19 @@ module.exports = {
getTelegramBotNameByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
return (myapp) ? myapp.telegram_bot_name : '';
if (process.env.NODE_ENV === 'test')
return (myapp) ? myapp.telegram_bot_name_test : '';
else
return (myapp) ? myapp.telegram_bot_name : '';
},
getTelegramKeyByIdApp: function(idapp) {
const myarr = this.getApps();
const myapp = myarr.find((item) => item.idapp === idapp);
return (myapp) ? myapp.telegram_key : '';
if (process.env.NODE_ENV === 'test')
return (myapp) ? myapp.telegram_key_test : '';
else
return (myapp) ? myapp.telegram_key : '';
},
getLookup: function(params, num, pass_proj) {
@@ -1069,10 +1092,7 @@ module.exports = {
throw new Error('endRow must be number');
}
let newvers = true;
if (params.lk_LF)
newvers = false;
let newvers = !!params.lookup1;
let query = [];
@@ -1236,8 +1256,10 @@ module.exports = {
filtriadded.push(...params.filtersearch);
}
if (filtriadded.length > 0)
query.push({$match: {$and: filtriadded}});
if (filtriadded) {
if (filtriadded.length > 0)
query.push({$match: {$and: filtriadded}});
}
if (idapp > 0) {
query.push({$match: {idapp}});
@@ -1275,8 +1297,10 @@ module.exports = {
const q4 = this.getLookup(params.lookup4, 4, proj);
if (q4) query = [...query, ...q4];
if (params.filtersearch2.length > 0) {
query.push({$match: {$and: params.filtersearch2}});
if (params.filtersearch2) {
if (params.filtersearch2.length > 0) {
query.push({$match: {$and: params.filtersearch2}});
}
}
} else {
@@ -1779,12 +1803,16 @@ module.exports = {
},
cryptdata(mydata) {
if (mydata === '')
return '';
// Encrypt
//return CryptoJS.AES.encrypt(JSON.stringify(mydata), process.env.SECRK);
return this.encrypt(mydata, process.env.SECRK);
},
decryptdata(mydatacrypted) {
if (mydatacrypted === '')
return '';
// Decrypt
// const bytes = CryptoJS.AES.decrypt(mydatacrypted.toString(), process.env.SECRK);
// return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));

View File

@@ -32,15 +32,24 @@ module.exports = {
FILTER_MYSKILL_SKILL: 1,
FRIENDSCMD: {
SETTRUST: 121,
SETFRIEND: 132,
REMOVE_FROM_MYFRIENDS: 144,
BLOCK_USER: 155,
},
REPORT_FILT_RESP: 1,
REPORT_FILT_ATTIVITA: 2,
TAB_COUNTRY: 'countries',
TAB_PHONES: 'phones',
TAB_SETTINGS: 'settings',
TAB_SITES: 'sites',
TAB_MYBOTS: 'mybots',
KEY_TO_CRYPTED: ['PWD_FROM'],
SITES_KEY_TO_CRYPTED: ['email_pwd'],
TablePickup: ['countries', 'phones'],
TableCities: ['citta', 'province'],

View File

@@ -6491,15 +6491,15 @@ mongodb-connection-string-url@^2.0.0:
"@types/whatwg-url" "^8.2.1"
whatwg-url "^9.1.0"
mongodb@3.6.11:
version "3.6.11"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.6.11.tgz#8a59a0491a92b00a8c925f72ed9d9a5b054aebb2"
integrity sha512-4Y4lTFHDHZZdgMaHmojtNAlqkvddX2QQBEN0K//GzxhGwlI9tZ9R0vhbjr1Decw+TF7qK0ZLjQT292XgHRRQgw==
mongodb@3.7.3:
version "3.7.3"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.7.3.tgz#b7949cfd0adc4cc7d32d3f2034214d4475f175a5"
integrity sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw==
dependencies:
bl "^2.2.1"
bson "^1.1.4"
denque "^1.4.1"
optional-require "^1.0.3"
optional-require "^1.1.8"
safe-buffer "^5.1.2"
optionalDependencies:
saslprep "^1.0.0"
@@ -6520,16 +6520,16 @@ mongoose-legacy-pluralize@1.0.2:
resolved "https://registry.yarnpkg.com/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz#3ba9f91fa507b5186d399fb40854bff18fb563e4"
integrity sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==
mongoose@^5.13.9:
version "5.13.9"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.13.9.tgz#4421a13566daea8fcc80149734c76e5641f477ce"
integrity sha512-JbLw5ie0LJxm7V9LoNxRY//6cyFJf0cOpON2TWUWvF9pabil6ArfECL3xHV2N+mwwO4gXiIa+c0pwTzDUVTgqw==
mongoose@^5.13.13:
version "5.13.14"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.13.14.tgz#ffc9704bd022dd018fbddcbe27dc802c77719fb4"
integrity sha512-j+BlQjjxgZg0iWn42kLeZTB91OejcxWpY2Z50bsZTiKJ7HHcEtcY21Godw496GMkBqJMTzmW7G/kZ04mW+Cb7Q==
dependencies:
"@types/bson" "1.x || 4.0.x"
"@types/mongodb" "^3.5.27"
bson "^1.1.4"
kareem "2.3.2"
mongodb "3.6.11"
mongodb "3.7.3"
mongoose-legacy-pluralize "1.0.2"
mpath "0.8.4"
mquery "3.2.5"
@@ -7026,10 +7026,10 @@ optional-require@1.0.x:
resolved "https://registry.yarnpkg.com/optional-require/-/optional-require-1.0.3.tgz#275b8e9df1dc6a17ad155369c2422a440f89cb07"
integrity sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==
optional-require@^1.0.3:
version "1.1.7"
resolved "https://registry.yarnpkg.com/optional-require/-/optional-require-1.1.7.tgz#9ab5b254f59534108d4b2201d9ae96a063abc015"
integrity sha512-cIeRZocXsZnZYn+SevbtSqNlLbeoS4mLzuNn4fvXRMDRNhTGg0sxuKXl0FnZCtnew85LorNxIbZp5OeliILhMw==
optional-require@^1.1.8:
version "1.1.8"
resolved "https://registry.yarnpkg.com/optional-require/-/optional-require-1.1.8.tgz#16364d76261b75d964c482b2406cb824d8ec44b7"
integrity sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==
dependencies:
require-at "^1.0.6"