- Chart Maps Nationality

- Username lowercase
- Statistics
- Telegram
This commit is contained in:
Paolo Arena
2020-01-27 15:07:53 +01:00
parent f5355c3a54
commit 25ad3e91c2
11 changed files with 262 additions and 76 deletions

View File

@@ -42,6 +42,7 @@
"nodemailer": "^6.4.2", "nodemailer": "^6.4.2",
"preview-email": "^1.0.2", "preview-email": "^1.0.2",
"pug": "^2.0.4", "pug": "^2.0.4",
"rate-limiter-flexible": "^1.3.1",
"save": "^2.4.0", "save": "^2.4.0",
"superagent": "^5.1.3", "superagent": "^5.1.3",
"url-parse": "^1.4.7", "url-parse": "^1.4.7",

View File

@@ -99,9 +99,9 @@ if (process.env.NODE_ENV === 'production') {
portapp: '0', portapp: '0',
dir: '/var/www/ayni.gifteconomy.app', dir: '/var/www/ayni.gifteconomy.app',
email_from: 'ayni.gifteconomy@gmail.com', email_from: 'ayni.gifteconomy@gmail.com',
email_pwd: '4a16f0c93b28cd53cb2b6d9b6698ad20c5514f1c91de8161b2789274d15617bb20Ecne0RP3aNDl8NhJj5Uw==', email_pwd: 'b72b121f6fb69f7c58a269f5b5110e179430cd6fa940a168c2c10b255aa75fd1ebql9yXWoH1LwANdHD7Yvw==',
telegram_key:'1037577457:AAGQbdIuYoB838v61ewJ0Hearx9UPpTBhMI', telegram_key:'1037577457:AAGQbdIuYoB838v61ewJ0Hearx9UPpTBhMI',
telegram_bot_name: 'aynibot', telegram_bot_name: 'notevoleaynibot',
}, },
{ {
idapp: '8', idapp: '8',

View File

@@ -123,6 +123,12 @@ ExtraListSchema.statics.getRegDellaLista = async function (idapp) {
return await ExtraList.count(myfind); return await ExtraList.count(myfind);
}; };
ExtraListSchema.statics.getLastUser = function (idapp) {
const ExtraList = this;
return ExtraList.findOne({ idapp }).sort({ ind_order: -1 })
};
ExtraListSchema.statics.findByCellAndNameSurname = function (idapp, cell_complete, name, surname) { ExtraListSchema.statics.findByCellAndNameSurname = function (idapp, cell_complete, name, surname) {
const ExtraList = this; const ExtraList = this;
@@ -163,7 +169,7 @@ ExtraListSchema.statics.getUsersList = function (idapp) {
ExtraListSchema.statics.getFieldsForSearch = function () { ExtraListSchema.statics.getFieldsForSearch = function () {
return ['name', 'surname', 'cell_complete', 'aportador_solidario_name_surname', 'aportador_solidario_originale_name_surname'] return ['username', 'name', 'surname', 'cell_complete', 'aportador_solidario_name_surname', 'aportador_solidario_originale_name_surname']
}; };
ExtraListSchema.statics.executeQueryTable = function (idapp, params) { ExtraListSchema.statics.executeQueryTable = function (idapp, params) {

View File

@@ -286,7 +286,7 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) {
return User.findOne({ idapp, username: username }).then((user) => { return User.findOne({ idapp, username: username }).then((user) => {
if (!user) { if (!user) {
// Check if with email: // Check if with email:
return User.findOne({ idapp, email: username }) return User.findOne({ idapp, email: username.toLowerCase() })
} else { } else {
return user return user
} }
@@ -416,6 +416,12 @@ UserSchema.statics.findByEmail = function (idapp, email) {
}); });
}; };
UserSchema.statics.getLastUser = function (idapp) {
const User = this;
return User.findOne({ idapp }).sort({ ind_order: -1 })
};
UserSchema.pre('save', function (next) { UserSchema.pre('save', function (next) {
const user = this; const user = this;
@@ -548,7 +554,28 @@ UserSchema.statics.getUsersTelegALL = async function (idapp) {
UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) { UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
const User = this; const User = this;
return await User.findOne({ idapp, 'profile.manage_telegram': true, 'profile.teleg_id': idtelegram }, { 'profile.teleg_id': 1 }) return await User.findOne({
idapp,
'profile.manage_telegram': true,
'profile.teleg_id': idtelegram
}, { 'profile.teleg_id': 1 })
.then((rec) => {
return (!!rec && rec.profile.teleg_id === idtelegram);
}).catch((e) => {
console.error('getusersManagers', e);
return false
});
};
UserSchema.statics.isAdminByIdTeleg = async function (idapp, idtelegram) {
const User = this;
return await User.findOne({
idapp,
'username': 'paoloar77',
'profile.manage_telegram': true,
'profile.teleg_id': idtelegram
}, { 'profile.teleg_id': 1 })
.then((rec) => { .then((rec) => {
return (!!rec && rec.profile.teleg_id === idtelegram); return (!!rec && rec.profile.teleg_id === idtelegram);
}).catch((e) => { }).catch((e) => {
@@ -607,7 +634,7 @@ UserSchema.statics.getUsersListByParams = function (params) {
*/ */
UserSchema.statics.getFieldsForSearch = function () { UserSchema.statics.getFieldsForSearch = function () {
return ['name', 'surname', 'email', 'profile.cell', 'profile.email_paypal', 'profile.username_telegram', 'aportador_solidario'] return ['username', 'name', 'surname', 'email', 'profile.cell', 'profile.email_paypal', 'profile.username_telegram', 'aportador_solidario']
}; };
UserSchema.statics.executeQueryTable = function (idapp, params) { UserSchema.statics.executeQueryTable = function (idapp, params) {
@@ -682,12 +709,59 @@ UserSchema.statics.getUsersRegistered = async function (idapp) {
return await User.count(myfind); return await User.count(myfind);
}; };
UserSchema.statics.getEmailNotVerified = async function (idapp) {
const User = this;
const myfind = { idapp, verified_email: false };
return await User.count(myfind);
};
UserSchema.statics.getUsersTelegramAttivo = async function (idapp) {
const User = this;
const myfind = { idapp, 'profile.teleg_id': { $gt: 0 } };
return await User.count(myfind);
};
UserSchema.statics.getUsersTelegramPending = async function (idapp) {
const User = this;
const myfind = { idapp, 'profile.teleg_checkcode': { $gt: 0 } };
return await User.count(myfind);
};
UserSchema.statics.getUsersZoom = async function (idapp) {
const User = this;
const myfind = { idapp, 'profile.saw_zoom_presentation': true };
return await User.count(myfind);
};
UserSchema.statics.getUsersDreams = async function (idapp) {
const User = this;
const myfind = {
idapp,
'profile.my_dream': { $exists: true },
"$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] }
};
return await User.count(myfind);
};
UserSchema.statics.getLastUsers = async function (idapp) { UserSchema.statics.getLastUsers = async function (idapp) {
const User = this; const User = this;
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5); const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5);
return await User.find({ idapp }).sort({ date_temp_reg: -1 }).limit(lastn); return await User.find({ idapp }).sort({ date_temp_reg: -1 }).limit(lastn).then((arr) => {
//return JSON.stringify(arr)
return arr
});
}; };
@@ -698,6 +772,8 @@ UserSchema.statics.checkUser = async function (idapp, username) {
verified_email: 1, verified_email: 1,
'profile.teleg_id': 1, 'profile.teleg_id': 1,
'profile.teleg_checkcode': 1, 'profile.teleg_checkcode': 1,
}).then((rec) => {
return JSON.stringify(rec)
}); });
}; };
@@ -712,8 +788,61 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
}; };
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
const query = [
{
$match: { idapp }
},
{
$group: { _id: "$profile.nationality", count: { $sum: 1 } }
},
{
$sort: { count: -1 }
}
];
return query
};
UserSchema.statics.findAllDistinctNationality = async function (idapp) {
const User = this;
return User.aggregate(User.getUsersNationalityQuery(idapp))
.then(ris => {
// console.table(ris);
return JSON.stringify(ris);
});
};
UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
const query = [
{
$match: { idapp }
},
{
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_temp_reg" } }, count: { $sum: 1 } }
},
{
$sort: { _id: 1 }
},
{
$limit: nrec
}
];
return query
};
UserSchema.statics.calcRegDaily = async function (idapp) {
const User = this;
return User.aggregate(User.getUsersRegDaily(idapp, 30))
.then(ris => {
// console.table(ris);
return JSON.stringify(ris);
});
};
if (tools.INITDB_FIRSTIME) { if (tools.INITDB_FIRSTIME) {
console.log(' createIndex User Index...'); console.log(' createIndex User Index...');

View File

@@ -20,13 +20,6 @@ module.exports = {
} }
}, },
getiPAddressUser: function (req) {
try {
return req.ip; // Express
} catch (e) {
return ''
}
}
}; };

View File

@@ -21,7 +21,7 @@ router.post('/', authenticate, async (req, res) => {
const aportador_solidario = req.user.aportador_solidario; const aportador_solidario = req.user.aportador_solidario;
const dashboard = User.getDashboard(idapp, aportador_solidario, req.user.username); const dashboard = await User.getDashboard(idapp, aportador_solidario, req.user.username);
if (dashboard) if (dashboard)
res.send({ dashboard }); res.send({ dashboard });
else else

View File

@@ -26,13 +26,22 @@ router.post('/load', async (req, res) => {
num_tot_lista: await ExtraList.getTotInLista(idapp), num_tot_lista: await ExtraList.getTotInLista(idapp),
num_reg_lista: await ExtraList.getRegDellaLista(idapp), num_reg_lista: await ExtraList.getRegDellaLista(idapp),
num_reg: await User.getUsersRegistered(idapp), num_reg: await User.getUsersRegistered(idapp),
email_non_verif: await User.getEmailNotVerified(idapp),
num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
num_teleg_pending: await User.getUsersTelegramPending(idapp),
num_part_zoom: await User.getUsersZoom(idapp),
num_users_dream: await User.getUsersDreams(idapp),
arr_nations: await User.findAllDistinctNationality(idapp),
reg_daily: await User.calcRegDaily(idapp),
lastsreg: await User.getLastUsers(idapp), lastsreg: await User.getLastUsers(idapp),
checkuser: await User.checkUser(idapp, username), checkuser: await User.checkUser(idapp, username),
}; };
// console.table(datastat.lastsreg); // console.table(datastat.lastsreg);
/* /*
let datastat = { let datastat = {
num_tot_lista: 80, num_tot_lista: 80,
num_reg: 40, num_reg: 40,
@@ -45,7 +54,7 @@ router.post('/load', async (req, res) => {
{ username: 'prova5', name: 'Secondo', surname: 'PPP', nationality: 'sl', date_reg: new Date()}, { username: 'prova5', name: 'Secondo', surname: 'PPP', nationality: 'sl', date_reg: new Date()},
] ]
}; };
*/ */
res.send({ datastat }); res.send({ datastat });
}); });

View File

@@ -53,7 +53,7 @@ router.post('/', async (req, res) => {
user.linkreg = reg.getlinkregByEmail(body.idapp, body.email, body.username); user.linkreg = reg.getlinkregByEmail(body.idapp, body.email, body.username);
user.verified_email = false; user.verified_email = false;
user.ipaddr = reg.getiPAddressUser(req); user.ipaddr = tools.getiPAddressUser(req);
user.lasttimeonline = new Date(); user.lasttimeonline = new Date();
user.date_reg = new Date(); user.date_reg = new Date();
user.date_temp_reg = new Date(); user.date_temp_reg = new Date();
@@ -62,6 +62,11 @@ router.post('/', async (req, res) => {
user.verified_email = true; user.verified_email = true;
} }
if (user.profile.intcode_cell) {
if (user.profile.cell.substring(0, user.profile.intcode_cell.length) === user.profile.intcode_cell) {
user.profile.cell = user.profile.cell.substring(user.profile.intcode_cell.length)
}
}
let exit; let exit;
// Check if already esist email or username // Check if already esist email or username
@@ -98,6 +103,21 @@ router.post('/', async (req, res) => {
nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname; nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname;
} }
const lastuser = await User.getLastUser(user.idapp);
const lastextra = await ExtraList.getLastUser(user.idapp);
let lastindorder = 0;
if (lastuser) {
lastindorder = lastuser.ind_order;
}
if (lastextra) {
if (lastextra.ind_order > lastindorder)
lastindorder = lastextra.ind_order;
}
if (lastindorder > 0)
user.ind_order = lastindorder + 1;
namesurname_aportador_reg = await User.getNameSurnameByUsername(user.idapp, user.aportador_solidario); namesurname_aportador_reg = await User.getNameSurnameByUsername(user.idapp, user.aportador_solidario);
@@ -119,6 +139,9 @@ router.post('/', async (req, res) => {
if (already_registered) { if (already_registered) {
// Check in the extraList if is present! // Check in the extraList if is present!
if (!recextra) { if (!recextra) {
console.log('Utente non trovato; ', user);
const msg = 'Utente non trovato: ' + user.name + ' ' + user.surname + ' ' + user.profile.nationality + ' ' + user.profile.intcode_cell + user.profile.cell + ' email: ' + user.email + ' username: ' + user.username;
telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
res.status(400).send({ code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND, msg: '' }); res.status(400).send({ code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND, msg: '' });
return 1; return 1;
} else { } else {
@@ -247,7 +270,9 @@ router.post('/login', (req, res) => {
.then((user) => { .then((user) => {
// tools.mylog("CREDENZIALI ! "); // tools.mylog("CREDENZIALI ! ");
if (!user) { if (!user) {
tools.mylogshow("NOT FOUND !"); tools.mylogshow("Errore LOGIN ! Username o password Errati: ", body.username, body.password);
const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR }); res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
} }
return user return user

View File

@@ -78,6 +78,8 @@ module.exports = {
} }
// console.log('2 . paramemail.transport', paramemail.transport); // console.log('2 . paramemail.transport', paramemail.transport);
// console.log('user', tools.getEmailByIdApp(mylocalsconf.idapp));
// console.log('pass', tools.getPwdByIdApp(mylocalsconf.idapp));
// console.log('paramemail', paramemail); // console.log('paramemail', paramemail);
@@ -116,13 +118,13 @@ module.exports = {
mailOptions['reply-to'] = replyTo; mailOptions['reply-to'] = replyTo;
if (process.env.SEND_EMAIL === 1) { if (process.env.SEND_EMAIL === 1) {
console.log("SEND EMAIL..."); // console.log("SEND EMAIL...");
// send mail with defined transport object // send mail with defined transport object
smtpTransport.sendMail(mailOptions, function (error, response) { smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) { if (error) {
console.log(error); console.log("Email Inviata ERRORE RISPOSTA: " + error);
} else { } else {
console.log("Email Inviata RISPOSTA: " + response); // console.log("Email Inviata RISPOSTA: " + response);
} }
}); });
} else { } else {
@@ -303,7 +305,7 @@ module.exports = {
}, },
Add_to_MailingList_AndSendEmailNotify: async function (lang, user, idapp, sendnews) { Add_to_MailingList_AndSendEmailNotify: async function (lang, user, idapp, sendnews) {
console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); // console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
mylocalsconf = { mylocalsconf = {
idapp, idapp,
@@ -442,9 +444,9 @@ module.exports = {
templemail_id: await Settings.getValDbSettings(idapp, 'TEMPLEMAIL_ID'), templemail_id: await Settings.getValDbSettings(idapp, 'TEMPLEMAIL_ID'),
}; };
console.log(mydata.templemail_id); // console.log(mydata.templemail_id);
mydata.templ = await TemplEmail.findOne({_id: mydata.templemail_id }); mydata.templ = await TemplEmail.findOne({_id: mydata.templemail_id });
console.log(mydata.templ); // console.log(mydata.templ);
return mydata return mydata
}, },
@@ -547,7 +549,7 @@ module.exports = {
await tools.snooze(5000); await tools.snooze(5000);
// Send Email to the User // Send Email to the User
console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')'); // console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply, smtpTransport); const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply, smtpTransport);
//Put the result in the database, to check if is sent or not. //Put the result in the database, to check if is sent or not.

View File

@@ -101,18 +101,18 @@ const StatusMSGALL = {
const txt = { const txt = {
MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Scegli una voce di menu:' + emoji.get('dizzy'), MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Scegli una voce di menu:' + emoji.get('dizzy'),
MSG_ASK_USERNAME_BO: 'Inserire lo username con cui ti sei registrato sul sito:', MSG_ASK_USERNAME_BO: 'Inserire lo username con cui ti sei registrato sul sito %s:',
MSG_ERRORE_USERNAME: 'Attenzione! Devi inserire solo lo username (20 caratteri massimo)', MSG_ERRORE_USERNAME: 'Attenzione! Devi inserire solo lo username (20 caratteri massimo)',
MSG_ERRORE_USERNAME_NOT_FOUND: 'Attenzione! Username non trovato in archivio. Verifica che sia corretto.', MSG_ERRORE_USERNAME_NOT_FOUND: 'Attenzione! Username non trovato in archivio. Verifica che sia corretto.',
MSG_ERRORE_USERNAME_ANNULLA: 'Inserimento Annullato. Riprovare', MSG_ERRORE_USERNAME_ANNULLA: 'Inserimento Annullato. Riprovare',
MSG_OPERAZ_ANNULLATA: 'Operazione Annullata', MSG_OPERAZ_ANNULLATA: 'Operazione Annullata',
MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Attenzione! Devi inserire solo il codice a 6 cifre', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Attenzione! Devi inserire solo il codice a 6 cifre',
MSG_VERIFY_CODE: 'Vai sul sito e scrivi qui il Codice di Autenticazione che vedrai visualizzato', MSG_VERIFY_CODE: 'Ritorna sul sito cliccando qui %s, poi torna qui e scrivi il Codice di Autenticazione che vedrai visualizzato',
MSG_ERR_VERIFY_CODE: 'Codice di Verifica Errato! Controllare sul Sito e reinserire il nuovo codice di 6 cifre.', MSG_ERR_VERIFY_CODE: 'Codice di Verifica Errato! Controllare sul Sito e reinserire il nuovo codice di 6 cifre.',
MSG_VERIFY_OK: emoji.get('grinning') + ' Benvenuto %s. Ora sei correttamente verificato!', MSG_VERIFY_OK: emoji.get('grinning') + ' Benvenuto %s. Sono il tuo BOT. Chiedi utilizzando il menu che trovi in basso.\nOra sei correttamente verificato!\nContinua la guida passo passo che trovi sul sito. Qui puoi ritornare per vedere La tua Lavagna in maniera rapida, senza passare dal sito.',
MSG_ERR_UNKNOWN_VERIFY_CODE: 'Errore durante il salvataggio sul Server. Riprovare piú tardi', MSG_ERR_UNKNOWN_VERIFY_CODE: 'Errore durante il salvataggio sul Server. Riprovare piú tardi',
MSG_EXIT_TELEGRAM: 'L\'account è stato ora scollegato da questo Telegram BOT.', MSG_EXIT_TELEGRAM: 'L\'account è stato ora scollegato da questo Telegram BOT.',
MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Si è appena Registrato %s\n(Invitato da %s)', MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Si è appena Registrato "%s (n. %s)"\n(Invitato da %s)',
MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !', MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !',
}; };
@@ -131,6 +131,7 @@ module.exports = {
notifyToTelegram: async function (phase, mylocalsconf) { notifyToTelegram: async function (phase, mylocalsconf) {
let userdest = mylocalsconf.user.aportador_solidario; let userdest = mylocalsconf.user.aportador_solidario;
let NameFrom = `${mylocalsconf.user.name} ${mylocalsconf.user.surname}`; let NameFrom = `${mylocalsconf.user.name} ${mylocalsconf.user.surname}`;
const ind_order = mylocalsconf.user.ind_order;
let aportador = ''; let aportador = '';
if (userdest) { if (userdest) {
@@ -146,7 +147,7 @@ module.exports = {
NameFrom = await User.getNameSurnameByUsername(mylocalsconf.idapp, userdest) + aportador; NameFrom = await User.getNameSurnameByUsername(mylocalsconf.idapp, userdest) + aportador;
aportador = NameFrom; aportador = NameFrom;
} }
text = printf(txt.MSG_APORTADOR_USER_REGISTERED, `${mylocalsconf.user.name} ${mylocalsconf.user.surname} (${mylocalsconf.user.username})`, aportador); text = printf(txt.MSG_APORTADOR_USER_REGISTERED, `${mylocalsconf.user.name} ${mylocalsconf.user.surname} (${mylocalsconf.user.username})`, ind_order, aportador);
} }
let addtext = ""; let addtext = "";
@@ -275,14 +276,14 @@ class Telegram {
} }
} }
getsymb(symb, valid, isnum, verdeif, smileif) { getsymb(symb, valid, isnum, num, smileif) {
let str = symb + ': '; let str = symb + ': ';
if (valid) if (valid)
str += emo.CHECK_VERDE; str += emo.CHECK_VERDE;
else else
str += emo.CROSS_ROSSA; str += emo.CROSS_ROSSA;
if (isnum) { if (isnum) {
str += ' ' + getemojibynumber(valid); str += ' ' + getemojibynumber(num);
if (smileif) if (smileif)
str += emo.SMILE_STAR; str += emo.SMILE_STAR;
} }
@@ -317,7 +318,7 @@ class Telegram {
// mystr += `____________________________________________\n`; // mystr += `____________________________________________\n`;
if (rec.user) { if (rec.user) {
mystr += tools.get__('BENVENUTO', msg) + ' ' + rec.user.name + ' ' + emo.DIZZY; mystr += tools.get__('BENVENUTO', msg) + ' ' + rec.user.name + ' (' + rec.user.username + ') ' + emo.DIZZY;
mystr += '\n' + '\n' + this.getsymb(emo.ENVELOPE, rec.user.verified_email); mystr += '\n' + '\n' + this.getsymb(emo.ENVELOPE, rec.user.verified_email);
mystr += rec.user.verified_email ? tools.get__('EMAIL_VERIF', msg) : tools.get__('EMAIL_NON_VERIF', msg); mystr += rec.user.verified_email ? tools.get__('EMAIL_VERIF', msg) : tools.get__('EMAIL_NON_VERIF', msg);
@@ -328,9 +329,9 @@ class Telegram {
// mystr += tools.get__('TELEGRAM_NOT_CONNECTED', msg) + ' ' + emoji.get('e-mail'); // mystr += tools.get__('TELEGRAM_NOT_CONNECTED', msg) + ' ' + emoji.get('e-mail');
} }
// numpersone = 3; // numpersone = 2;
mystr += '\n' + '\n' + this.getsymb(emo.INVITATI, numpersone, true, numpersone >= 2, numpersone >= 3) + tools.get__('INVITATI', msg) + '\n'; mystr += '\n' + '\n' + this.getsymb(emo.INVITATI, numpersone >= 2, numpersone, numpersone, numpersone >= 3) + tools.get__('INVITATI', msg) + '\n';
if (numpersone > 0) { if (numpersone > 0) {
let index = 1; let index = 1;
@@ -400,10 +401,13 @@ class Telegram {
} }
} }
index++; index++;
});
if (!nextzoom && index > 1) {
mystr += "LINK ZOOM DA CONDIVIDERE :\n" + tools.getlinkzoom(listazoom[0].id_conf_zoom) + '\n\n';
} }
)
;
await await
@@ -429,8 +433,7 @@ class Telegram {
if (rec.user) { if (rec.user) {
const mystr = 'Scrivi qui un Messaggio da inviare a TUTTI:'; const mystr = 'Scrivi qui un Messaggio da inviare a TUTTI:';
rec.msgall_status = StatusMSGALL.ASK; rec.msgall_status = StatusMSGALL.ASK;
await await this.sendMsg(msg.chat.id, mystr, MenuAdmin);
this.sendMsg(msg.chat.id, mystr, MenuAdmin);
} }
} }
@@ -470,6 +473,9 @@ class Telegram {
async setUsernameBo(msg) { async setUsernameBo(msg) {
try { try {
const rec = this.getRecInMem(msg); const rec = this.getRecInMem(msg);
if (msg.text === undefined)
return false;
console.log('msg.text', msg.text); console.log('msg.text', msg.text);
const text = msg.text; const text = msg.text;
if (text.length < 20) { if (text.length < 20) {
@@ -480,15 +486,16 @@ class Telegram {
const user = await const user = await
User.findByUsername(this.idapp, rec.username_bo); User.findByUsername(this.idapp, rec.username_bo);
if (!user) { if (!user) {
await await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND);
this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND) rec.username_bo = '';
} else { } else {
rec.user = user; rec.user = user;
await await
User.SetTelegramCheckCode(this.idapp, rec.username_bo, rec.code); User.SetTelegramCheckCode(this.idapp, rec.username_bo, rec.code);
rec.status = Status.WAITFOR_VERIFY_CODE; rec.status = Status.WAITFOR_VERIFY_CODE;
await await
this.sendMsg(msg.from.id, txt.MSG_VERIFY_CODE) this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_CODE, tools.getHostByIdApp(this.idapp)))
} }
} }
} else if (text.length === 0) { } else if (text.length === 0) {
@@ -570,9 +577,9 @@ class Telegram {
if (usersall) { if (usersall) {
for (const rec of usersall) { for (const rec of usersall) {
await await this.sendMsg(rec.profile.teleg_id, texttosend);
this.sendMsg(rec.profile.teleg_id, texttosend);
nummsgsent++; nummsgsent++;
// ++Todo: SLEEP ??? sleep(0.03)
} }
} }
@@ -657,7 +664,7 @@ class Telegram {
this.addUser(msg); this.addUser(msg);
await await
this.sendMsg(msg.chat.id, getstr(msg.from.language_code, txt.MSG_ASK_USERNAME_BO)); this.sendMsg(msg.chat.id, getstr(msg.from.language_code, printf(txt.MSG_ASK_USERNAME_BO, tools.getHostByIdApp(this.idapp))));
return false; return false;
} }
@@ -730,7 +737,7 @@ class Telegram {
let keyb = MenuStandard; let keyb = MenuStandard;
// Check if you are Admin // Check if you are Admin
const ismanager = await const ismanager = await
User.isManagerByIdTeleg(this.idapp, id); User.isAdminByIdTeleg(this.idapp, id);
if (ismanager) if (ismanager)
keyb = MenuPerAdmin; keyb = MenuPerAdmin;
if (menu) { if (menu) {

View File

@@ -833,4 +833,18 @@ module.exports = {
return namesurname return namesurname
}, },
getiPAddressUser (req) {
try {
const striniziale = '::ffff:';
if (req.ip.indexOf(striniziale) >= 0){
return req.ip.substring(striniziale.length)
} else {
return req.ip; // Express
}
} catch (e) {
return ''
}
}
}; };