Registrazione: scegliere se Telegram o Email
This commit is contained in:
@@ -461,6 +461,18 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.setOnLine = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
return User.findOneAndUpdate({ idapp, username }, { $set: { lasttimeonline: new Date() } });
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.setPermissionsById = function (id, perm) {
|
||||
const user = this;
|
||||
|
||||
@@ -1273,31 +1285,33 @@ UserSchema.statics.createNewReqRegistrationGetLink = async function (idapp, user
|
||||
});
|
||||
|
||||
if (user) {
|
||||
if (!user.date_tokenreg || (!user.tokenreg) || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) {
|
||||
if (true) {
|
||||
// Se è scaduto, ne crea uno nuovo
|
||||
// Creo il tokenforgot
|
||||
let mycodestr = user._id.toHexString() + new Date().getTime().toString();
|
||||
user.tokenreg = jwt.sign(mycodestr, process.env.SIGNCODE).
|
||||
toString();
|
||||
|
||||
if (user.tokenreg) {
|
||||
try {
|
||||
user.tokenreg = user.tokenreg.replaceAll('.', '');
|
||||
user.tokenreg = user.tokenreg.replaceAll('/', '');
|
||||
user.tokenreg = user.tokenreg.slice(-8);
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
if (!user.date_tokenreg || (!user.tokenreg) || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) {
|
||||
|
||||
let mycodestr = user._id.toHexString() + new Date().getTime().toString();
|
||||
user.tokenreg = jwt.sign(mycodestr, process.env.SIGNCODE).
|
||||
toString();
|
||||
|
||||
if (user.tokenreg) {
|
||||
try {
|
||||
user.tokenreg = user.tokenreg.replaceAll('.', '');
|
||||
user.tokenreg = user.tokenreg.replaceAll('/', '');
|
||||
user.tokenreg = user.tokenreg.slice(-8);
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user.date_tokenreg = tools.AddDate(new Date(), 2);
|
||||
user.date_tokenreg = tools.AddDate(new Date(), 1);
|
||||
|
||||
return await user.save().then(() => {
|
||||
return user.tokenreg;
|
||||
});
|
||||
|
||||
} else {
|
||||
return user.tokenreg;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3535,6 +3549,31 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getLastSharedLink = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const lastn = 10;
|
||||
|
||||
return await User.find(
|
||||
{
|
||||
idapp,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
{
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
'profile.img': 1,
|
||||
index: 1,
|
||||
}).sort({ date_tokenreg: -1 }).limit(lastn).then((arr) => {
|
||||
return arr;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getDiffusoriUsers = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
@@ -4242,7 +4281,7 @@ UserSchema.statics.tooManyReqPassword = async function (idapp, email, set) {
|
||||
|
||||
await User.findOneAndUpdate({ _id: user._id }, { $set: { retry_pwd: user.retry_pwd } });
|
||||
}
|
||||
return user.retry_pwd > maxnum ;
|
||||
return user.retry_pwd > maxnum;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -278,6 +278,10 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
mydata.idapp = req.user.idapp;
|
||||
const idapp = mydata.idapp;
|
||||
|
||||
if (req.user && req.user.username) {
|
||||
User.setOnLine(req.user.idapp, req.user.username);
|
||||
}
|
||||
|
||||
let consentito = false;
|
||||
|
||||
try {
|
||||
@@ -564,6 +568,10 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
|
||||
try {
|
||||
|
||||
if (req.user && req.user.username) {
|
||||
User.setOnLine(req.user.idapp, req.user.username);
|
||||
}
|
||||
|
||||
return mytable.executeQueryTable(idapp, params, req.user).then(ris => {
|
||||
return res.send(ris);
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ router.post('/', authenticate, (req, res) => {
|
||||
tools.mylog('crea SendMsg');
|
||||
const myrecmsg = new SendMsg(body);
|
||||
|
||||
if (req.user && req.user.username) {
|
||||
User.setOnLine(req.user.idapp, req.user.username);
|
||||
}
|
||||
|
||||
const check = tools.checkUserOk(myrecmsg.origin.username, req.user.username, res);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
@@ -74,6 +78,10 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
const idapp = req.params.idapp;
|
||||
// var category = req.params.category;
|
||||
|
||||
if (req.user && req.user.username) {
|
||||
User.setOnLine(req.user.idapp, req.user.username);
|
||||
}
|
||||
|
||||
if (req.user.idapp !== idapp) {
|
||||
// I'm trying to get something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
||||
|
||||
@@ -48,6 +48,7 @@ router.post('/load', async (req, res) => {
|
||||
reg_weekly: await User.calcRegWeekly(idapp),
|
||||
lastsreg: await User.getLastUsers(idapp),
|
||||
lastsonline: await User.getLastOnlineUsers(idapp),
|
||||
lastssharedlink: await User.getLastSharedLink(idapp),
|
||||
diffusorilist: await User.getDiffusoriUsers(idapp),
|
||||
checkuser: await User.checkUser(idapp, username),
|
||||
// navi_partite: await Nave.getNaviPartite(idapp),
|
||||
|
||||
@@ -248,7 +248,7 @@ router.post('/', async (req, res) => {
|
||||
user.aportador_solidario = await User.getRealUsernameByUsername(user.idapp, user.aportador_solidario);
|
||||
}
|
||||
|
||||
/*if (!id_aportador && tools.getAskToVerifyReg(body.idapp)) {
|
||||
if (!id_aportador && tools.getAskToVerifyReg(body.idapp)) {
|
||||
// Si sta tentando di registrare una persona sotto che non corrisponde!
|
||||
let msg = 'Il link di registrazione non sembra risultare valido.<br>invitante: ' +
|
||||
user.aportador_solidario + '<br>username: ' + user.username;
|
||||
@@ -260,7 +260,7 @@ router.post('/', async (req, res) => {
|
||||
msg: '',
|
||||
});
|
||||
return 1;
|
||||
}*/
|
||||
}
|
||||
|
||||
if (utentenonancoraVerificato) {
|
||||
if (id_aportador) {
|
||||
|
||||
Reference in New Issue
Block a user