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"]
|
||||
title = mymsg["title_it"]
|
||||
}
|
||||
body = tools.convertSpecialTags(myuser, body);
|
||||
title = tools.convertSpecialTags(myuser, title);
|
||||
body = await tools.convertSpecialTags(myuser, body);
|
||||
title = await tools.convertSpecialTags(myuser, title);
|
||||
return { body, title }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,12 @@ const UserSchema = new mongoose.Schema({
|
||||
tokenforgot: {
|
||||
type: String,
|
||||
},
|
||||
date_tokenreg: {
|
||||
type: Date,
|
||||
},
|
||||
tokenreg: {
|
||||
type: String,
|
||||
},
|
||||
lasttimeonline: {
|
||||
type: Date,
|
||||
},
|
||||
@@ -733,6 +739,8 @@ UserSchema.statics.getProjectUser = function() {
|
||||
email: 1,
|
||||
date_reg: 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) {
|
||||
const User = this;
|
||||
|
||||
|
||||
@@ -122,7 +122,16 @@ router.post('/', async (req, res) => {
|
||||
user.date_reg = new Date();
|
||||
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
|
||||
user.verified_by_aportador = true;
|
||||
}
|
||||
@@ -319,7 +328,7 @@ router.post('/', async (req, res) => {
|
||||
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
||||
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()) {
|
||||
await sendemail.sendEmail_Registration(user.lang, user.email, user,
|
||||
|
||||
@@ -820,7 +820,7 @@ const MyTelegramBot = {
|
||||
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 {
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
@@ -846,7 +846,16 @@ const MyTelegramBot = {
|
||||
await cl.sendMsg(telegid, rismsg2.body);
|
||||
|
||||
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) {
|
||||
// Non chiedi la verifica Registrazione
|
||||
@@ -1044,7 +1053,7 @@ const MyTelegramBot = {
|
||||
|
||||
const cl = getclTelegByidapp(user.idapp);
|
||||
if (cl) {
|
||||
msg = tools.convertSpecialTags(rec.user, msg);
|
||||
msg = await tools.convertSpecialTags(rec.user, msg);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -2526,7 +2535,7 @@ class Telegram {
|
||||
|
||||
try {
|
||||
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);
|
||||
} catch (e) {
|
||||
console.error('ERR sendMsgByTemplate', e);
|
||||
@@ -2544,7 +2553,7 @@ class Telegram {
|
||||
} catch (e) {
|
||||
}
|
||||
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)
|
||||
return await this.sendMsg(id, mytext);
|
||||
} catch (e) {
|
||||
@@ -2563,7 +2572,7 @@ class Telegram {
|
||||
} catch (e) {
|
||||
}
|
||||
const text = getstr(langcode, keytext);
|
||||
const mytext = tools.convertSpecialTags(null, text);
|
||||
const mytext = await tools.convertSpecialTags(null, text);
|
||||
if (id > 0)
|
||||
return await this.sendMsg(id, mytext);
|
||||
} catch (e) {
|
||||
@@ -2850,7 +2859,7 @@ class Telegram {
|
||||
}
|
||||
|
||||
if (inviaveramente) {
|
||||
textdainviare = tools.convertSpecialTags(utente, textdainviare);
|
||||
textdainviare = await tools.convertSpecialTags(utente, textdainviare);
|
||||
|
||||
if (destin === Destin.A_UTENTE) {
|
||||
await this.sistemaRecDest(rec, msg);
|
||||
@@ -2965,13 +2974,18 @@ class Telegram {
|
||||
|
||||
let mymsg = msg.text.toString().trim().toLowerCase();
|
||||
let invitante = '';
|
||||
let regexpire = '';
|
||||
if (mymsg.startsWith('/start')) {
|
||||
let myarrmsg = mymsg.split(' ');
|
||||
if (myarrmsg.length > 0) {
|
||||
mymsg = myarrmsg[1];
|
||||
if (mymsg.startsWith('inv_')) {
|
||||
invitante = mymsg.substring(4);
|
||||
return invitante;
|
||||
let arrparams = mymsg.split('_');
|
||||
if (arrparams.length > 2) {
|
||||
invitante = arrparams[1];
|
||||
regexpire = arrparams[3];
|
||||
}
|
||||
return {invitante, regexpire};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2981,15 +2995,16 @@ class Telegram {
|
||||
return '';
|
||||
}
|
||||
|
||||
async setInvitante(msg, invitante, crea) {
|
||||
async setInvitante(msg, ris, crea) {
|
||||
let rec = this.getRecInMem(msg);
|
||||
if (!rec && crea) {
|
||||
let status = await this.setInit(msg);
|
||||
rec = this.getRecInMem(msg);
|
||||
}
|
||||
if (rec) {
|
||||
if (!rec.aportador_solidario && invitante) {
|
||||
rec.aportador_solidario = invitante;
|
||||
if (!rec.aportador_solidario && ris && ris.invitante) {
|
||||
rec.aportador_solidario = ris.invitante;
|
||||
rec.regexpire = ris.regexpire;
|
||||
rec.status = Status.SET_USERNAME_INVITANTE;
|
||||
}
|
||||
}
|
||||
@@ -3018,17 +3033,9 @@ class Telegram {
|
||||
await this.askUsernameInvitante(msg, true);
|
||||
// await this.settotheDatabase(msg);
|
||||
} else if (status === Status.SET_USERNAME_INVITANTE) {
|
||||
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 this.setInvitante(msg, invitante);
|
||||
}
|
||||
}
|
||||
const ris = this.getInvitanteByMsg(msg);
|
||||
if (ris.invitante) {
|
||||
await this.setInvitante(msg, ris, true);
|
||||
}
|
||||
|
||||
await this.setUsernameInvitante(msg);
|
||||
@@ -3857,19 +3864,6 @@ if (true) {
|
||||
|
||||
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;
|
||||
myclTelegram.receiveMsg(msg);
|
||||
});
|
||||
|
||||
@@ -1364,11 +1364,17 @@ module.exports = {
|
||||
return '';
|
||||
},
|
||||
|
||||
getTimeExpReg: async function(idapp, username) {
|
||||
var {User} = require('../models/user');
|
||||
|
||||
return await User.createNewReqRegistrationGetLink(idapp, username);
|
||||
},
|
||||
|
||||
getLinkRegByIdAppAndMsgStrutt: function(idapp, msg, rec) {
|
||||
|
||||
let myapp = this.getHostByIdApp(idapp);
|
||||
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;
|
||||
@@ -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 {
|
||||
if (!msg)
|
||||
return msg;
|
||||
|
||||
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 = await this.checkStr(msg, '{time_exp_reg}', user, 1);
|
||||
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
||||
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
||||
msg = msg.replace('{aportador_solidario}', user.aportador_solidario ? user.aportador_solidario : '');
|
||||
|
||||
@@ -367,8 +367,8 @@ module.exports = {
|
||||
|
||||
for (const user of arrusers) {
|
||||
|
||||
const mytitle = tools.convertSpecialTags(user, params.title);
|
||||
const mycontent = tools.convertSpecialTags(user, params.content);
|
||||
const mytitle = await tools.convertSpecialTags(user, params.title);
|
||||
const mycontent = await tools.convertSpecialTags(user, params.content);
|
||||
|
||||
let risult = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user