Nuovo Sistema di registrazione:
tramite il BOT, viene memorizzato l'username telegram e si usa quello come username per la APP, e l'ID telegram viene passato direttamente, senza chiedere la verifica. - ospitalità (inizio).
This commit is contained in:
@@ -408,8 +408,9 @@ const MenuYesNo = {
|
||||
|
||||
const MenuAdmin = {
|
||||
it: {
|
||||
menu: [[Menu.RESTART_SRV + ' 6711', Menu.LOG_SRV + ' 6711'],
|
||||
[Menu.REBOOT_SRV+ ' 6711', Menu.it.INDIETRO]],
|
||||
menu: [
|
||||
[Menu.RESTART_SRV + ' 6711', Menu.LOG_SRV + ' 6711'],
|
||||
[Menu.REBOOT_SRV + ' 6711', Menu.it.INDIETRO]],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -439,8 +440,10 @@ const Status = {
|
||||
EXIT: -5,
|
||||
NONE: 0,
|
||||
VERIFIED: 1,
|
||||
WAITFOR_USERNAME_BO: 102,
|
||||
WAITFOR_VERIFY_CODE: 103,
|
||||
WAITFOR_USERNAME_TELEGRAM: 101,
|
||||
WAITFOR_USERNAME_INVITANTE: 104,
|
||||
SET_USERNAME_INVITANTE: 105,
|
||||
CLICK_LINK_REG: 106,
|
||||
WAITFOR_RISPOSTA: 110,
|
||||
};
|
||||
|
||||
@@ -473,6 +476,8 @@ const txt = {
|
||||
MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Scegli una voce di menu:' +
|
||||
emoji.get('dizzy'),
|
||||
MSG_ASK_USERNAME_BO: 'Scrivete nel messaggio l\'username (SENZA SPAZI) o la email con cui vi siete registrati sul sito di %s:',
|
||||
MSG_ASK_USERNAME_INVITANTE: 'Scrivi l\'username di chi ti ha invitato su %s (non inserire spazi)',
|
||||
MSG_ERRORE_INVITANTE_NOT_FOUND: 'L\'username dell\'invitante appena digitato non sembra essere corretto!',
|
||||
MSG_ERRORE_USERNAME: 'Attenzione! Devi inserire solo lo username (40 caratteri massimo)',
|
||||
MSG_ERRORE_USERNAME_NOT_FOUND: 'Per Completare la Verifica Telegram BOT, dovete ora scrivere qui sotto nel messaggio l\'Username (senza spazi) OPPURE la email con cui vi siete registrati sul sito',
|
||||
MSG_ERRORE_USERNAME_ANNULLA: 'Inserimento Annullato. Riprovare',
|
||||
@@ -496,13 +501,26 @@ const txt = {
|
||||
MSG_APORTADOR_DEST_CONFIRMED: '✅ Sei stato Abilitato correttamente da %s!\n' +
|
||||
'Vai sulla App oppure clicca qui per entrare\n👉🏻 %s',
|
||||
MSG_GROUP_CONFIRMED: '✅ Sei stato Aggiunto sul Gruppo %s!',
|
||||
MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK + '🚫 Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s.<br>Contattalo per farti abilitare !',
|
||||
MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK +
|
||||
'🚫 Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s.<br>Contattalo per farti abilitare !',
|
||||
MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK + '🚫 %s Non è stato Abilitato !',
|
||||
MSG_ISCRITTO_CONACREIS: emo.FIRE + ' Si è appena Iscritto al Conacreis "%s"',
|
||||
MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !',
|
||||
MSG_MSG_TOSENT: emoji.get('envelope') + ' Messaggi da Inviare',
|
||||
MSG_MSG_INCORSO: emoji.get('envelope') +
|
||||
' messaggi in corso... Inviati attualmente',
|
||||
MSG_MSG_INCORSO: emoji.get('envelope') + ' messaggi in corso... Inviati attualmente',
|
||||
MSG_SET_USERNAME_TELEGRAM: '[Prima di continuare con la registrazione in RISO.APP]\n' +
|
||||
'Segui questi passi per <b>IMPOSTARE UN USERNAME IN TELEGRAM</b>: \n\n' +
|
||||
'1. premi sull\'icona con <b>3 linee orizzontali</b>, in alto a sinistra (sull\'iPhone si chiama "Impostazioni").\n' +
|
||||
'Per vederlo premi INDIETRO (si chiuderà questa chat).\n\n' +
|
||||
'2. Seleziona la voce <b>IMPOSTAZIONI</b> dalla lista.\n\n' +
|
||||
'3.Premi su <b>USERNAME</b> nella sezione account.\n\n' +
|
||||
'4. Digita un username (o nome utente) qualsiasi a tua scelta, se è già usato aggiungi dei numeri.\n\n' +
|
||||
'5. Per confermare premi sull\'icona con la spunta (V) in alto a destra.\n\n' +
|
||||
'🏁 6. Infine ritorna su questa chat BOT e scrivi OK nel messaggio. \n\n' +
|
||||
' Se non riesci a fare questi passaggi, clicca qui: \n' +
|
||||
'👉🏻 https://www.nigiara.it/telegram/come-impostare-uno-username-su-telegram.htm ',
|
||||
MSG_SIGNUP: 'Per registrarti su %s:',
|
||||
|
||||
};
|
||||
|
||||
const txt_es = {
|
||||
@@ -1345,7 +1363,7 @@ class Telegram {
|
||||
}
|
||||
}
|
||||
|
||||
async start(msg) {
|
||||
async settotheDatabase(msg) {
|
||||
|
||||
// Check if Present to the DB
|
||||
const riscreate = await this.createIfNotExist(msg);
|
||||
@@ -1357,12 +1375,21 @@ class Telegram {
|
||||
|
||||
if (rec.user)
|
||||
rec.status = Status.VERIFIED;
|
||||
} else {
|
||||
// await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', tools.getNomeAppByIdApp(this.idapp)), MenuNoLogin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async start(msg) {
|
||||
|
||||
// Check if Username Telegram Present
|
||||
if (!msg.from.username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await this.settotheDatabase(msg);
|
||||
|
||||
}
|
||||
|
||||
geturlfaq() {
|
||||
return tools.getHostByIdApp(this.idapp) + '/faq';
|
||||
}
|
||||
@@ -1463,10 +1490,10 @@ class Telegram {
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!rec.user.profile.username_telegram) {
|
||||
return this.checkIfUsernameTelegramSet(msg, rec.user);
|
||||
}
|
||||
/*} else {
|
||||
if (!rec.user.profile.username_telegram) {
|
||||
return this.checkIfUsernameTelegramSet(msg, rec.user);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1875,10 +1902,6 @@ class Telegram {
|
||||
|
||||
async menuAccedi(msg) {
|
||||
let status = this.getstatusInMemory(msg);
|
||||
if (status === Status.WAITFOR_USERNAME_BO) {
|
||||
await this.sendMsg(msg.from.id,
|
||||
getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'));
|
||||
}
|
||||
}
|
||||
|
||||
getlang(msg) {
|
||||
@@ -2216,7 +2239,8 @@ class Telegram {
|
||||
}
|
||||
|
||||
nonAbilitato(msg) {
|
||||
MyTelegramBot.local_sendMsgTelegramByIdTelegram(this.idapp, msg.chat.id, 'Utente Non abilitato o codice non valido ad eseguire questa funzione');
|
||||
MyTelegramBot.local_sendMsgTelegramByIdTelegram(this.idapp, msg.chat.id,
|
||||
'Utente Non abilitato o codice non valido ad eseguire questa funzione');
|
||||
}
|
||||
|
||||
chisono(rec) {
|
||||
@@ -2228,9 +2252,10 @@ class Telegram {
|
||||
async menuRestartSrv(rec, msg, cmd2) {
|
||||
if (cmd2 === '6711') {
|
||||
await MyTelegramBot.sendMsgTelegramToTheAdminAllSites(this.chisono(rec) + ' ha rilanciato il Server NODE.JS...');
|
||||
const ris = await tools.execScript(this.idapp, msg, '~/batch/production_restart_server.sh', this.chisono(rec) + ' Restart il Server (Node.Js)');
|
||||
const ris = await tools.execScript(this.idapp, msg, '~/batch/production_restart_server.sh',
|
||||
this.chisono(rec) + ' Restart il Server (Node.Js)');
|
||||
} else {
|
||||
this.nonAbilitato(msg)
|
||||
this.nonAbilitato(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2238,16 +2263,17 @@ class Telegram {
|
||||
if (cmd2 === '6711') {
|
||||
const ris = await tools.execScript(this.idapp, msg, '~/batch/logserver.sh', this.chisono(rec) + ' Visualizzo il Log del Server...');
|
||||
} else {
|
||||
this.nonAbilitato(msg)
|
||||
this.nonAbilitato(msg);
|
||||
}
|
||||
}
|
||||
|
||||
async menuRebootSrv(rec, msg, cmd2) {
|
||||
if (cmd2 === '6711') {
|
||||
await MyTelegramBot.sendMsgTelegramToTheAdminAllSites(this.chisono(rec) + ' ha effettuato il Reboot del Server! ...');
|
||||
const ris = await tools.execScript(this.idapp, msg, '~/batch/esegui_reboot.sh', this.chisono(rec) + ' Eseguo il Reboot del Server !...');
|
||||
const ris = await tools.execScript(this.idapp, msg, '~/batch/esegui_reboot.sh',
|
||||
this.chisono(rec) + ' Eseguo il Reboot del Server !...');
|
||||
} else {
|
||||
this.nonAbilitato(msg)
|
||||
this.nonAbilitato(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2432,41 +2458,19 @@ class Telegram {
|
||||
}
|
||||
|
||||
async setUsernameBo(msg) {
|
||||
|
||||
}
|
||||
|
||||
async askUsernameInvitante(msg) {
|
||||
try {
|
||||
let rec = this.getRecInMem(msg);
|
||||
if (msg.text === undefined)
|
||||
return false;
|
||||
|
||||
console.log('msg.text', msg.text);
|
||||
const text = msg.text;
|
||||
if (text.length < 40) {
|
||||
if (rec) {
|
||||
let ris = await this.getUser(msg, rec, true);
|
||||
rec = ris.rec;
|
||||
if (rec) {
|
||||
rec.status = Status.SET_USERNAME_INVITANTE;
|
||||
await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_INVITANTE', tools.getNomeAppByIdApp(this.idapp), null));
|
||||
|
||||
if (ris.ok) {
|
||||
rec.user = ris.user;
|
||||
await User.SetTelegramCheckCode(this.idapp, ris.myid.toString(),
|
||||
rec.code);
|
||||
rec.status = Status.WAITFOR_VERIFY_CODE;
|
||||
await this.sendMsg(msg.from.id,
|
||||
getstr(this.getlang(msg), 'MSG_VERIFY_CODE',
|
||||
tools.getHostByIdApp(this.idapp)), null);
|
||||
} else {
|
||||
await this.sendMsg(msg.chat.id,
|
||||
getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO',
|
||||
tools.getNomeAppByIdApp(this.idapp)), null);
|
||||
}
|
||||
}
|
||||
} else if (text.length === 0) {
|
||||
if (rec)
|
||||
rec.status = Status.NONE;
|
||||
await this.sendMsg(msg.from.id,
|
||||
getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_ANNULLA'));
|
||||
this.deleteRecInMem(msg);
|
||||
} else {
|
||||
await this.sendMsg(msg.from.id,
|
||||
getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error setUsernameBo:', e);
|
||||
@@ -2484,13 +2488,85 @@ class Telegram {
|
||||
}
|
||||
}
|
||||
|
||||
async checkIfUsernameTelegramSet(msg, myuser) {
|
||||
async sendMsgByTemplateByMsgStrutt(title, msg) {
|
||||
|
||||
try {
|
||||
let langcode = 'it';
|
||||
let id = 0;
|
||||
try {
|
||||
langcode = msg.from.language_code;
|
||||
id = msg.from.id;
|
||||
} catch (e) {
|
||||
}
|
||||
const mymsg = await MsgTemplate.getMsgByTitleAndLang(tools.RISO, title, langcode);
|
||||
const mytext = tools.convertSpecialTags(null, mymsg.body);
|
||||
if (id > 0)
|
||||
return this.sendMsg(id, mytext);
|
||||
} catch (e) {
|
||||
console.error('ERR sendMsgByTemplateByMsgStrutt', e);
|
||||
}
|
||||
}
|
||||
|
||||
async sendMsgByTextByMsgStrutt(keytext, msg) {
|
||||
|
||||
try {
|
||||
let langcode = 'it';
|
||||
let id = 0;
|
||||
try {
|
||||
id = msg.from.id;
|
||||
langcode = msg.from.language_code;
|
||||
} catch (e) {
|
||||
}
|
||||
const text = getstr(langcode, keytext);
|
||||
const mytext = tools.convertSpecialTags(null, text);
|
||||
if (id > 0)
|
||||
return this.sendMsg(id, mytext);
|
||||
} catch (e) {
|
||||
console.error('ERR sendMsgByTextByMsgStrutt', e);
|
||||
}
|
||||
}
|
||||
|
||||
async checkIfUsernameTelegramSet(msg) {
|
||||
try {
|
||||
if (!msg.from.username) {
|
||||
await this.sendMsgByTemplate('MSG_SET_USERNAME', myuser);
|
||||
//await this.sendMsgByTemplateByMsgStrutt('MSG_SET_USERNAME', msg);
|
||||
await this.sendMsgByTextByMsgStrutt('MSG_SET_USERNAME_TELEGRAM', msg);
|
||||
return false;
|
||||
//await this.sendMsgByTemplate('MSG_SET_USERNAME', myuser);
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async setUsernameInvitante(msg) {
|
||||
try {
|
||||
if (!!msg.text) {
|
||||
const rec = this.getRecInMem(msg);
|
||||
let aportador_solidario = rec.aportador_solidario;
|
||||
if (!aportador_solidario) {
|
||||
aportador_solidario = msg.text.toString().trim().toLowerCase();
|
||||
const user = await User.getUserShortDataByUsername(this.idapp, aportador_solidario);
|
||||
if (user)
|
||||
rec.aportador_solidario = user.username;
|
||||
}
|
||||
if (rec.aportador_solidario) {
|
||||
|
||||
// Link per Registrarsi
|
||||
this.asktoRegistrationByLink(msg);
|
||||
|
||||
} else {
|
||||
rec.status = Status.WAITFOR_USERNAME_INVITANTE;
|
||||
|
||||
const str2 = '\n' + getstr(this.getlang(msg), 'MSG_ASK_USERNAME_INVITANTE', tools.getNomeAppByIdApp(this.idapp));
|
||||
|
||||
await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_INVITANTE_NOT_FOUND') + str2, null);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error setUsernameInvitante', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2535,7 +2611,7 @@ class Telegram {
|
||||
console.log(' ... MA GLI MANCA L\'USERNAME TELEGRAM !! ');
|
||||
}
|
||||
|
||||
this.checkIfUsernameTelegramSet(msg, recuser);
|
||||
// this.checkIfUsernameTelegramSet(msg, recuser);
|
||||
// local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg);
|
||||
} else {
|
||||
this.sendMsgLog(msg.from.id, getstr(this.getlang(msg), 'MSG_ERR_UNKNOWN_VERIFY_CODE'));
|
||||
@@ -2830,6 +2906,11 @@ class Telegram {
|
||||
|
||||
async receiveMsg(msg) {
|
||||
|
||||
// Check if Username Telegram Present
|
||||
if (!this.checkIfUsernameTelegramSet(msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let status = await this.setInit(msg);
|
||||
|
||||
if (status === Status.EXIT) {
|
||||
@@ -2839,11 +2920,14 @@ class Telegram {
|
||||
const rec = this.getRecInMem(msg);
|
||||
|
||||
status = this.getstatus(rec);
|
||||
if (status === Status.WAITFOR_USERNAME_BO && !this.selectMenuHelp(msg) &&
|
||||
!this.selectMenuLang(msg)) {
|
||||
await this.setUsernameBo(msg);
|
||||
} else if (status === Status.WAITFOR_VERIFY_CODE) {
|
||||
await this.setVerifyCode(msg);
|
||||
if (status === Status.WAITFOR_USERNAME_TELEGRAM && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) {
|
||||
// await this.setUsernameBo(msg);
|
||||
await this.settotheDatabase(msg);
|
||||
} else if (status === Status.WAITFOR_USERNAME_INVITANTE && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) {
|
||||
await this.askUsernameInvitante(msg);
|
||||
// await this.settotheDatabase(msg);
|
||||
} else if (status === Status.SET_USERNAME_INVITANTE) {
|
||||
await this.setUsernameInvitante(msg);
|
||||
} else if (status === Status.NONE) {
|
||||
await this.start(msg);
|
||||
} else if (status === Status.VERIFIED) {
|
||||
@@ -2924,18 +3008,47 @@ class Telegram {
|
||||
}
|
||||
}
|
||||
|
||||
async askVerifiedCode(msg) {
|
||||
async asktoRegistrationByLink(msg) {
|
||||
|
||||
const rec = this.getRecInMem(msg);
|
||||
|
||||
let visu = false;
|
||||
|
||||
if (!rec) {
|
||||
await this.addUser(msg);
|
||||
|
||||
// await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), printf(txt.MSG_ASK_USERNAME_BO, tools.getHostByIdApp(this.idapp))));
|
||||
await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', tools.getNomeAppByIdApp(this.idapp)), null);
|
||||
visu = true;
|
||||
|
||||
}
|
||||
|
||||
if (rec && !rec.username_bo)
|
||||
visu = true;
|
||||
|
||||
if (visu) {
|
||||
|
||||
const status = this.getstatus(rec);
|
||||
if (status === Status.SET_USERNAME_INVITANTE && rec.aportador_solidario) {
|
||||
let linkreg = tools.getLinkRegByIdAppAndMsgStrutt(this.idapp, msg);
|
||||
|
||||
if (process.env.LOCALE === '1') {
|
||||
linkreg = 'http://192.168.1.115:8084/signup/' + rec.aportador_solidario + '/' + msg.from.username + '/' + msg.from.id;
|
||||
}
|
||||
|
||||
const keyb = this.getInlineKeyboard(this.getlang(msg), [
|
||||
{
|
||||
text: '✅ CLICCA QUI ',
|
||||
url: linkreg,
|
||||
},
|
||||
]);
|
||||
|
||||
// await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), printf(txt.MSG_ASK_USERNAME_BO, tools.getHostByIdApp(this.idapp))));
|
||||
await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_SIGNUP', tools.getNomeAppByIdApp(this.idapp)), null, keyb);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -3003,7 +3116,6 @@ class Telegram {
|
||||
id: this.getchatid(msg),
|
||||
code,
|
||||
lang,
|
||||
status: Status.WAITFOR_USERNAME_BO,
|
||||
statusmsg: 0,
|
||||
msgcodeprec: '',
|
||||
sex: 0,
|
||||
@@ -3029,8 +3141,15 @@ class Telegram {
|
||||
menuSaved: {},
|
||||
pagenow: 1,
|
||||
menuDb: null,
|
||||
aportador_solidario: '',
|
||||
};
|
||||
|
||||
if (!msg.from.username) {
|
||||
rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
|
||||
} else {
|
||||
rec.status = Status.WAITFOR_USERNAME_INVITANTE;
|
||||
}
|
||||
|
||||
this.arrUsers.push(rec);
|
||||
|
||||
return rec;
|
||||
@@ -3039,7 +3158,7 @@ class Telegram {
|
||||
|
||||
async insertIntoDB(msg) {
|
||||
|
||||
return this.askVerifiedCode(msg);
|
||||
return this.asktoRegistrationByLink(msg);
|
||||
|
||||
}
|
||||
|
||||
@@ -3071,7 +3190,7 @@ 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: false;
|
||||
let isAdmin = user ? user.profile.manage_telegram : false;
|
||||
const isManager = user ? user.profile.manage_telegram : false;
|
||||
const isVerified = user ? user.profile.teleg_id > 0 && user.verified_by_aportador : false;
|
||||
|
||||
@@ -3280,7 +3399,6 @@ class Telegram {
|
||||
// text = text.replace(/<\/div>/g, '');
|
||||
text = text.replace(/ /g, ' ');
|
||||
|
||||
|
||||
if (!form) {
|
||||
form = {
|
||||
'parse_mode': 'HTML',
|
||||
|
||||
Reference in New Issue
Block a user