diff --git a/files/lista-1.pdf b/files/lista-1.pdf index d94c855..17fba84 100644 Binary files a/files/lista-1.pdf and b/files/lista-1.pdf differ diff --git a/package-lock.json b/package-lock.json index 225330e..e6b1034 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1107,6 +1107,15 @@ "ini": "^1.3.4" } }, + "gmail-send": { + "version": "1.8.10", + "resolved": "https://registry.npmjs.org/gmail-send/-/gmail-send-1.8.10.tgz", + "integrity": "sha512-QMpWwzeA64U69HzOEzI37UNc73xXkhTg8LuqsfKX9W7LjiQY3yRvViVn7ZhuJWLTV4136vsLJf2sXiZKmdykbw==", + "requires": { + "lodash": "^4.17.15", + "nodemailer": "^6.3.0" + } + }, "got": { "version": "6.7.1", "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", @@ -1447,6 +1456,11 @@ } } }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + }, "lowercase-keys": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", @@ -1669,6 +1683,11 @@ "tar": "^4.4.2" } }, + "nodemailer": { + "version": "6.4.6", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.6.tgz", + "integrity": "sha512-/kJ+FYVEm2HuUlw87hjSqTss+GU35D4giOpdSfGp7DO+5h6RlJj7R94YaYHOkoxu1CSaM0d3WRBtCzwXrY6MKA==" + }, "nodemailer-fetch": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/nodemailer-fetch/-/nodemailer-fetch-1.6.0.tgz", diff --git a/package.json b/package.json index 9a0b990..1a621cd 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "express": "^4.17.1", "express-fileupload": "^1.1.6", "fs": "0.0.1-security", + "gmail-send": "^1.8.10", "mysql": "^2.18.1", + "nodemailer": "^6.4.6", "nodemon": "^2.0.2", "pdfkit": "^0.11.0", "qr-image": "^3.2.0", diff --git a/routes/descargar_pdf.js b/routes/descargar_pdf.js index c7948b6..dc9f066 100644 --- a/routes/descargar_pdf.js +++ b/routes/descargar_pdf.js @@ -1,7 +1,6 @@ const connection = require('../conf/connection.js'); const express = require('express') -const sendmail = require('sendmail')(); var app = express(); @@ -13,26 +12,49 @@ function query(consulta) { }); }) } + + + + + + + + + app.get('/descargar_pdf', async (req, res) => { let cad=`select * from persona where id_persona=${req.query.id_persona};`; let ans=await query(cad); let correo=ans[0].correo_electronico; - console.log(ans); - sendmail({ - from: 'ciie2020@acatlan.unam.mx', - to: `${correo}`, - subject: 'Inscipción coloquio de Educacion FES-Acatlan', - html: `Gracias por inscribirte al coloquio internacional de educacion`, - // attachments: [ - // { // use URL as an attachment - // filename: 'comprobante.txt', - // path: __dirname + `/../files/lista-${req.query.id_persona}.pdf` - // } - // ] - }); - //res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`); - return res.status(200).json({msj: "exito"}); + + const send = require('gmail-send')({ + user: 'daniel.adrian.ramirez.george@gmail.com', + pass: '753951852_dan', + to: `${correo}`, + subject: 'Comprobante de inscripción CIIE FES Acatlan', + text: 'Se adjunta el comprobante de inscripcion al Coloquio Internacional de Educacion.', // Plain text + + }); + + + const filepath = __dirname + `/../files/lista-${req.query.id_persona}.pdf`; // File to attach + + + await send({ // Overriding default parameters + //subject: 'attached '+filepath, // Override value set as default + files: [ filepath ], + }, function (err, res, full) { + if (err) + console.log('* [example 1.1] send() callback returned: res:', res); + // uncomment to see full response from Nodemailer: + // console.log('* [example 1.2] send() callback returned: full:', full); + }); + + + console.log(correo); + + return res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`); + //return res.status(200).json({msj: "exito"}); }) module.exports = app; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 2915da6..3fe24bc 100644 --- a/routes/index.js +++ b/routes/index.js @@ -16,4 +16,6 @@ app.use(require('./traer_eventos')); app.use(require('./registro_evento')); app.use(require('./crear_pdf')); app.use(require('./descargar_pdf')); +app.use(require('./traer_asistente')); + module.exports = app; \ No newline at end of file diff --git a/routes/loggin_persona.js b/routes/loggin_persona.js index c497bd8..7f6e022 100644 --- a/routes/loggin_persona.js +++ b/routes/loggin_persona.js @@ -36,6 +36,7 @@ app.post('/loggin_persona', async(req, res) => { let respuesta = query(cad); // console.log(respuesta); respuesta.then(async r => { + // console.log(r, r.length); if (r.length == 0) { res.status(400).json({ error: false, msj: "Usuario o contraseña invalidos" }); @@ -45,17 +46,18 @@ app.post('/loggin_persona', async(req, res) => { //console.log(pass); let n_pasword = await bcrypt.hash(pass, 10); //console.log(data); - // console.log(n_pasword); + //console.log(n_pasword); let ban = bcrypt.compareSync(data.password, r[0].password); if (ban == true) { + delete r[0].password if (r[0].ponente == 1) { try { let c = `select * from trabajo where id_persona=${r[0].id_persona};`; let q = await query(c); if (q.length > 0) { - return res.status(200).json({ error: false, msj: "Bienvenido", paricipacion: 'Ponente', id_persona: r, trabajo: q }); + return res.status(200).json({ error: false, msj: "Bienvenido", participacion: 'Ponente', id_persona: r, trabajo: q }); } else { - return res.status(200).json({ error: false, msj: "Bienvenido", paricipacion: 'Ponente', id_persona: r }); + return res.status(200).json({ error: false, msj: "Bienvenido", participacion: 'Ponente', id_persona: r }); } @@ -65,7 +67,7 @@ app.post('/loggin_persona', async(req, res) => { return; } } else - res.status(200).json({ error: false, msj: "Bienvenido", paricipacion: 'Asistente', id_persona: r[0] }); + res.status(200).json({ error: false, msj: "Bienvenido", participacion: 'Asistente',id_persona: r }); return; } else { diff --git a/routes/registro_evento.js b/routes/registro_evento.js index f0c10dc..1ea3bde 100644 --- a/routes/registro_evento.js +++ b/routes/registro_evento.js @@ -17,15 +17,17 @@ function query(consulta) { app.post('/registro_evento', async(req, res) => { try { + console.log(req.body); let datos=req.body.eventos; let id_persona= req.body.id_persona; let pag=true; - let con=req.body.constacia; + let con=req.body.constancia; let total= req.body.total_pago; let eliminar_eventos=`select distinct f.id_evento from fecha as f inner join asistencia as a where a.id_persona=${id_persona} and a.id_fecha=f.id_fecha `; let query_eliminar= await query(eliminar_eventos); //console.log(query_eliminar); + for(let i=0; i { + if (error) reject(error); + resolve(results); + }); + }) +} + + + +app.get('/traer_asistente', async(req, res) => { + let id_persona=req.query.id_persona; + try { + let cad = `select * from persona where id_persona=${id_persona}`; + let respuesta = await query(cad); + delete respuesta.password; + let select_const= `select a.constancia from asistencia as a inner join fecha as f inner join evento as e where a.id_persona=${id_persona} and a.id_fecha=f.id_fecha and f.id_evento=e.id_evento and e.tipo_evento="Mesa tematica" and a.constancia=true;`; + let traer_cons=await query(select_const); + let cons=false; + if(traer_cons.length>0) + cons=true; + + let eventos_persona=`select distinct f.id_evento from fecha as f inner join asistencia as a where a.id_persona=${id_persona} and a.id_fecha=f.id_fecha `; + let todos_los_id_eventos= await query(eventos_persona); + let mesa=[]; + let taller=[]; + let ponencias=[]; + for(let i=0; i { let cad = `select * from evento;`; let respuesta = query(cad); //console.log(respuesta); - respuesta.then(r => { + respuesta.then(async r => { let ans={}; ans.mesa=[]; ans.taller=[]; ans.ponencia=[]; for(let i=0; i { } - res.status(200).json({ error: false, msj: "exito", data: ans }); + res.status(200).json({ error: false, msj: "exito", eventos: ans }); return; }).catch(err => { - res.status(400).json({ error: false, msj: err }); + console.log(err); + res.status(400).json({ error: true, msj: err }); }); } catch (err) { diff --git a/sql/values.sql b/sql/values.sql index c81699f..3b31a0b 100644 --- a/sql/values.sql +++ b/sql/values.sql @@ -227,7 +227,7 @@ insert into admin values(null, 'Administrador', '$2b$10$YqVknXcVK3g4H.b4X7ecVO9i insert into evento values (null,"Mesa tematica", "Mesa 9: Educación ambiental y bioética.", 60, "Sala 1"); -insert into fecha values(null , 1, '2020-08-17 12:00:00', , '2020-08-17 15:00:00'); +insert into fecha values(null , 1, '2020-08-17 12:00:00' , '2020-08-17 15:00:00'); insert into evento values (null,"Mesa tematica", "Mesa 8: Políticas Públicas para la innovación y transoformación educativa.", 60, "Sala 2");