2019-02-05 03:40:22 +01:00
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const { User } = require('../models/user');
|
2020-03-10 21:44:14 +01:00
|
|
|
const { Nave } = require('../models/nave');
|
|
|
|
|
const { ListaIngresso } = require('../models/listaingresso');
|
2020-01-13 23:52:51 +01:00
|
|
|
const { ExtraList } = require('../models/extralist');
|
2020-03-10 21:44:14 +01:00
|
|
|
const { ObjectID } = require('mongodb');
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const sendemail = require('../sendemail');
|
2019-02-06 18:48:32 +01:00
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
const { Settings } = require('../models/settings');
|
|
|
|
|
|
2019-02-07 00:52:48 +01:00
|
|
|
const tools = require('../tools/general');
|
2019-10-13 20:44:05 +02:00
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
2019-02-07 00:52:48 +01:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const server_constants = require('../tools/server_constants');
|
2019-02-06 18:48:32 +01:00
|
|
|
|
2020-01-20 01:48:25 +01:00
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
2019-02-05 03:40:22 +01:00
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const reg = require('../reg/registration');
|
2019-02-06 18:48:32 +01:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const { authenticate } = require('../middleware/authenticate');
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const mongoose = require('mongoose');
|
2019-02-12 12:06:25 +01:00
|
|
|
const Subscription = mongoose.model('subscribers');
|
|
|
|
|
|
2019-02-14 19:01:41 +01:00
|
|
|
function existSubScribe(userId, access, browser) {
|
|
|
|
|
return Subscription.findOne({ userId, access, browser })
|
2019-02-12 12:06:25 +01:00
|
|
|
.then(itemsub => {
|
|
|
|
|
return itemsub
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
function getMobileComplete(user) {
|
|
|
|
|
let str = user.profile.intcode_cell + user.profile.cell;
|
|
|
|
|
str = str.replace(/\s+/g, '');
|
|
|
|
|
// str = str.replace(/.+/g, '');
|
|
|
|
|
// str = str.replace(/-+/g, '');
|
|
|
|
|
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-05 03:40:22 +01:00
|
|
|
// POST /users
|
2019-12-29 23:30:49 +01:00
|
|
|
router.post('/', async (req, res) => {
|
2019-02-07 00:52:48 +01:00
|
|
|
tools.mylog("POST /users");
|
2020-01-20 01:48:25 +01:00
|
|
|
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile', 'aportador_solidario']);
|
2020-02-19 16:09:16 +01:00
|
|
|
body.email = body.email.toLowerCase();
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
const user = new User(body);
|
|
|
|
|
|
2019-02-07 00:52:48 +01:00
|
|
|
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2019-10-13 20:44:05 +02:00
|
|
|
user.linkreg = reg.getlinkregByEmail(body.idapp, body.email, body.username);
|
2019-02-05 03:40:22 +01:00
|
|
|
user.verified_email = false;
|
2020-01-27 15:07:53 +01:00
|
|
|
user.ipaddr = tools.getiPAddressUser(req);
|
2019-10-27 00:37:10 +02:00
|
|
|
user.lasttimeonline = new Date();
|
2020-01-20 01:48:25 +01:00
|
|
|
user.date_reg = new Date();
|
|
|
|
|
user.date_temp_reg = new Date();
|
2020-03-10 21:44:14 +01:00
|
|
|
user.aportador_iniziale = user.aportador_solidario;
|
|
|
|
|
if (user.idapp === tools.AYNI) {
|
|
|
|
|
user.profile.paymenttypes = ['paypal'];
|
|
|
|
|
}
|
2019-12-27 12:41:39 +01:00
|
|
|
// user.perm = 3;
|
2019-02-07 00:52:48 +01:00
|
|
|
if (tools.testing()) {
|
2019-02-06 18:48:32 +01:00
|
|
|
user.verified_email = true;
|
|
|
|
|
}
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2020-01-30 01:19:25 +01:00
|
|
|
// if (user.profile.intcode_cell) {
|
|
|
|
|
// if (user.profile.cell.substring(0, user.profile.intcode_cell.length) === user.profile.intcode_cell) {
|
|
|
|
|
// user.profile.cell = user.profile.cell.substring(user.profile.intcode_cell.length)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2019-12-29 23:30:49 +01:00
|
|
|
let exit;
|
|
|
|
|
|
|
|
|
|
// 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 (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;
|
|
|
|
|
|
2020-01-30 01:19:25 +01:00
|
|
|
let recuser = null;
|
|
|
|
|
|
|
|
|
|
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname);
|
|
|
|
|
if (recuser) {
|
|
|
|
|
// User already registered!
|
|
|
|
|
res.status(400).send({ code: server_constants.RIS_CODE_USER_ALREADY_EXIST, msg: '' });
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
let recextra = null;
|
2019-02-06 18:48:32 +01:00
|
|
|
|
2020-02-19 16:09:16 +01:00
|
|
|
// 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;
|
|
|
|
|
// }
|
2020-01-30 01:19:25 +01:00
|
|
|
|
2020-01-27 15:07:53 +01:00
|
|
|
const lastuser = await User.getLastUser(user.idapp);
|
|
|
|
|
const lastextra = await ExtraList.getLastUser(user.idapp);
|
|
|
|
|
let lastindorder = 0;
|
|
|
|
|
|
|
|
|
|
if (lastuser) {
|
|
|
|
|
lastindorder = lastuser.ind_order;
|
|
|
|
|
}
|
|
|
|
|
if (lastextra) {
|
|
|
|
|
if (lastextra.ind_order > lastindorder)
|
|
|
|
|
lastindorder = lastextra.ind_order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lastindorder > 0)
|
|
|
|
|
user.ind_order = lastindorder + 1;
|
|
|
|
|
|
2020-02-19 16:09:16 +01:00
|
|
|
const numero = user.name.slice(-1);
|
|
|
|
|
if ((numero === '2') || (numero === '3') || (numero === '4')) {
|
|
|
|
|
recorig = await User.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name.slice(0, -1), user.surname);
|
|
|
|
|
if (!!recorig) {
|
|
|
|
|
user.profile.teleg_id = recorig.profile.teleg_id;
|
|
|
|
|
user.profile.saw_zoom_presentation = recorig.profile.saw_zoom_presentation;
|
|
|
|
|
user.profile.saw_and_accepted = recorig.profile.saw_and_accepted;
|
|
|
|
|
user.profile.email_paypal = recorig.profile.email_paypal;
|
|
|
|
|
user.profile.paymenttypes = recorig.profile.paymenttypes;
|
|
|
|
|
let msgseconda = '!!! REGISTRATA ';
|
|
|
|
|
if (numero === '2')
|
|
|
|
|
msgseconda += 'SECONDA';
|
|
|
|
|
else if (numero === '3')
|
|
|
|
|
msgseconda += 'TERZA';
|
|
|
|
|
else if (numero === '4')
|
|
|
|
|
msgseconda += 'QUARTA';
|
|
|
|
|
|
|
|
|
|
msgseconda += ' UTENZA di ' + recorig.name + ' ' + recorig.surname + ' (' + recorig.username + ') : ' + user.name + ' ' + user.surname + ' (' + user.username + ') ';
|
2020-03-10 21:44:14 +01:00
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msgseconda);
|
2020-02-19 16:09:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-20 01:48:25 +01:00
|
|
|
|
|
|
|
|
namesurname_aportador_reg = await User.getNameSurnameByUsername(user.idapp, user.aportador_solidario);
|
|
|
|
|
|
2020-01-20 02:18:11 +01:00
|
|
|
if (recextra && namesurname_aportador_reg !== '' && namesurname_aportador_reg !== nomeaportador_corretto) {
|
2020-01-20 01:48:25 +01:00
|
|
|
// Si sta tentando di registrare una persona sotto che non corrisponde!
|
|
|
|
|
let msg = 'L\'utente ' + user.name + ' ' + user.surname + ' si sta registrando con il link di ' + user.aportador_solidario + ' (' + namesurname_aportador_reg + ') ' +
|
|
|
|
|
'invece è assegnato a ' + nomeaportador_corretto;
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
2020-01-20 01:48:25 +01:00
|
|
|
res.status(400).send({ code: server_constants.RIS_CODE_USER_NOT_THIS_APORTADOR, msg: '' });
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 10:28:26 +01:00
|
|
|
let already_registered = recextra || user.aportador_solidario === tools.APORTADOR_NONE;
|
2020-01-20 01:48:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if is an other people aportador_solidario
|
|
|
|
|
|
|
|
|
|
if (already_registered) {
|
2020-01-13 23:52:51 +01:00
|
|
|
// Check in the extraList if is present!
|
|
|
|
|
if (!recextra) {
|
2020-01-30 01:19:25 +01:00
|
|
|
const msg = 'Utente non trovato: ' + user.name + ' ' + user.surname + ' ' + user.profile.nationality + ' ' + user.profile.cell + ' email: ' + user.email + ' username: ' + user.username;
|
|
|
|
|
console.log('Utente non trovato; ', msg);
|
2020-03-10 21:44:14 +01:00
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
|
|
|
|
res.status(400).send({
|
|
|
|
|
code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND,
|
|
|
|
|
msg: 'Controlla se il numero ' + user.profile.cell + ' è corretto.'
|
|
|
|
|
});
|
2020-01-13 23:52:51 +01:00
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
user.ind_order = recextra.ind_order;
|
|
|
|
|
user.date_reg = recextra.date_reg;
|
|
|
|
|
if (recextra.aportador_solidario_name_surname)
|
|
|
|
|
user.aportador_solidario_nome_completo = recextra.aportador_solidario_name_surname;
|
|
|
|
|
else
|
|
|
|
|
user.aportador_solidario_nome_completo = recextra.aportador_solidario_originale_name_surname;
|
|
|
|
|
|
|
|
|
|
user.aportador_solidario_ind_order = recextra.aportador_solidario_ind_order;
|
|
|
|
|
|
2020-01-20 01:48:25 +01:00
|
|
|
user.note = recextra.note;
|
|
|
|
|
|
|
|
|
|
if (recextra.is_staff) {
|
|
|
|
|
user.perm = shared_consts.Permissions.Manager;
|
|
|
|
|
}
|
|
|
|
|
if (recextra.username === 'paoloar77') {
|
|
|
|
|
user.perm = shared_consts.Permissions.Manager + shared_consts.Permissions.Admin;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const useraportador = await ExtraList.findByIndOrder(user.idapp, user.aportador_solidario_ind_order);
|
|
|
|
|
if (useraportador)
|
|
|
|
|
user.aportador_solidario = useraportador.username;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await user.save()
|
|
|
|
|
.then(async () => {
|
2020-02-19 16:09:16 +01:00
|
|
|
return await User.findByUsername(user.idapp, user.username, false)
|
2020-01-13 23:52:51 +01:00
|
|
|
.then((usertrovato) => {
|
|
|
|
|
|
|
|
|
|
// tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
|
|
|
|
|
if (usertrovato !== null) {
|
|
|
|
|
return user.generateAuthToken(req);
|
|
|
|
|
} else {
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(async (token) => {
|
|
|
|
|
// tools.mylog("passo il TOKEN: ", token);
|
|
|
|
|
|
|
|
|
|
if (recextra) {
|
|
|
|
|
recextra.registered = true;
|
|
|
|
|
recextra.username = user.username;
|
|
|
|
|
await recextra.save();
|
|
|
|
|
|
|
|
|
|
await User.fixUsername(user.idapp, user.ind_order, user.username);
|
|
|
|
|
}
|
|
|
|
|
return token;
|
|
|
|
|
})
|
|
|
|
|
.then(async (token) => {
|
|
|
|
|
|
|
|
|
|
// tools.mylog("LINKREG = " + user.linkreg);
|
|
|
|
|
// Invia un'email all'utente
|
|
|
|
|
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
|
|
|
|
console.log('res.locale', res.locale);
|
|
|
|
|
if (!tools.testing()) {
|
|
|
|
|
await sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
|
|
|
|
|
}
|
|
|
|
|
res.header('x-auth', token).send(user);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
})
|
2019-02-05 03:40:22 +01:00
|
|
|
});
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
router.get('/:idapp/:username', async (req, res) => {
|
2019-02-05 03:40:22 +01:00
|
|
|
var username = req.params.username;
|
2019-10-13 20:44:05 +02:00
|
|
|
const idapp = req.params.idapp;
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
await User.findByUsername(idapp, username, false).then((user) => {
|
2019-02-05 03:40:22 +01:00
|
|
|
if (!user) {
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
}
|
|
|
|
|
res.status(200).send();
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-13 20:44:05 +02:00
|
|
|
router.patch('/:id', authenticate, (req, res) => {
|
|
|
|
|
const id = req.params.id;
|
|
|
|
|
const body = _.pick(req.body.user, shared_consts.fieldsUserToChange());
|
|
|
|
|
|
|
|
|
|
tools.mylogshow('PATCH USER: ', id);
|
|
|
|
|
|
2020-01-03 22:02:18 +01:00
|
|
|
if (!User.isAdmin(req.user.perm)) {
|
2019-10-13 20:44:05 +02:00
|
|
|
// If without permissions, exit
|
2019-10-14 20:31:57 +02:00
|
|
|
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
2019-10-13 20:44:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.findByIdAndUpdate(id, { $set: body }).then((user) => {
|
|
|
|
|
tools.mylogshow(' USER TO MODIFY: ', user);
|
|
|
|
|
if (!user) {
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
} else {
|
|
|
|
|
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
tools.mylogserr('Error patch USER: ', e);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
|
|
|
router.post('/login', (req, res) => {
|
|
|
|
|
var body = _.pick(req.body, ['username', 'password', 'idapp', 'keyappid', 'lang']);
|
|
|
|
|
var user = new User(body);
|
2019-02-13 18:47:58 +01:00
|
|
|
// const subs = _.pick(req.body, ['subs']);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2020-01-03 01:52:49 +01:00
|
|
|
// tools.mylog("LOGIN: username: " + user.username + " pwd = " + user.password);
|
2019-02-06 18:48:32 +01:00
|
|
|
|
2020-01-03 01:52:49 +01:00
|
|
|
// tools.mylog("user REC:", user);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
|
|
|
if (body.keyappid !== process.env.KEY_APP_ID)
|
|
|
|
|
return res.status(400).send();
|
|
|
|
|
|
2019-02-13 18:47:58 +01:00
|
|
|
let resalreadysent = false;
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2019-10-13 20:44:05 +02:00
|
|
|
User.findByCredentials(user.idapp, user.username, user.password)
|
2020-01-30 01:19:25 +01:00
|
|
|
.then(async (user) => {
|
2020-01-13 23:52:51 +01:00
|
|
|
// tools.mylog("CREDENZIALI ! ");
|
2019-02-05 03:40:22 +01:00
|
|
|
if (!user) {
|
2020-01-30 01:19:25 +01:00
|
|
|
await tools.snooze(3000);
|
2020-01-27 15:07:53 +01:00
|
|
|
const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
|
2020-01-30 01:19:25 +01:00
|
|
|
tools.mylogshow(msg);
|
2020-02-02 04:06:32 +01:00
|
|
|
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
|
2019-02-05 03:40:22 +01:00
|
|
|
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
|
2019-02-12 12:06:25 +01:00
|
|
|
}
|
2019-02-12 19:10:58 +01:00
|
|
|
return user
|
2019-02-12 12:06:25 +01:00
|
|
|
})
|
|
|
|
|
.then(user => {
|
2019-02-13 18:47:58 +01:00
|
|
|
if (user) {
|
|
|
|
|
return user.generateAuthToken(req).then((token) => {
|
|
|
|
|
var usertosend = User();
|
2019-10-27 00:37:10 +02:00
|
|
|
|
|
|
|
|
shared_consts.fieldsUserToChange().forEach((field) => {
|
|
|
|
|
usertosend[field] = user[field]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// usertosend._id = user._id.toHexString();
|
|
|
|
|
// if (!User.isAdmin(req.user)) {
|
|
|
|
|
// usertosend.ipaddr = user.ipaddr;
|
|
|
|
|
// }
|
2019-02-13 18:47:58 +01:00
|
|
|
|
|
|
|
|
// tools.mylog("user.verified_email:" + user.verified_email);
|
2020-01-03 01:52:49 +01:00
|
|
|
// tools.mylog("usertosend.userId", usertosend.userId);
|
2019-02-13 18:47:58 +01:00
|
|
|
|
|
|
|
|
return { usertosend, token }
|
|
|
|
|
|
2019-10-14 20:31:57 +02:00
|
|
|
})
|
|
|
|
|
.then((myris) => {
|
|
|
|
|
const access = 'auth';
|
|
|
|
|
const browser = req.get('User-Agent');
|
|
|
|
|
|
|
|
|
|
// Check if already exist Subscribe
|
2019-10-25 19:08:38 +02:00
|
|
|
return existSubScribe(myris.usertosend._id, access, browser).then(subscribe => {
|
2019-10-14 20:31:57 +02:00
|
|
|
return (subscribe !== null)
|
|
|
|
|
}).then(subsExistonDb => {
|
|
|
|
|
return { usertosend: myris.usertosend, token: myris.token, subsExistonDb }
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
return { usertosend: myris.usertosend, token: myris.token, subsExistonDb: false }
|
|
|
|
|
})
|
|
|
|
|
}).then(myris => {
|
2020-01-03 01:52:49 +01:00
|
|
|
// console.log('res', myris.token, myris.usertosend);
|
2019-10-14 20:31:57 +02:00
|
|
|
|
|
|
|
|
// SEND TOKEN AND CODE RESULT
|
|
|
|
|
res.header('x-auth', myris.token).send({
|
|
|
|
|
usertosend: myris.usertosend,
|
|
|
|
|
code: server_constants.RIS_CODE_OK,
|
|
|
|
|
subsExistonDb: myris.subsExistonDb
|
|
|
|
|
});
|
2020-02-19 16:09:16 +01:00
|
|
|
|
2019-10-14 20:31:57 +02:00
|
|
|
// tools.mylog("TROVATOOO!");
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
// tools.mylog('FINE LOGIN')
|
2019-02-13 18:47:58 +01:00
|
|
|
});
|
|
|
|
|
}
|
2019-02-12 12:06:25 +01:00
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
tools.mylog("ERRORE IN LOGIN: " + e);
|
2019-02-13 18:47:58 +01:00
|
|
|
if (!resalreadysent)
|
|
|
|
|
res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
|
2019-02-12 12:06:25 +01:00
|
|
|
});
|
2019-02-05 03:40:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.delete('/me/token', authenticate, (req, res) => {
|
2020-01-13 23:52:51 +01:00
|
|
|
// tools.mylog("TOKENREM = " + req.token);
|
2019-02-05 03:40:22 +01:00
|
|
|
req.user.removeToken(req.token).then(() => {
|
|
|
|
|
res.status(200).send();
|
|
|
|
|
}, () => {
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-13 20:44:05 +02:00
|
|
|
router.post('/setperm', authenticate, (req, res) => {
|
|
|
|
|
const body = _.pick(req.body, ['idapp', 'username', 'perm']);
|
|
|
|
|
tools.mylog("SETPERM = " + req.token);
|
|
|
|
|
|
|
|
|
|
User.setPermissionsById(res.user._id, body).then(() => {
|
|
|
|
|
res.status(200).send();
|
|
|
|
|
}, () => {
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
router.post('/import_extralist', async (req, res) => {
|
|
|
|
|
|
|
|
|
|
const strdata = req.body.strdata;
|
|
|
|
|
idapp = req.body.idapp;
|
|
|
|
|
locale = req.body.locale;
|
|
|
|
|
|
|
|
|
|
const ris = await ExtraList.ImportData(locale, idapp, strdata);
|
|
|
|
|
console.log('ris', ris);
|
|
|
|
|
|
|
|
|
|
res.send(ris);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
router.post('/dbop', authenticate, async (req, res) => {
|
|
|
|
|
|
|
|
|
|
const mydata = req.body.mydata;
|
|
|
|
|
idapp = req.body.idapp;
|
|
|
|
|
locale = req.body.locale;
|
|
|
|
|
|
|
|
|
|
let ris = await User.DbOp(idapp, mydata);
|
|
|
|
|
|
2020-03-21 10:28:26 +01:00
|
|
|
if (mydata.dbop === 'creaNaviProvvisorie') {
|
|
|
|
|
mydata.provvisoria = true;
|
|
|
|
|
const num = await Nave.generaNave(idapp, mydata);
|
|
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'creaNaviDefinitive') {
|
|
|
|
|
mydata.provvisoria = false;
|
2020-03-10 21:44:14 +01:00
|
|
|
const num = await Nave.generaNave(idapp, mydata);
|
|
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'delNavi') {
|
|
|
|
|
await Nave.setRiga(idapp, 1);
|
|
|
|
|
await Nave.setCol(idapp, 1);
|
|
|
|
|
const num = await Nave.remove({ idapp });
|
|
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'delNaviNoStarted') {
|
|
|
|
|
await Nave.setRiga(idapp, 1);
|
|
|
|
|
await Nave.setCol(idapp, 1);
|
|
|
|
|
const num = await Nave.remove({ idapp, date_start : { $gte: tools.IncDateNow(-1000 * 60 * 60 * 24 * 3) } });
|
2020-03-21 10:28:26 +01:00
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'delNaviProvvisorie') {
|
|
|
|
|
const num = await Nave.remove({ idapp, provvisoria: true });
|
|
|
|
|
|
|
|
|
|
const data = await Nave.getLastRigaCol(idapp);
|
|
|
|
|
await Nave.setRiga(idapp, data.riga);
|
|
|
|
|
await Nave.setCol(idapp, data.col + 1);
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'visuListaNave') {
|
|
|
|
|
const mystr = await Nave.showListaOrd(idapp);
|
|
|
|
|
ris = { mystr };
|
2020-03-21 10:28:26 +01:00
|
|
|
} else if (mydata.dbop === 'pulisciNonPresenzeInNave') {
|
|
|
|
|
const mystr = await Nave.pulisciNonPresenzeInNave(idapp);
|
|
|
|
|
ris = { mystr };
|
2020-03-10 21:44:14 +01:00
|
|
|
} else if (mydata.dbop === 'checkInserimentiUtentiInNave') {
|
|
|
|
|
const mystr = await Nave.checkIfDevoAggiungereInNave(idapp);
|
|
|
|
|
ris = { mystr };
|
|
|
|
|
} else if (mydata.dbop === 'visuListaIngresso') {
|
|
|
|
|
const mystr = await ListaIngresso.showListaOrd(idapp);
|
|
|
|
|
ris = { mystr };
|
|
|
|
|
} else if (mydata.dbop === 'initListaIngresso') {
|
2020-03-21 10:28:26 +01:00
|
|
|
// const aaa = await User.updateMany({ idapp }, { $set: { 'profile.nationality': 'IT' } });
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
const num = await ListaIngresso.updateMany({ idapp }, { $set: { added: false } });
|
|
|
|
|
|
|
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'ImpostaATuttiPaypal') {
|
|
|
|
|
const listautenti = await User.find({ idapp });
|
|
|
|
|
let num = 0;
|
|
|
|
|
for (let rec of listautenti) {
|
|
|
|
|
if (!rec._doc.profile.paymenttypes.includes('paypal')) {
|
|
|
|
|
rec._doc.profile.paymenttypes = [...rec._doc.profile.paymenttypes, 'paypal'];
|
|
|
|
|
const user = await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.paymenttypes': rec._doc.profile.paymenttypes } });
|
|
|
|
|
// await rec.save();
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
// const num = await User.f({ idapp }, { $set: { 'profile: false } });
|
|
|
|
|
}
|
2020-01-30 01:19:25 +01:00
|
|
|
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'numtessUno') {
|
|
|
|
|
const listanavi = await ListaIngresso.find({ idapp });
|
|
|
|
|
let num = 0;
|
|
|
|
|
for (let rec of listanavi) {
|
|
|
|
|
if (!rec._doc.num_tess) {
|
|
|
|
|
rec._doc.num_tess = 1;
|
|
|
|
|
const risu = await ListaIngresso.findOneAndUpdate({ _id: rec._id }, { $set: { num_tess: rec._doc.num_tess } }, { new: false });
|
|
|
|
|
// await rec.save();
|
|
|
|
|
if (!!risu)
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
// const num = await User.f({ idapp }, { $set: { 'profile: false } });
|
|
|
|
|
}
|
2020-01-30 01:19:25 +01:00
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'creaUtentiTest') {
|
|
|
|
|
|
|
|
|
|
let num = 0;
|
|
|
|
|
lastrec = await User.find({ idapp }).sort({ _id: -1 }).limit(1);
|
2020-03-21 10:28:26 +01:00
|
|
|
for (let ind = 0; ind < 100; ind++) {
|
2020-03-10 21:44:14 +01:00
|
|
|
let myuser = new User();
|
|
|
|
|
myuser._id = new ObjectID();
|
|
|
|
|
myuser.ind_order = lastrec[0].ind_order + ind + 1;
|
|
|
|
|
myuser.idapp = idapp;
|
|
|
|
|
myuser.password = "$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG";
|
|
|
|
|
myuser.lang = 'it';
|
|
|
|
|
myuser.email = "miaemail@email.it";
|
|
|
|
|
myuser.name = 'U' + myuser.ind_order;
|
2020-03-21 10:28:26 +01:00
|
|
|
myuser.surname = 'Ar' + myuser.ind_order;
|
2020-03-10 21:44:14 +01:00
|
|
|
myuser.verified_email = true;
|
|
|
|
|
if (myuser.ind_order < 2)
|
|
|
|
|
myuser.perm = "3";
|
|
|
|
|
myuser.username = "Userna_" + myuser.name;
|
|
|
|
|
myuser.profile.special_req = true;
|
2020-03-21 10:28:26 +01:00
|
|
|
myuser.profile.nationality = 'IT';
|
2020-03-10 21:44:14 +01:00
|
|
|
await myuser.save();
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ris = { num };
|
|
|
|
|
} else if (mydata.dbop === 'visuPlacca') {
|
2020-03-21 10:28:26 +01:00
|
|
|
const rec = {};
|
|
|
|
|
const placca = await Nave.getPlaccaPerDonatore(idapp, parseInt(mydata.riga), parseInt(mydata.col), false, rec);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
|
|
|
telegrambot.sendMsgTelegramToTheAdmin(idapp, placca);
|
|
|
|
|
|
|
|
|
|
ris = { placca };
|
|
|
|
|
} else if (mydata.dbop === 'visuNave') {
|
|
|
|
|
const mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
|
|
|
|
|
|
|
|
|
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
|
|
|
|
|
if (visu_nave_Bot)
|
2020-03-21 10:28:26 +01:00
|
|
|
telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
|
|
|
ris = { mystr };
|
|
|
|
|
} else if (mydata.dbop === 'getnavibyuser') {
|
|
|
|
|
|
|
|
|
|
let arrnavi = null;
|
|
|
|
|
|
|
|
|
|
const user = await User.getUserShortDataByUsername(idapp, mydata.username);
|
|
|
|
|
if (user) {
|
|
|
|
|
arrnavi = await Nave.getArrPosizioniByIndOrder(idapp, user.ind_order);
|
|
|
|
|
|
|
|
|
|
for (let mynave of arrnavi) {
|
|
|
|
|
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ris = { data: arrnavi };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log('ris', ris);
|
|
|
|
|
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-01-30 01:19:25 +01:00
|
|
|
|
2019-10-14 20:31:57 +02:00
|
|
|
|
2019-02-05 03:40:22 +01:00
|
|
|
module.exports = router;
|