"Riregistrarsi se l'invitante non ha ancora confermato l'invito.
Annullo la richiesta precedente. (inviando un msg di annullamento. (Si è già registrato con un alto invito.)"
This commit is contained in:
@@ -91,7 +91,8 @@ router.post('/', async (req, res) => {
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
|
||||
if (!tools.isAlphaNumericAndSpecialCharacter(body.username) || body.email.length < 6 ||
|
||||
if (!tools.isAlphaNumericAndSpecialCharacter(body.username) ||
|
||||
body.email.length < 6 ||
|
||||
body.username.length < 6 || body.password.length < 6) {
|
||||
await tools.snooze(5000);
|
||||
console.log('Username non valido in Registrazione: ' + body.username);
|
||||
@@ -156,65 +157,77 @@ router.post('/', async (req, res) => {
|
||||
// }
|
||||
let exit;
|
||||
|
||||
let utentenonancoraVerificato = false;
|
||||
|
||||
const trovarec = await User.findByCredentials(user.idapp, user.username, user.password, true);
|
||||
|
||||
// Check if already esist email or username
|
||||
exit = await User.findByUsername(user.idapp, user.username).
|
||||
then((useralreadyexist) => {
|
||||
if (useralreadyexist) {
|
||||
res.status(400).
|
||||
send({
|
||||
code: server_constants.RIS_CODE_USERNAME_ALREADY_EXIST,
|
||||
msg: '',
|
||||
});
|
||||
return 1;
|
||||
|
||||
if (tools.getAskToVerifyReg(useralreadyexist.idapp)) {
|
||||
if (!useralreadyexist.verified_by_aportador &&
|
||||
useralreadyexist.profile.teleg_id > 0) {
|
||||
if (trovarec) {
|
||||
utentenonancoraVerificato = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!utentenonancoraVerificato) {
|
||||
res.status(400).
|
||||
send({
|
||||
code: server_constants.RIS_CODE_USERNAME_ALREADY_EXIST,
|
||||
msg: '',
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (exit === 1)
|
||||
return;
|
||||
if (!utentenonancoraVerificato) {
|
||||
|
||||
exit = await User.findByEmail(user.idapp, user.email).
|
||||
then((useralreadyexist) => {
|
||||
if (useralreadyexist) {
|
||||
res.status(400).
|
||||
send({
|
||||
code: server_constants.RIS_CODE_EMAIL_ALREADY_EXIST,
|
||||
msg: '',
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
if (exit === 1)
|
||||
return;
|
||||
|
||||
});
|
||||
exit = await User.findByEmail(user.idapp, user.email).
|
||||
then((useralreadyexist) => {
|
||||
if (useralreadyexist) {
|
||||
res.status(400).
|
||||
send({
|
||||
code: server_constants.RIS_CODE_EMAIL_ALREADY_EXIST,
|
||||
msg: '',
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (exit === 1)
|
||||
return;
|
||||
});
|
||||
|
||||
let recuser = null;
|
||||
if (exit === 1)
|
||||
return;
|
||||
|
||||
let recuser = null;
|
||||
|
||||
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell,
|
||||
user.name, user.surname);
|
||||
if (recuser && user.name !== '' && user.surname !== '' &&
|
||||
user.profile.cell !== '') {
|
||||
console.log('UTENTE GIA ESISTENTE:\n');
|
||||
console.log(user);
|
||||
// User already registered!
|
||||
res.status(400).
|
||||
send({code: server_constants.RIS_CODE_USER_ALREADY_EXIST, msg: ''});
|
||||
return 1;
|
||||
}
|
||||
|
||||
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell,
|
||||
user.name, user.surname);
|
||||
if (recuser && user.name !== '' && user.surname !== '' &&
|
||||
user.profile.cell !== '') {
|
||||
console.log('UTENTE GIA ESISTENTE:\n');
|
||||
console.log(user);
|
||||
// User already registered!
|
||||
res.status(400).
|
||||
send({code: server_constants.RIS_CODE_USER_ALREADY_EXIST, msg: ''});
|
||||
return 1;
|
||||
}
|
||||
|
||||
let recextra = null;
|
||||
|
||||
// recextra = await ExtraList.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname);
|
||||
// let nomeaportador_corretto = "";
|
||||
// if (recextra) {
|
||||
// nomeaportador_corretto = recextra.aportador_solidario_name_surname;
|
||||
// if (nomeaportador_corretto === '')
|
||||
// nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname;
|
||||
// }
|
||||
|
||||
const id_aportador = await User.getIdByUsername(user.idapp,
|
||||
user.aportador_solidario);
|
||||
const id_aportador = await User.getIdByUsername(user.idapp, user.aportador_solidario);
|
||||
|
||||
if (!id_aportador && tools.getAskToVerifyReg(body.idapp)) {
|
||||
// Si sta tentando di registrare una persona sotto che non corrisponde!
|
||||
@@ -230,6 +243,28 @@ router.post('/', async (req, res) => {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (utentenonancoraVerificato) {
|
||||
if (id_aportador) {
|
||||
// Se mi sono registrato ma l'invitante non mi abilita, allora il posso registrarmi nuovamente, con lo stesso username e password,
|
||||
// con un'altro link di un'altro invitante !
|
||||
await User.setaportador_solidario(user.idapp, user.username,
|
||||
user.aportador_solidario);
|
||||
|
||||
const myuser = await User.findOne({_id: trovarec._id});
|
||||
if (myuser) {
|
||||
|
||||
await telegrambot.askConfirmationUserRegistration(myuser.idapp,
|
||||
shared_consts.CallFunz.REGISTRATION, myuser,
|
||||
myuser.profile.username_telegram, myuser.profile.firstname_telegram,
|
||||
myuser.profile.lastname_telegram);
|
||||
|
||||
const token = await myuser.generateAuthToken(req);
|
||||
res.header('x-auth', token).send(myuser);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// let already_registered = (recextra || user.aportador_solidario === tools.APORTADOR_NONE) && (user.idapp === tools.AYNI);
|
||||
|
||||
// Check if is an other people aportador_solidario
|
||||
@@ -297,7 +332,7 @@ router.get('/:idapp/:username', async (req, res) => {
|
||||
// return res.status(200).send();
|
||||
// }
|
||||
|
||||
await User.findByUsername(idapp, username, false).then((user) => {
|
||||
await User.findByUsername(idapp, username, false, true).then((user) => {
|
||||
if (!user) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
@@ -341,12 +376,14 @@ router.post('/profile', authenticate, (req, res) => {
|
||||
|
||||
//++Todo: controlla che tipo di dati ha il permesso di leggere
|
||||
|
||||
return User.getUserProfileByUsername(idapp, username, req.user.username, false, req.user.perm).
|
||||
return User.getUserProfileByUsername(idapp, username, req.user.username,
|
||||
false, req.user.perm).
|
||||
then((ris) => {
|
||||
|
||||
return User.getFriendsByUsername(idapp, req.user.username).then((friends) => {
|
||||
res.send({user: ris, friends });
|
||||
});
|
||||
return User.getFriendsByUsername(idapp, req.user.username).
|
||||
then((friends) => {
|
||||
res.send({user: ris, friends});
|
||||
});
|
||||
|
||||
}).catch((e) => {
|
||||
tools.mylog('ERRORE IN Profile: ' + e.message);
|
||||
@@ -892,7 +929,13 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
//++ Todo: TO FIXIT !
|
||||
const mytablesstr = ['settings', 'users', 'templemail', 'contribtypes', 'bots', 'cfgservers'];
|
||||
const mytablesstr = [
|
||||
'settings',
|
||||
'users',
|
||||
'templemail',
|
||||
'contribtypes',
|
||||
'bots',
|
||||
'cfgservers'];
|
||||
|
||||
try {
|
||||
let numrectot = 0;
|
||||
@@ -1031,7 +1074,7 @@ router.post('/dbop', authenticate, async (req, res) => {
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
|
||||
try{
|
||||
try {
|
||||
const ris = await eseguiDbOp(idapp, mydata, locale);
|
||||
|
||||
res.send(ris);
|
||||
|
||||
Reference in New Issue
Block a user