Non permettere il cambio del codice del gruppo

disattivare l'abilitazione se la registrazione arriva da me paoloar77
Sistemato il Menu del BOT per inviare msg a tutti e per ricevere il proprio Link personale.
Non permettere il cambio del codice del gruppo
Aggiunta la Provincia tra parentesi nei Comuni: es Rimini (RN)
This commit is contained in:
paoloar77
2022-02-26 17:35:50 +01:00
parent 574d192661
commit 2749506de7
7 changed files with 241 additions and 119 deletions

View File

@@ -65,7 +65,7 @@ BotSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {idapp};
return Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1});
return Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}).lean();
};
const MyBot = mongoose.model('Bot', BotSchema);

View File

@@ -118,20 +118,46 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
filterfindexact = {comune: strfind};
}
let limit = 10
let risexact = []
let limit = 10;
let risexact = [];
let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}};
let aggr1 = [
{
$match: {comune: strfind},
},
{ $limit : 1 },
{
$project: {
comune: { $concat: ["$comune", " (", "$prov", ")"] },
},
},
];
if (params.filter) {
filterfind = {...params.filter, ...filterfind}
limit = 200
filterfind = {...params.filter, ...filterfind};
limit = 200;
} else {
risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
// risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
risexact = await City.aggregate(aggr1);
}
let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit);
let aggr2 = [
{
$match: filterfind,
},
{ $limit : limit },
{
$project: {
comune: { $concat: ["$comune", " (", "$prov", ")"] },
},
},
];
// let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit);
let ris = await City.aggregate(aggr2).limit(limit);
return [...risexact, ...ris];

View File

@@ -145,6 +145,9 @@ const UserSchema = new mongoose.Schema({
verified_by_aportador: {
type: Boolean,
},
notask_verif: {
type: Boolean,
},
trust_modified: {
type: Date,
},
@@ -880,6 +883,24 @@ UserSchema.statics.setVerifiedByAportador = async function(
return !!myrec;
};
UserSchema.statics.setnotask_verif = async function(
idapp, username, valuebool) {
const User = this;
if (username === undefined)
return false;
const myquery = {
'idapp': idapp,
'username': username,
};
const myrec = await User.findOneAndUpdate(myquery,
{$set: {'notask_verif': valuebool}}, {new: false});
return !!myrec;
};
UserSchema.statics.setVerifiedByAportadorToALL = async function() {
return User.updateMany({}, {$set: {'verified_by_aportador': true}},
@@ -1247,6 +1268,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
notask_verif: 1,
'profile.nationality': 1,
'profile.qualifica': 1,
'profile.biografia': 1,
@@ -1641,6 +1663,7 @@ function getWhatToShow(idapp, username) {
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
notask_verif: 1,
'profile.nationality': 1,
'profile.qualifica': 1,
'profile.biografia': 1,
@@ -1857,6 +1880,18 @@ UserSchema.statics.TelegIdByUsername = async function(idapp, username) {
console.error('TelegIdByUsername', e);
});
};
UserSchema.statics.notAsk_VerifByUsername = async function(idapp, username) {
return User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'notask_verif': 1}).then((rec) => {
return (!!rec && rec.notask_verif) ? true: false;
}).catch((e) => {
console.error('notAsk_VerifByUsername', e);
return false;
});
};
UserSchema.statics.SetTelegramCheckCode = async function(
idapp, id, teleg_checkcode) {
@@ -2124,7 +2159,7 @@ UserSchema.statics.getusersManagers = async function(idapp) {
const User = this;
return User.find({idapp, 'profile.manage_telegram': true},
{'profile.teleg_id': 1, perm: 1}).then((arrrec) => {
{username: 1, 'profile.teleg_id': 1, perm: 1}).then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
console.error('getusersManagers', e);
@@ -2619,6 +2654,7 @@ UserSchema.statics.checkUser = async function(idapp, username) {
return User.findOne({idapp, username}, {
verified_email: 1,
verified_by_aportador: 1,
notask_verif: 1,
'profile.teleg_id': 1,
'profile.teleg_checkcode': 1,
}).then((rec) => {

View File

@@ -549,13 +549,13 @@ router.post('/groups/cmd', authenticate, (req, res) => {
const cmd = req.body.cmd;
const value = req.body.value;
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
/*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.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).
then((ris) => {

View File

@@ -240,10 +240,10 @@ const Menu = {
MSG_TO_USER: 'sendmsgto',
ADMIN: emoji.get('information_desk_person') + ' Admin',
ALTRO: emoji.get('newspaper') + ' Altro',
MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
MSG_NO_7_REQ: emoji.get('incoming_envelope') + 'No 7 Req.',
MSG_NO_9_REQ: emoji.get('incoming_envelope') + 'No 9 Req',
NESSUN_IMBARCO_7REQ: emoji.get('incoming_envelope') + 'No Imbarco (7 Req)',
// MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
// MSG_NO_7_REQ: emoji.get('incoming_envelope') + 'No 7 Req.',
// MSG_NO_9_REQ: emoji.get('incoming_envelope') + 'No 9 Req',
// NESSUN_IMBARCO_7REQ: emoji.get('incoming_envelope') + 'No Imbarco (7 Req)',
MSG_SI_INVITATI_NO_7REQ_INVITATI: emoji.get('incoming_envelope') +
'Inv e NO 7 Req',
MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF',
@@ -745,7 +745,7 @@ module.exports = {
rismsg = await this.sendMsgTelegram(mylocalsconf.idapp, userdest, text);
}
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text, false, null, userdest);
if (phase === this.phase.REGISTRATION) {
await this.askConfirmationUserRegistration(mylocalsconf.idapp, shared_consts.CallFunz.REGISTRATION,
@@ -790,8 +790,7 @@ module.exports = {
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
},
sendMsgTelegramToTheManagers: async function(
idapp, text, onlyintofile = false, MyForm = null) {
sendMsgTelegramToTheManagers: async function(idapp, text, onlyintofile = false, MyForm = null, nottousername = '') {
tools.writeManagersLog(text);
@@ -799,12 +798,15 @@ module.exports = {
const usersmanagers = await User.getusersManagers(idapp);
if (usersmanagers) {
for (const rec of usersmanagers) {
if (rec.username !== nottousername) {
await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id,
emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm);
emo.ROBOT_FACE + ': ' + text, undefined, undefined, true,
MyForm);
await tools.snooze(100);
}
}
}
}
return true;
},
@@ -828,7 +830,6 @@ module.exports = {
return true;
},
getMsgByTipoMsg: async function(mydata, lang, user, sonosognatore) {
if (!!mydata.msgextra) {
return {body: mydata.msgextra, title: ''};
@@ -862,26 +863,11 @@ module.exports = {
title = ris.title;
}
if (!!user) {
msg = msg.replace('{username}', user.username);
msg = msg.replace('{name}', user.name ? user.name : user.username);
msg = msg.replace('{surname}', user.surname ? user.surname : '');
if (!!user.profile.link_payment)
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
if (!!user.profile.revolut)
msg = msg.replace('{revolut}', user.profile.revolut);
if (!!user.profile.payeer_id)
msg = msg.replace('{payeer_id}', user.profile.payeer_id);
if (!!user.profile.advcash_id)
msg = msg.replace('{advcash_id}', user.profile.advcash_id);
if (!!user.profile.email_paypal)
msg = msg.replace('{email_paypal}', user.profile.email_paypal);
if (!!user.profile.note_payment)
msg = msg.replace('{note_payment}', user.profile.note_payment);
const cl = getclTelegByidapp(user.idapp);
if (cl) {
msg = cl.convertSpecialTags(rec.user, msg);
}
// const cl = getclTelegByidapp(user.idapp);
msg = msg.replace('{link_chathelp}', tools.HELP_CHAT);
if (!!mydata.flotta) {
// SOSTITUISCI LE PAROLE CHIAVI
@@ -1203,6 +1189,19 @@ module.exports = {
},
setVerifiedReg: async function (idapp, lang, usernameorig, usernameDest) {
try {
await User.setVerifiedByAportador(idapp, usernameDest, true);
await User.setFriendsCmd(idapp, usernameorig, usernameDest,
shared_consts.FRIENDSCMD.SETFRIEND);
const msgDest = printf(getstr(lang, 'MSG_APORTADOR_CONFIRMED'), `${usernameDest}`);
await local_sendMsgTelegram(idapp, usernameorig, msgDest);
}catch (e) {
console.log('e', e);
}
},
askConfirmationUserRegistration: async function(idapp, myfunc, myuser, userDest = '', langdest = '') {
const cl = getclTelegByidapp(idapp);
@@ -1236,8 +1235,13 @@ module.exports = {
// INvia Msg
const teleg_id = await User.TelegIdByUsername(idapp, userDest);
const notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
await this.sendMsgTelegramByIdTelegram(myuser.idapp, teleg_id, domanda,
undefined, undefined, true, keyb);
undefined, undefined, true, keyb);bot
if (notask_verif) {
this.setVerifiedReg(myuser.idapp, myuser.lang, userDest, myuser.username);
}
} catch (e) {
console.error('Error askConfirmationUserRegistration', e);
@@ -1438,6 +1442,37 @@ class Telegram {
'\n\nI miei colleghi umani ti aiuteranno a risolvere !';
}
convertSpecialTags(user, msg) {
try {
if (!!user) {
msg = msg.replace('{username}', user.username);
msg = msg.replace('{name}', user.name ? user.name : user.username);
msg = msg.replace('{surname}', user.surname ? user.surname : '');
if (!!user.profile.link_payment)
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
if (!!user.profile.revolut)
msg = msg.replace('{revolut}', user.profile.revolut);
if (!!user.profile.payeer_id)
msg = msg.replace('{payeer_id}', user.profile.payeer_id);
if (!!user.profile.advcash_id)
msg = msg.replace('{advcash_id}', user.profile.advcash_id);
if (!!user.profile.email_paypal)
msg = msg.replace('{email_paypal}', user.profile.email_paypal);
if (!!user.profile.note_payment)
msg = msg.replace('{note_payment}', user.profile.note_payment);
}
// const cl = getclTelegByidapp(user.idapp);
msg = msg.replace('{link_chathelp}', tools.HELP_CHAT);
}catch (e) {
console.log(e);
}
return msg;
}
async IsTesto(msg) {
let risp = '';
@@ -1526,7 +1561,7 @@ class Telegram {
if (risp === '') {
if (menusite) {
risp = this.getValueMenu(this.idapp, testo, lang);
risp = this.getValueMenu(this.idapp, rec, msg, testo, lang);
noanswer = true;
} else if (MsgBot.CIAO.includes(testo.replace('!', ''))) {
risp = 'Ciao ';
@@ -1663,6 +1698,8 @@ class Telegram {
}
}
risp = this.convertSpecialTags(rec.user, risp);
let keyboard = null;
if (contastiera) {
@@ -1711,7 +1748,7 @@ class Telegram {
return risp !== '';
}
async isMenuNotVerified(rec, msg) {
async isMenuNotVerified(rec, msg, notlast) {
if (this.isSelMenu(msg, msg.text, 'ASSISTENZA')) {
await this.menuAssistenza(msg);
} else if (msg.text === Menu.LANG_IT) {
@@ -1733,7 +1770,7 @@ class Telegram {
} else if (this.isSelMenu(msg, msg.text, 'ZOOM') ||
MsgBot.PROSSIMO_ZOOM.find((rec) => msg.text.indexOf(rec) > -1)) {
await this.menuZoom(msg);
} else if (await this.IsTesto(msg)) {
} else if (!notlast && await this.IsTesto(msg)) {
// OK
} else {
await this.msgScegliMenu(msg);
@@ -1761,14 +1798,14 @@ class Telegram {
return trovato;
}
async isMenu(rec, msg) {
async isMenu(rec, msg, testo, notlast) {
if (!msg)
return;
if (msg.text === undefined)
if (testo === undefined)
return;
const arrtext = msg.text.split(' ');
const arrtext = testo.split(' ');
let cmd2 = '';
let cmd1 = arrtext[0];
if (arrtext.length > 1)
@@ -1776,56 +1813,56 @@ class Telegram {
let oldusername = rec.msgall_username_specifico;
if ((this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) ||
(this.isSelMenu(msg, msg.text, 'INDIETRO'))) {
if ((this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) ||
(this.isSelMenu(msg, testo, 'INDIETRO'))) {
rec.msgall_username_specifico = '';
} else {
if (rec.msgall_username_specifico !== '') {
await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico,
msg.text);
testo);
return true;
}
}
if (this.isSelMenu(msg, msg.text, 'LAVAGNA') ||
MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) {
if (this.isSelMenu(msg, testo, 'LAVAGNA') ||
MsgBot.LAVAGNA.find((rec) => testo.indexOf(rec) > -1)) {
await this.menuLavagna(msg);
} else if (this.isSelMenu(msg, msg.text, 'ACCEDI')) {
} else if (this.isSelMenu(msg, testo, 'ACCEDI')) {
await this.menuAccedi(msg);
} else if (this.isSelMenu(msg, msg.text, 'LINK_CONDIVIDERE')) {
} else if (this.isSelMenu(msg, testo, 'LINK_CONDIVIDERE')) {
await this.menuLinkCondividere(msg);
} else if (msg.text === Menu.EXIT_TELEGRAM) {
} else if (testo === Menu.EXIT_TELEGRAM) {
await this.menuExitToTelegram(msg);
} else if (msg.text === Menu.ADMIN) {
} else if (testo === Menu.ADMIN) {
await this.menuAdmin(msg);
} else if (msg.text === Menu.LANG) {
} else if (testo === Menu.LANG) {
await this.menuLang(msg);
} else if (msg.text === Menu.MSGATUTTI) {
} else if (testo === Menu.MSGATUTTI) {
await this.menumsgAll(msg);
} else if (msg.text === Menu.MSGSTAFF) {
} else if (testo === Menu.MSGSTAFF) {
await this.menumsgStaff(msg);
} else if (msg.text === Menu.MSGPAOLO) {
} else if (testo === Menu.MSGPAOLO) {
await this.menumsgPaolo(msg);
} else if (msg.text === Menu.MSG_NO_7_REQ) {
await this.menumsg_No_7_Req(msg);
} else if (msg.text === Menu.MSG_NO_9_REQ) {
await this.menumsg_No_9_Req(msg);
} else if (msg.text === Menu.NESSUN_IMBARCO_7REQ) {
await this.menumsgGenerico(msg, Destin.NESSUN_IMBARCO_7REQ);
} else if (cmd1 === Menu.MSG_TO_NAVE) {
await this.menumsg_to_Nave(msg, cmd2);
} else if (msg.text === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) {
await this.menumsg_Si_Invitati_No_7Req(msg);
// } else if (testo === Menu.MSG_NO_7_REQ) {
// await this.menumsg_No_7_Req(msg);
// } else if (testo === Menu.MSG_NO_9_REQ) {
// await this.menumsg_No_9_Req(msg);
// } else if (testo === Menu.NESSUN_IMBARCO_7REQ) {
// await this.menumsgGenerico(msg, Destin.NESSUN_IMBARCO_7REQ);
// } else if (cmd1 === Menu.MSG_TO_NAVE) {
// await this.menumsg_to_Nave(msg, cmd2);
// } else if (testo === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) {
// await this.menumsg_Si_Invitati_No_7Req(msg);
} else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) {
await this.menumsg_A_Utente(msg);
} else if (this.isSelMenu(msg, msg.text, 'INDIETRO') ||
(msg.text === Menu.it.INDIETRO)) {
} else if (this.isSelMenu(msg, testo, 'INDIETRO') ||
(testo === Menu.it.INDIETRO)) {
await this.msgScegliMenu(msg);
} else if (this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) {
} else if (this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) {
await this.sendMsg(msg.chat.id, 'Uscito dalla Chat con ' + oldusername);
rec.msgall_username_specifico = '';
} else {
await this.isMenuNotVerified(rec, msg);
await this.isMenuNotVerified(rec, msg, notlast);
}
}
@@ -2235,9 +2272,15 @@ class Telegram {
}
}
permitSendMsg(user) {
return User.isAdmin(user.perm)
}
async menumsgGenerico(msg, dest, username, extraparam) {
const rec = this.getRecInMem(msg);
if (rec.user) {
if (this.permitSendMsg(rec.user)) {
rec.msgall_status = StatusMSGALL.ASK;
rec.msgall_achi = dest;
rec.extraparam = extraparam;
@@ -2249,6 +2292,7 @@ class Telegram {
await this.sendMsg(msg.chat.id, mystr, MenuSend);
}
}
}
async menumsgDomanda(
msg, cmd, dest, username, extraparam, domanda, msgYes, msgNo, destYes,
@@ -2843,10 +2887,10 @@ class Telegram {
if (normale) {
// Check Menu
await this.isMenu(rec, msg);
await this.isMenu(rec, msg, msg.text, false);
}
} else {
await this.isMenuNotVerified(rec, msg);
await this.isMenuNotVerified(rec, msg, false);
}
}
@@ -2984,11 +3028,9 @@ class Telegram {
// Check if you are Admin
const user = await User.UserByIdTelegram(idapp, id);
let isAdmin = user ? user.profile.manage_telegram && user.username ===
'paoloar77' : false;
let isAdmin = user ? user.profile.manage_telegram && user.username === 'paoloar77' : false;
const isManager = user ? user.profile.manage_telegram : false;
const isVerified = user ? user.profile.teleg_id > 0 &&
user.verified_email && user.verified_by_aportador : false;
const isVerified = user ? user.profile.teleg_id > 0 && user.verified_by_aportador : false;
this.menuDb = await MyBot.findAllIdApp(idapp);
@@ -2999,15 +3041,19 @@ class Telegram {
let lang = '';
for (const rec of this.menuDb) {
if (rec.active && rec.main && rec.page === this.pagenow
rec.active_mem = false;
if (rec.active && rec.page === this.pagenow
&& ((isAdmin && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_ADMIN))
|| (isManager && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_MANAGER))
|| (isVerified && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLYIF_LOGGED))
shared_consts.VISIB_ONLYIF_VERIFIED))
|| (rec.visibility === 0))
) {
)
{
rec.active_mem = true;
if (rec.main) {
lang = rec.lang;
if (!arrlang[rec.lang])
arrlang[rec.lang] = {menu: []};
@@ -3021,6 +3067,7 @@ class Telegram {
}
arrtemp.push(rec.label);
}
}
}
@@ -3051,35 +3098,46 @@ class Telegram {
}
for (const rec of this.menuDb) {
if (rec.active_mem) {
if (rec.idapp === idapp && rec.lang === lang &&
rec.label.toLowerCase() === testo) {
return true;
}
}
}
} catch (e) {
return false;
}
return false;
}
getValueMenu(idapp, testo, lang) {
getValueMenu(idapp, rec, msg, testo, lang) {
try {
for (const rec of this.menuDb) {
if (rec.idapp === idapp && rec.lang === lang &&
rec.label.toLowerCase() === testo) {
if (rec.type === shared_consts.BOTTYPE_TEXT) {
return rec.value;
}
if (rec.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(rec.value)) {
this.pagenow = parseInt(rec.value);
for (const recdb of this.menuDb) {
if (recdb.active_mem) {
if (recdb.idapp === idapp && recdb.lang === lang &&
recdb.label.toLowerCase() === testo) {
if (recdb.type === shared_consts.BOTTYPE_TEXT) {
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_LINK) {
//++TODO: Link diretto !?
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
this.pagenow = parseInt(recdb.value);
this.pageChange = true;
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true);
return '';
}
}
}
}
}
return '';
} catch (e) {
return '';

View File

@@ -2425,6 +2425,7 @@ module.exports = {
code = str.charCodeAt(i);
if (!(code > 47 && code < 58) && // numeric (0-9)
!(code > 63 && code < 91) && // upper alpha (A-Z) // e @
(code !== 46) && // . (punto)
(code !== 95) && // _
(code !== 45) && // -
!(code > 96 && code < 123)) { // lower alpha (a-z)

View File

@@ -153,6 +153,7 @@ module.exports = {
BOTTYPE_PAGE: 1,
BOTTYPE_LINK: 2,
BOTTYPE_TEXT: 3,
BOTTYPE_MENU: 4,
CashType: {
None: 0,