Togliere "in attesa di abilitazione"
Registrazione rapida (senza dover confermare, un link che scade dopo 48 ore.
This commit is contained in:
@@ -83,8 +83,8 @@ MsgTemplateSchema.statics.getMsgByLang = async function (idapp, myuser, typemsg,
|
|||||||
body = mymsg["msg_it"]
|
body = mymsg["msg_it"]
|
||||||
title = mymsg["title_it"]
|
title = mymsg["title_it"]
|
||||||
}
|
}
|
||||||
body = tools.convertSpecialTags(myuser, body);
|
body = await tools.convertSpecialTags(myuser, body);
|
||||||
title = tools.convertSpecialTags(myuser, title);
|
title = await tools.convertSpecialTags(myuser, title);
|
||||||
return { body, title }
|
return { body, title }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,12 @@ const UserSchema = new mongoose.Schema({
|
|||||||
tokenforgot: {
|
tokenforgot: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
date_tokenreg: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
tokenreg: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
lasttimeonline: {
|
lasttimeonline: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
@@ -733,6 +739,8 @@ UserSchema.statics.getProjectUser = function() {
|
|||||||
email: 1,
|
email: 1,
|
||||||
date_reg: 1,
|
date_reg: 1,
|
||||||
img: 1,
|
img: 1,
|
||||||
|
tokenreg: 1,
|
||||||
|
date_tokenreg: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1204,6 +1212,57 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function(idap
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getifRegTokenIsValid = async function(idapp, tokenreg) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
let regexp = new RegExp(`^${tokenreg}$`, 'i');
|
||||||
|
|
||||||
|
const user = await User.findOne({
|
||||||
|
idapp,
|
||||||
|
tokenreg: {$regex: regexp}
|
||||||
|
});
|
||||||
|
if (user && user.date_tokenreg) {
|
||||||
|
return user.date_tokenreg > (new Date().getTime());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UserSchema.statics.createNewReqRegistrationGetLink = async function(idapp, username) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
const user = await User.findOne({
|
||||||
|
idapp,
|
||||||
|
username,
|
||||||
|
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
if (!user.date_tokenreg || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) {
|
||||||
|
// Se è scaduto, ne crea uno nuovo
|
||||||
|
// Creo il tokenforgot
|
||||||
|
user.tokenreg = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
||||||
|
toString();
|
||||||
|
|
||||||
|
user.tokenreg = user.tokenreg.replaceAll('.', '');
|
||||||
|
user.tokenreg = user.tokenreg.replaceAll('/', '');
|
||||||
|
user.tokenreg = user.tokenreg.substring(1,8);
|
||||||
|
|
||||||
|
user.date_tokenreg = tools.AddDate(new Date(), 2);
|
||||||
|
|
||||||
|
return await user.save().then(() => {
|
||||||
|
return user.tokenreg;
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return user.tokenreg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.findByEmail = function(idapp, email, onlyifVerifiedByAportador) {
|
UserSchema.statics.findByEmail = function(idapp, email, onlyifVerifiedByAportador) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,16 @@ router.post('/', async (req, res) => {
|
|||||||
user.date_reg = new Date();
|
user.date_reg = new Date();
|
||||||
user.aportador_iniziale = user.aportador_solidario;
|
user.aportador_iniziale = user.aportador_solidario;
|
||||||
|
|
||||||
if (!tools.getAskToVerifyReg(body.idapp)) {
|
let regexpire = req.body['regexpire'];
|
||||||
|
let nonchiedereverifica = false;
|
||||||
|
if (regexpire) {
|
||||||
|
nonchiedereverifica = await User.getifRegTokenIsValid(body.idapp, regexpire);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nonchiedereverifica)
|
||||||
|
regexpire = '';
|
||||||
|
|
||||||
|
if (!tools.getAskToVerifyReg(body.idapp) || nonchiedereverifica) {
|
||||||
// Se non devo chiedere di verificare all'Invitato, allora lo verifico direttamente
|
// Se non devo chiedere di verificare all'Invitato, allora lo verifico direttamente
|
||||||
user.verified_by_aportador = true;
|
user.verified_by_aportador = true;
|
||||||
}
|
}
|
||||||
@@ -319,7 +328,7 @@ router.post('/', async (req, res) => {
|
|||||||
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
||||||
console.log('res.locale', res.locale);
|
console.log('res.locale', res.locale);
|
||||||
|
|
||||||
await telegrambot.askConfirmationUser(user.idapp, shared_consts.CallFunz.REGISTRATION, user);
|
await telegrambot.askConfirmationUser(user.idapp, shared_consts.CallFunz.REGISTRATION, user, '', '', '', regexpire);
|
||||||
|
|
||||||
// if (!tools.testing()) {
|
// if (!tools.testing()) {
|
||||||
await sendemail.sendEmail_Registration(user.lang, user.email, user,
|
await sendemail.sendEmail_Registration(user.lang, user.email, user,
|
||||||
|
|||||||
@@ -820,7 +820,7 @@ const MyTelegramBot = {
|
|||||||
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
|
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
|
||||||
},
|
},
|
||||||
|
|
||||||
askConfirmationUser: async function(idapp, myfunc, myuser, userDest = '', groupname = '', groupid = '') {
|
askConfirmationUser: async function(idapp, myfunc, myuser, userDest = '', groupname = '', groupid = '', regexpire = '') {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cl = getclTelegByidapp(idapp);
|
const cl = getclTelegByidapp(idapp);
|
||||||
@@ -846,7 +846,16 @@ const MyTelegramBot = {
|
|||||||
await cl.sendMsg(telegid, rismsg2.body);
|
await cl.sendMsg(telegid, rismsg2.body);
|
||||||
|
|
||||||
userDest = myuser.aportador_solidario;
|
userDest = myuser.aportador_solidario;
|
||||||
const notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
|
let notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
|
||||||
|
|
||||||
|
let useraportador = await User.getUserShortDataByUsername(idapp, userDest);
|
||||||
|
|
||||||
|
if (useraportador && useraportador.tokenreg && (regexpire.toLowerCase() === useraportador.tokenreg.toLowerCase())) {
|
||||||
|
const nonchiedereverifica = await User.getifRegTokenIsValid(idapp, useraportador.tokenreg);
|
||||||
|
if (nonchiedereverifica)
|
||||||
|
notask_verif = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (notask_verif) {
|
if (notask_verif) {
|
||||||
// Non chiedi la verifica Registrazione
|
// Non chiedi la verifica Registrazione
|
||||||
@@ -1044,7 +1053,7 @@ const MyTelegramBot = {
|
|||||||
|
|
||||||
const cl = getclTelegByidapp(user.idapp);
|
const cl = getclTelegByidapp(user.idapp);
|
||||||
if (cl) {
|
if (cl) {
|
||||||
msg = tools.convertSpecialTags(rec.user, msg);
|
msg = await tools.convertSpecialTags(rec.user, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!mydata.flotta) {
|
if (!!mydata.flotta) {
|
||||||
@@ -1692,7 +1701,7 @@ class Telegram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
risp = tools.convertSpecialTags(rec.user, risp);
|
risp = await tools.convertSpecialTags(rec.user, risp);
|
||||||
|
|
||||||
let keyboard = null;
|
let keyboard = null;
|
||||||
|
|
||||||
@@ -2526,7 +2535,7 @@ class Telegram {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const msg = await MsgTemplate.getMsgByTitleAndLang(myuser.idapp, title, myuser.lang);
|
const msg = await MsgTemplate.getMsgByTitleAndLang(myuser.idapp, title, myuser.lang);
|
||||||
const mytext = tools.convertSpecialTags(myuser, msg.body);
|
const mytext = await tools.convertSpecialTags(myuser, msg.body);
|
||||||
return await this.sendMsg(myuser.profile.teleg_id, mytext);
|
return await this.sendMsg(myuser.profile.teleg_id, mytext);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERR sendMsgByTemplate', e);
|
console.error('ERR sendMsgByTemplate', e);
|
||||||
@@ -2544,7 +2553,7 @@ class Telegram {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
const mymsg = await MsgTemplate.getMsgByTitleAndLang(tools.RISO, title, langcode);
|
const mymsg = await MsgTemplate.getMsgByTitleAndLang(tools.RISO, title, langcode);
|
||||||
const mytext = tools.convertSpecialTags(null, mymsg.body);
|
const mytext = await tools.convertSpecialTags(null, mymsg.body);
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
return await this.sendMsg(id, mytext);
|
return await this.sendMsg(id, mytext);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -2563,7 +2572,7 @@ class Telegram {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
const text = getstr(langcode, keytext);
|
const text = getstr(langcode, keytext);
|
||||||
const mytext = tools.convertSpecialTags(null, text);
|
const mytext = await tools.convertSpecialTags(null, text);
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
return await this.sendMsg(id, mytext);
|
return await this.sendMsg(id, mytext);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -2850,7 +2859,7 @@ class Telegram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inviaveramente) {
|
if (inviaveramente) {
|
||||||
textdainviare = tools.convertSpecialTags(utente, textdainviare);
|
textdainviare = await tools.convertSpecialTags(utente, textdainviare);
|
||||||
|
|
||||||
if (destin === Destin.A_UTENTE) {
|
if (destin === Destin.A_UTENTE) {
|
||||||
await this.sistemaRecDest(rec, msg);
|
await this.sistemaRecDest(rec, msg);
|
||||||
@@ -2965,13 +2974,18 @@ class Telegram {
|
|||||||
|
|
||||||
let mymsg = msg.text.toString().trim().toLowerCase();
|
let mymsg = msg.text.toString().trim().toLowerCase();
|
||||||
let invitante = '';
|
let invitante = '';
|
||||||
|
let regexpire = '';
|
||||||
if (mymsg.startsWith('/start')) {
|
if (mymsg.startsWith('/start')) {
|
||||||
let myarrmsg = mymsg.split(' ');
|
let myarrmsg = mymsg.split(' ');
|
||||||
if (myarrmsg.length > 0) {
|
if (myarrmsg.length > 0) {
|
||||||
mymsg = myarrmsg[1];
|
mymsg = myarrmsg[1];
|
||||||
if (mymsg.startsWith('inv_')) {
|
if (mymsg.startsWith('inv_')) {
|
||||||
invitante = mymsg.substring(4);
|
let arrparams = mymsg.split('_');
|
||||||
return invitante;
|
if (arrparams.length > 2) {
|
||||||
|
invitante = arrparams[1];
|
||||||
|
regexpire = arrparams[3];
|
||||||
|
}
|
||||||
|
return {invitante, regexpire};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2981,15 +2995,16 @@ class Telegram {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async setInvitante(msg, invitante, crea) {
|
async setInvitante(msg, ris, crea) {
|
||||||
let rec = this.getRecInMem(msg);
|
let rec = this.getRecInMem(msg);
|
||||||
if (!rec && crea) {
|
if (!rec && crea) {
|
||||||
let status = await this.setInit(msg);
|
let status = await this.setInit(msg);
|
||||||
rec = this.getRecInMem(msg);
|
rec = this.getRecInMem(msg);
|
||||||
}
|
}
|
||||||
if (rec) {
|
if (rec) {
|
||||||
if (!rec.aportador_solidario && invitante) {
|
if (!rec.aportador_solidario && ris && ris.invitante) {
|
||||||
rec.aportador_solidario = invitante;
|
rec.aportador_solidario = ris.invitante;
|
||||||
|
rec.regexpire = ris.regexpire;
|
||||||
rec.status = Status.SET_USERNAME_INVITANTE;
|
rec.status = Status.SET_USERNAME_INVITANTE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3018,17 +3033,9 @@ class Telegram {
|
|||||||
await this.askUsernameInvitante(msg, true);
|
await this.askUsernameInvitante(msg, true);
|
||||||
// await this.settotheDatabase(msg);
|
// await this.settotheDatabase(msg);
|
||||||
} else if (status === Status.SET_USERNAME_INVITANTE) {
|
} else if (status === Status.SET_USERNAME_INVITANTE) {
|
||||||
let mymsg = msg.text.toString().trim().toLowerCase();
|
const ris = this.getInvitanteByMsg(msg);
|
||||||
let invitante = '';
|
if (ris.invitante) {
|
||||||
if (mymsg && mymsg.startsWith('/start')) {
|
await this.setInvitante(msg, ris, true);
|
||||||
let myarrmsg = mymsg.split(' ');
|
|
||||||
if (myarrmsg.length > 0) {
|
|
||||||
mymsg = myarrmsg[1];
|
|
||||||
if (mymsg && mymsg.startsWith('inv_')) {
|
|
||||||
invitante = mymsg.substring(4);
|
|
||||||
await this.setInvitante(msg, invitante);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.setUsernameInvitante(msg);
|
await this.setUsernameInvitante(msg);
|
||||||
@@ -3857,19 +3864,6 @@ if (true) {
|
|||||||
|
|
||||||
const myclTelegram = getclTelegBytoken(bot.token);
|
const myclTelegram = getclTelegBytoken(bot.token);
|
||||||
|
|
||||||
let mymsg = msg.text.toString().trim().toLowerCase();
|
|
||||||
let invitante = '';
|
|
||||||
if (mymsg && mymsg.startsWith('/start')) {
|
|
||||||
let myarrmsg = mymsg.split(' ');
|
|
||||||
if (myarrmsg.length > 0) {
|
|
||||||
mymsg = myarrmsg[1];
|
|
||||||
if (mymsg && mymsg.startsWith('inv_')) {
|
|
||||||
invitante = mymsg.substring(4);
|
|
||||||
// await myclTelegram.setInvitante(msg, invitante);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// const chatId = msg.chat.id;
|
// const chatId = msg.chat.id;
|
||||||
myclTelegram.receiveMsg(msg);
|
myclTelegram.receiveMsg(msg);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1364,11 +1364,17 @@ module.exports = {
|
|||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getTimeExpReg: async function(idapp, username) {
|
||||||
|
var {User} = require('../models/user');
|
||||||
|
|
||||||
|
return await User.createNewReqRegistrationGetLink(idapp, username);
|
||||||
|
},
|
||||||
|
|
||||||
getLinkRegByIdAppAndMsgStrutt: function(idapp, msg, rec) {
|
getLinkRegByIdAppAndMsgStrutt: function(idapp, msg, rec) {
|
||||||
|
|
||||||
let myapp = this.getHostByIdApp(idapp);
|
let myapp = this.getHostByIdApp(idapp);
|
||||||
if (myapp) {
|
if (myapp) {
|
||||||
myapp += '/signup/' + rec.aportador_solidario + '/' + msg.from.username + '/' + msg.from.id;
|
myapp += '/signup/' + rec.aportador_solidario + '/' + msg.from.username + '/' + msg.from.id + '/' + rec.regexpire;
|
||||||
}
|
}
|
||||||
|
|
||||||
return myapp;
|
return myapp;
|
||||||
@@ -3203,14 +3209,25 @@ module.exports = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
convertSpecialTags(user, msg) {
|
async checkStr(msg, mystr, user, cmd) {
|
||||||
|
if (msg.includes(mystr)) {
|
||||||
|
if (cmd === 1) {
|
||||||
|
msg = msg.replace(mystr, await this.getTimeExpReg(user.idapp, user.username));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
},
|
||||||
|
|
||||||
|
async convertSpecialTags(user, msg) {
|
||||||
try {
|
try {
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
if (!!user) {
|
if (!!user) {
|
||||||
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
|
if (msg.includes('{appname}'))
|
||||||
|
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
|
||||||
msg = msg.replace('{username}', user.username);
|
msg = msg.replace('{username}', user.username);
|
||||||
|
msg = await this.checkStr(msg, '{time_exp_reg}', user, 1);
|
||||||
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
||||||
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
||||||
msg = msg.replace('{aportador_solidario}', user.aportador_solidario ? user.aportador_solidario : '');
|
msg = msg.replace('{aportador_solidario}', user.aportador_solidario ? user.aportador_solidario : '');
|
||||||
|
|||||||
@@ -367,8 +367,8 @@ module.exports = {
|
|||||||
|
|
||||||
for (const user of arrusers) {
|
for (const user of arrusers) {
|
||||||
|
|
||||||
const mytitle = tools.convertSpecialTags(user, params.title);
|
const mytitle = await tools.convertSpecialTags(user, params.title);
|
||||||
const mycontent = tools.convertSpecialTags(user, params.content);
|
const mycontent = await tools.convertSpecialTags(user, params.content);
|
||||||
|
|
||||||
let risult = null;
|
let risult = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user