- Iscrizione Conacreis
This commit is contained in:
@@ -40,7 +40,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
|
||||
// Modify:
|
||||
return Booking.findOne({ id_bookedevent: id })
|
||||
return Booking.findOne({ id_bookedevent: id, userId: req.user._id })
|
||||
.then(trovato => {
|
||||
// console.log('trovato', trovato);
|
||||
if (trovato) {
|
||||
|
||||
@@ -64,6 +64,9 @@ const Group = require('../models/group');
|
||||
const { Todo } = require('../models/todo');
|
||||
const Hours = require('../models/hours');
|
||||
const Order = require('../models/order');
|
||||
const Cash = require('../models/cash');
|
||||
const CashCategory = require('../models/cashCategory');
|
||||
const CashSubCategory = require('../models/cashSubCategory');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
@@ -224,6 +227,12 @@ function getTableByTableName(tablename) {
|
||||
mytable = Hours;
|
||||
else if (tablename === 'orders')
|
||||
mytable = Order;
|
||||
else if (tablename === 'cashs')
|
||||
mytable = Cash;
|
||||
else if (tablename === 'cashCategorys')
|
||||
mytable = CashCategory;
|
||||
else if (tablename === 'cashSubCategorys')
|
||||
mytable = CashSubCategory;
|
||||
else if (tablename === 'producers')
|
||||
mytable = Producer;
|
||||
else if (tablename === 'carts')
|
||||
@@ -1124,10 +1133,10 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) => {
|
||||
router.get('/loadsite/:userId/:idapp', authenticate_noerror, (req, res) => {
|
||||
const userId = req.params.userId;
|
||||
const idapp = req.params.idapp;
|
||||
const sall = req.params.sall;
|
||||
const sall = (User.isAdmin(req.user.perm) || User.isManager(req.user.perm) || User.isEditor(req.user.perm)) ? '1' : '0'
|
||||
|
||||
// var category = req.params.category;
|
||||
|
||||
@@ -1255,9 +1264,9 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
|
||||
|
||||
if (req.user) {
|
||||
// If User is Admin, then send user Lists
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) || User.isManager(req.user.perm)) {
|
||||
// Send UsersList
|
||||
// usersList = User.getUsersList(req.user.idapp)
|
||||
usersList = User.getUsersList(req.user.idapp);
|
||||
// usersList = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const mongoose = require('mongoose');
|
||||
// POST /iscritti_conacreis
|
||||
router.post('/', async (req, res) => {
|
||||
tools.mylog("POST /iscritti_conacreis");
|
||||
const body = _.pick(req.body, ['idapp', 'userId', 'name', 'surname', 'email', 'fiscalcode', 'residency_address', 'residency_city', 'residency_province', 'residency_country', 'residency_zipcode', 'dateofbirth', 'cell_phone', 'newsletter_on', 'iscrizione_compilata', 'annoTesseramento', 'note', 'accetta_carta_costituzionale_on', 'terms']);
|
||||
const body = req.body;
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const iscritti = new IscrittiConacreis(body);
|
||||
@@ -67,7 +67,7 @@ router.post('/', async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
return await iscritti.save()
|
||||
return iscritti.save()
|
||||
.then(async () => {
|
||||
await sendemail.sendEmail_IscrizioneConacreis(iscritti.lang, iscritti.email, iscritti, iscritti.idapp);
|
||||
// }
|
||||
|
||||
@@ -46,9 +46,8 @@ router.post('/', authenticate, (req, res) => {
|
||||
let idobj = writeresult._id;
|
||||
Project.findById(idobj)
|
||||
.then(record => {
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
|
||||
tools.sendNotificationToUser(record.userId, titolo + ' ' + record.descr, record.descr, '/todo/' + record._id, '', 'todo', [])
|
||||
tools.sendNotificationToUser(record.userId, '[Progetto]: ' + record.descr, record.descr, '/todo/' + record._id, '', 'todo', [])
|
||||
|
||||
res.send({ record: record._doc });
|
||||
|
||||
|
||||
@@ -293,94 +293,6 @@ router.post('/', async (req, res) => {
|
||||
})
|
||||
});
|
||||
|
||||
// POST /users/iscriviti_conacreis
|
||||
router.post('/iscriviti_conacreis', async (req, res) => {
|
||||
tools.mylog("POST /users");
|
||||
const body = _.pick(req.body, ['name', 'surname', 'email', 'fiscalcode', 'residency_address', 'residency_city', 'residency_province', 'residency_country', 'residency_zipcode', 'dateofbirth', 'cell_phone', 'newsletter_on']);
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const user = new User(body);
|
||||
user.ipaddr = tools.getiPAddressUser(req);
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
|
||||
if (!tools.isAlphaNumeric(body.name)) {
|
||||
await tools.snooze(5000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tools.blockwords(body.email) || tools.blockwords(body.name) || tools.blockwords(body.surname)) {
|
||||
// tools.writeIPToBan(user.ipaddr + ': [' + user.username + '] ' + user.name + ' ' + user.surname);
|
||||
await tools.snooze(5000);
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
|
||||
user.date_reg = new Date();
|
||||
|
||||
// Controlla se anche l'ultimo record era dallo stesso IP:
|
||||
const lastrec = await User.getLastRec(body.idapp);
|
||||
if (!!lastrec) {
|
||||
if (process.env.LOCALE !== "1") {
|
||||
if (lastrec.ipaddr === user.ipaddr) {
|
||||
// Se l'ha fatto troppo ravvicinato
|
||||
if (lastrec.date_reg) {
|
||||
let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120);
|
||||
if (ris) {
|
||||
tools.writeIPToBan(user.ipaddr + ': ' + user.name + ' ' + user.surname);
|
||||
await tools.snooze(10000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await user.save()
|
||||
.then(async () => {
|
||||
return await User.findByUsername(user.idapp, user.username, false)
|
||||
.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) => {
|
||||
console.error(e.message);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
});
|
||||
|
||||
router.get('/:idapp/:username', async (req, res) => {
|
||||
var username = req.params.username;
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
Reference in New Issue
Block a user