From efb3fe2a30e8d1cf81d2817e1953110ecbe16a76 Mon Sep 17 00:00:00 2001 From: DanielRamirezGe Date: Sat, 28 Sep 2019 18:43:26 -0500 Subject: [PATCH] ultima modificacion antes de seguridad --- routes/Imagenes/Fesa.jpg | Bin routes/Imagenes/logo.png | Bin routes/Imagenes/logo_unam.png | Bin routes/Imagenes/persona_1.png | Bin 0 -> 348 bytes routes/Imagenes/persona_12.png | Bin 0 -> 341 bytes routes/Imagenes/persona_2.png | Bin 0 -> 342 bytes routes/Imagenes/persona_3.png | Bin 0 -> 341 bytes routes/Imagenes/persona_4.png | Bin 0 -> 335 bytes routes/Imagenes/persona_6.png | Bin 0 -> 332 bytes routes/Imagenes/persona_8.png | Bin 0 -> 332 bytes routes/Imagenes/qr_ejemplo.png | Bin routes/comprobante.pdf | Bin 2141 -> 0 bytes routes/cupo.js | 26 +++ routes/descargar_pdf.js | 10 ++ routes/g_img.js | 10 ++ routes/getConferencias.js | 286 +++------------------------------ routes/get_pdf.js | 13 ++ routes/get_qr.js | 13 ++ routes/index.js | 4 + routes/loggin.js | 25 ++- routes/pdf.js | 230 +++++++++++--------------- routes/pdfkit-tables.js | 2 +- routes/registro.js | 24 ++- routes/registroPersona.js | 14 +- routes/verificarConferencia.js | 34 ++-- 25 files changed, 245 insertions(+), 446 deletions(-) mode change 100644 => 100755 routes/Imagenes/Fesa.jpg mode change 100644 => 100755 routes/Imagenes/logo.png mode change 100644 => 100755 routes/Imagenes/logo_unam.png create mode 100644 routes/Imagenes/persona_1.png create mode 100644 routes/Imagenes/persona_12.png create mode 100644 routes/Imagenes/persona_2.png create mode 100644 routes/Imagenes/persona_3.png create mode 100644 routes/Imagenes/persona_4.png create mode 100644 routes/Imagenes/persona_6.png create mode 100644 routes/Imagenes/persona_8.png mode change 100644 => 100755 routes/Imagenes/qr_ejemplo.png delete mode 100644 routes/comprobante.pdf create mode 100644 routes/cupo.js create mode 100644 routes/descargar_pdf.js create mode 100644 routes/g_img.js create mode 100644 routes/get_pdf.js create mode 100644 routes/get_qr.js diff --git a/routes/Imagenes/Fesa.jpg b/routes/Imagenes/Fesa.jpg old mode 100644 new mode 100755 diff --git a/routes/Imagenes/logo.png b/routes/Imagenes/logo.png old mode 100644 new mode 100755 diff --git a/routes/Imagenes/logo_unam.png b/routes/Imagenes/logo_unam.png old mode 100644 new mode 100755 diff --git a/routes/Imagenes/persona_1.png b/routes/Imagenes/persona_1.png new file mode 100644 index 0000000000000000000000000000000000000000..0d5f8999a3bf915ed859704961fea33ab1318e13 GIT binary patch literal 348 zcmeAS@N?(olHy`uVBq!ia0vp^6G4~*NH9Fx%=({!fl=Ah#WAGf*4tZ-ea!|utO4)p zUzS-0g)YA@z|<30rZMrWS(wc1x24;+3c|r(|BK(MYv=s_{l;BUDN1YAC$ zLBY4;TismRy}{BZoR^zk1U&V3F>y9|F2D9;?&ihO&OpwV&!z@_Mc+cEbga0zHuLPq z<3P`UkqE3}_MIgwC^%Q&i=X|km(rr8i%QJ@=KlF%(%tc5!HWOOc%OM5TbP0l+XkKv9FN} literal 0 HcmV?d00001 diff --git a/routes/Imagenes/persona_12.png b/routes/Imagenes/persona_12.png new file mode 100644 index 0000000000000000000000000000000000000000..5fe6d563150bc8d06dbf0cdf9a96fcea09bd71ab GIT binary patch literal 341 zcmeAS@N?(olHy`uVBq!ia0vp^6G4~*NH9Fx%=({!fl z7cIVVqjzfAk~pPBS6#w^(or5IDb{=YJ2DglFGTY@DJ@cWbu^RulXY%WXUDRuir%7g zrk&Cd4BTe_Yfr?Ks>x4VJ6`Ao3It7`F0QnwF3_Obw$nG##f5i~_VEP=>p>P=Zoj-$ zxnf$!iqMez#;m{pnlP#Yu zT$~p<9_rob=3=6I%}YOZtBbwh#XElkquSrx{wXZT`*h3Ke)+U{vVwx4uKi|8FtF&p a_+G{>E3c&=b`QP+3NKGrKbLh*2~7Zw`;RsN literal 0 HcmV?d00001 diff --git a/routes/Imagenes/persona_2.png b/routes/Imagenes/persona_2.png new file mode 100644 index 0000000000000000000000000000000000000000..f0d1d625bc90aea09fa791a8eec1edf147ecd4db GIT binary patch literal 342 zcmeAS@N?(olHy`uVBq!ia0vp^6G4~*NH9Fx%=({!fl=1e#WAGf*4tZ_e9VeG3lGBtJ=e$N`{RYfl#Uf%B6Gj{ zAH9|3>+KSvA|=jrd^ON&rHg*&4Gn*Fb_m_e(6#F5SmkojJnAv~lh3-+N{dV`E=Ka` ach~%m@bfk97sXbC0?gCZ&t;ucLK6UCbCrbv literal 0 HcmV?d00001 diff --git a/routes/Imagenes/persona_3.png b/routes/Imagenes/persona_3.png new file mode 100644 index 0000000000000000000000000000000000000000..52981df666fde45207f094e17e1256c5de1b9b52 GIT binary patch literal 341 zcmeAS@N?(olHy`uVBq!ia0vp^6G4~*NH9Fx%=({!flN{d1lt?llB dffs)l=|48F+~%UT=OHM(JYD@<);T3K0RV^Fkskm6 literal 0 HcmV?d00001 diff --git a/routes/Imagenes/persona_4.png b/routes/Imagenes/persona_4.png new file mode 100644 index 0000000000000000000000000000000000000000..262f1b9e1cc0b9e4f584cc14739bf33aa68adeb8 GIT binary patch literal 335 zcmeAS@N?(olHy`uVBq!ia0vp^6G4~*NH9Fx%=({!fl1lwe@df05kluXj91FW!El7Z`SSNV)vvd{kM!Y?+md%hp9NcB(&}F<)L#aIL`8{4dPgTxU+} zSn*PN?XxMqE+PNV$<5g+EO=LC);@KwP&K720oVN(t@xQvt1otO`TF_IBv%(0`0{&^ YdDarfNcl6IEufI{boFyt=akR{0LIUZ^S~B^Ra>w4E*xH__5k$+q$<-E+uO->Vgus?%);-Y<{6* z)|P&5zw|mGLE9jc`9gwwqfGi;lol=T43fN1b8FH@LBY2xGJ^%L1*HlLzJ1}mY?it1 z+(4y8L3Ji7b96?oy0vWr%j-|FGHqvPT-y)#Jm$Q5S>rA4=0f7ZKS+>*8Ol$z2l#Z&t)avhNp zyeRFWYpN@F(RR_aa~gsd%>oljmpUmZy%Jw~FJtL0Q}6oC9UZS0MY9XSz{TIL@wxNn UuG1A4F9rpZr>mdKI;Vst04jZf!~g&Q literal 0 HcmV?d00001 diff --git a/routes/Imagenes/persona_8.png b/routes/Imagenes/persona_8.png new file mode 100644 index 0000000000000000000000000000000000000000..8f9cf8ca59306e1c90dd8b74ef9d869a08af78a3 GIT binary patch literal 332 zcmeAS@N?(olHy`uVBq!ia0vp^6G4~*NH9Fx%=({!fl=7g#WAGf*4tZ-Ld^;SEDrzw zzkD+9Qc76L)R5v&4vz8L64`L~1w1n+8c?Yj72_0H33O1qTWeSTlx zmolZ}#g)G=ekTeZv1pvrvBG(c)jQ=5)|1Uez3Zk}zbfFKO4)vsdS!j=6X TZ=1>lP%wGA`njxgN@xNAAb^b{ literal 0 HcmV?d00001 diff --git a/routes/Imagenes/qr_ejemplo.png b/routes/Imagenes/qr_ejemplo.png old mode 100644 new mode 100755 diff --git a/routes/comprobante.pdf b/routes/comprobante.pdf deleted file mode 100644 index beeb0665760a572f8ac9321694a2625bc58311ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2141 zcmbVNc~BEq824soQQB$MYRBp;hs1M_Bpad>Asi7wr9{VSL|Kvzh9EdqnK9vQS&JSs@7*tZKY9MiGW{b%QW`}^MSd*And zzx9g=il_Gwx;e+59zyO<&gaig6=)AP$G(f{sd9{Y8cp5=<6u_n`5HvJIdLIR2J2Tuj0dcZ#AyUHiKmBZAZ%4#e)ks?{6;#FoSg2X@yY6zi%bnr0IDWq=HTt%)$2 zc-jKc2or2`7_DRVw2;N|7Me06se5em&oPbIP{+$je-4}<9_ww+Z>G+Y@h7PAVbc$n z)JCO`TG`yvQj`2`nY~Vu)nEO6minnfoufK$4L`ZCs$fl0hpa5M)u@neV;wXYa5w_#C{tjeat^%rwn7bVr# z4;T}i=F~6L{t+Fp?nr^x&G!1W>ivUe7Eh18Pa}}MPJWTEsYzIW zx%3W2cpNyKd7vX(W6d0&lX1(?tjtff%-sF-@!=s0M(zrwB~<^(t%Tuemk z(KU0DCGX^=v!8EpsK4~`-E!#*Yi3<#O8%0?nV$3R4Yz5Fk?S%3{n9r)85keDws3&$ z$?);FJym{L^pxDFyBXzplQMH>b?FCu*`s)$mPf4(KicjTm&YA1Q3bV(+RmF$-{5Me z8yYF547ZYTzcraO3#iX@fvq~#Yo0VnHs1$03X4c1>#`t?UK2($0 zg*oFE&dF{&_44(Nn~rV8{*}v@-X6BB!{3pj8d1|odG4Q>g*z^8RBUT3fA_k?dDpqE zX;QQ^{>88ci1<9Y}ZpG@}w|iBl4Dcuk&R%StV5#;f zaW;8umYBbqw2}Bb=jZ!WKYNkoim7nlp(A@stdoD(F~~m6xZuW5+kJAXO&=wXqoO9{ zO|5QtSZR-%eZ2p~7jb8=P8$`SvBGC`+lagi33YalJZIC$*=zcz7cgT5H|V;vE?hP9$em1d(-G9P-l~J@!38cTzECI{ zo`q|H!nHQCOc>M_z&riIElEMnE=hL!ogjMzRZ$!*8UQ+zHYL-%QAZ)D#+ty3o+u!p zZo?TURU?xK&;>>&gyD>?KsU_`&hZ}!rl?qx{{OMK+6nE-eKuF~-CiC_@sx>86kIkD zdS#c%&Y{e3Av9I=E7$D$6fPzS-fI;M8bPCsdJbp>Bae;iM%#TlVKfI#8WsQm+DW5D zM6A2YR10lDFo2T?_T~YkTrQOZ1L%t3auV(;Jb-xkhO)DwqG74XQtVnje6UJMg1TTdK@Df-}W0)x}*iNkRm-kaVr860Tu7}*WS zTPUN6wut|3jd3Ns?IeQ6vMdj}q!Gy&SOEW_qAnuCfHshn69$UZDGf3LHz*A_4!eLG j5@Z;qBLkFDT@ZLXM4TtbQx;wvB~Fqg;^!AWHv;(w${^np diff --git a/routes/cupo.js b/routes/cupo.js new file mode 100644 index 0000000..dfb5c60 --- /dev/null +++ b/routes/cupo.js @@ -0,0 +1,26 @@ +const connection = require('../conf/connection.js'); +const express = require('express') +var app = express(); + +app.get('/cupo', async(req, res) => { + let arr = []; + connection.query(`Select * from conferencia;`, async(error, results, file) => { + if (error) { + res.status(200).json({ err: false }); + return; + } + await results.forEach(element => { + if (element.idConferencia == 7) + arr.push([element.nombre, 'ilimitado', 100000 - element.capacidad]); + else + arr.push([element.nombre, 150, 150 - element.capacidad]); + + }); + res.status(200).json(arr); + return; + + }); +}); + + +module.exports = app; \ No newline at end of file diff --git a/routes/descargar_pdf.js b/routes/descargar_pdf.js new file mode 100644 index 0000000..eeb9e7f --- /dev/null +++ b/routes/descargar_pdf.js @@ -0,0 +1,10 @@ +const connection = require('../conf/connection.js'); +const express = require('express') +var app = express(); + + +app.get('/descargar_pdf', (req, res) => { + res.download(__dirname + `/../public/comprobante-${req.query.idPersona}.pdf`); +}) + +module.exports = app; \ No newline at end of file diff --git a/routes/g_img.js b/routes/g_img.js new file mode 100644 index 0000000..7912fed --- /dev/null +++ b/routes/g_img.js @@ -0,0 +1,10 @@ +var qr = require('qr-image'); +let i_m = async function(persona) { + + var qr_svg = await qr.image(`${persona}`, { type: 'png' }); + await qr_svg.pipe(require('fs').createWriteStream(__dirname + `/Imagenes/persona_${persona}.png`)); + + // var svg_string = qr.imageSync(`${persona}`, { type: 'png' }); + return +} +module.exports = i_m; \ No newline at end of file diff --git a/routes/getConferencias.js b/routes/getConferencias.js index 903cac7..d18f24f 100644 --- a/routes/getConferencias.js +++ b/routes/getConferencias.js @@ -2,275 +2,41 @@ const connection = require('../conf/connection.js'); const express = require('express') var app = express(); -var conferencias = { - dia1: { - conf1: { - nombre: "", - fecha: "", - asistir: false - }, - conf2: { - nombre: "", - fecha: "", - asistir: false - }, - conf3: { - nombre: "", - fecha: "", - asistir: false - } - }, - dia2: { - conf1: { - nombre: "", - fecha: "", - asistir: false - }, - conf2: { - nombre: "", - fecha: "", - asistir: false - }, - conf3: { - nombre: "", - fecha: "", - asistir: false - } - }, - dia4: { - conf1: { - nombre: "", - fecha: "", - asistir: false - }, - conf2: { - nombre: "", - fecha: "", - asistir: false - }, - conf3: { - nombre: "", - fecha: "", - asistir: false - } - }, - dia5: { - conf1: { - nombre: "", - fecha: "", - asistir: false - }, - conf2: { - nombre: "", - fecha: "", - asistir: false - }, - conf3: { - nombre: "", - fecha: "", - asistir: false - } - } - -} - app.get('/getConferencias', (req, res) => { - - - connection.query(`select * from conferencia ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - - conferencias.dia1.conf1.nombre = results[0].nombre; - conferencias.dia1.conf1.fecha = results[0].fecha; - conferencias.dia1.conf2.nombre = results[1].nombre; - conferencias.dia1.conf2.fecha = results[1].fecha; - conferencias.dia1.conf3.nombre = results[2].nombre; - conferencias.dia1.conf3.fecha = results[2].fecha; - - conferencias.dia2.conf1.nombre = results[3].nombre; - conferencias.dia2.conf1.fecha = results[3].fecha; - conferencias.dia2.conf2.nombre = results[4].nombre; - conferencias.dia2.conf2.fecha = results[4].fecha; - conferencias.dia2.conf3.nombre = results[5].nombre; - conferencias.dia2.conf3.fecha = results[5].fecha; - - conferencias.dia4.conf1.nombre = results[6].nombre; - conferencias.dia4.conf1.fecha = results[6].fecha; - conferencias.dia4.conf2.nombre = results[7].nombre; - conferencias.dia4.conf2.fecha = results[7].fecha; - conferencias.dia4.conf3.nombre = results[8].nombre; - conferencias.dia4.conf3.fecha = results[8].fecha; - - conferencias.dia5.conf1.nombre = results[9].nombre; - conferencias.dia5.conf1.fecha = results[9].fecha; - conferencias.dia5.conf2.nombre = results[10].nombre; - conferencias.dia5.conf2.fecha = results[10].fecha; - conferencias.dia5.conf3.nombre = results[11].nombre; - conferencias.dia5.conf3.fecha = results[11].fecha; - - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[0].idConferencia}' ;`, function(error, results, fields) { + console.log(req.body); + connection.query(`select * from conferencia ;`, + function(error, results, fields) { if (error) { res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); connection.end(); - throw error; + return; } - if (results.length > 0) - conferencias.dia1.conf1.asistir = true; + + connection.query(`select * from asistencia a join conferencia c on a.idConferencia=c.idConferencia where a.idPersona=${req.query.idPersona}`, + async(error2, results2, file2) => { + if (error2) { + res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); + connection.end(); + return; + + } + let data = { + conf: results, + activas: [] + } + for (let index = 0; index < results2.length; index++) { + data.activas.push(results2[index].idConferencia) + + } + //console.log(results); + //console.log(results2); + res.status(200).json(data); + return; + }); }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[1].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia1.conf2.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[2].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia1.conf3.asistir = true; - - }); - - - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[3].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia2.conf1.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[4].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia2.conf2.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[5].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia2.conf3.asistir = true; - - }); - - - - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[6].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia4.conf1.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[7].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia4.conf2.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[8].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia4.conf3.asistir = true; - - }); - - - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[9].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia5.conf1.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[10].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia5.conf2.asistir = true; - - }); - connection.query(`select * from asistencia where idPersona='${req.body.idPersona}' - and idConferencia='${results[11].idConferencia}' ;`, function(error, results, fields) { - if (error) { - res.status(400).json({ err: true, mjs: 'error en la consulta de conferencia' }); - connection.end(); - throw error; - - } - if (results.length > 0) - conferencias.dia5.conf3.asistir = true; - - }); - // console.log(req.body.idPersona); - res.status(200).json(conferencias); - }); - }); - - module.exports = app; \ No newline at end of file diff --git a/routes/get_pdf.js b/routes/get_pdf.js new file mode 100644 index 0000000..58e6f76 --- /dev/null +++ b/routes/get_pdf.js @@ -0,0 +1,13 @@ +const connection = require('../conf/connection.js'); +const fs = require('fs'); +const express = require('express') +var app = express(); +var pdf = require('./pdf.js'); +const path = require('path'); +app.get('/get_pdf', async(req, res) => { + await pdf(req.query.idPersona); + res.status(200).json({ err: false, msj: " listo" }); + + }) + //pdf(req.query.idPersona).then(res.status(200).json({ err: false, msj: 'exito' })); +module.exports = app; \ No newline at end of file diff --git a/routes/get_qr.js b/routes/get_qr.js new file mode 100644 index 0000000..b9f5467 --- /dev/null +++ b/routes/get_qr.js @@ -0,0 +1,13 @@ +const express = require('express') + +var app = express(); +var i_m = require('./g_img.js'); + + +app.get('/get_qr', async(req, res) => { + + i_m(req.query.idPersona); + res.status(200).json({ err: false }); +}) + +module.exports = app; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 7407cbc..fe100fe 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,5 +5,9 @@ app.use(require('./registro')); app.use(require('./registroPersona')); app.use(require('./loggin')); app.use(require('./getConferencias')); +app.use(require('./get_pdf')); +app.use(require('./descargar_pdf')); +app.use(require('./get_qr')); app.use(require('./verificarConferencia')); +app.use(require('./cupo')); module.exports = app; \ No newline at end of file diff --git a/routes/loggin.js b/routes/loggin.js index 56a003b..9ed0768 100644 --- a/routes/loggin.js +++ b/routes/loggin.js @@ -4,24 +4,29 @@ const bcrypt = require('bcryptjs'); var app = express(); app.post('/loggin', async(req, res) => { + if (!req.body.correo || req.body.correo == "") { + res.status(400).json({ error: true, msj: "faltan datos" }); + return; + } + console.log(req.body); connection.query(`SELECT idPersona from persona where correo = '${req.body.correo}' `, function(error, results, fields) { if (error) { res.status(400).json({ err: true, mjs: 'error en la verificacion del correo' }); - throw error; + return; } if (results.length == 0) { res.status(400).json({ err: true, mjs: 'Correo no registrado' }); - throw error; + return; } else { connection.query(`select * from persona where correo = '${req.body.correo}'`, async function(e, r, f) { if (e) { res.status(200).json({ err: true, mjs: 'error en la verificacion del de la contraseña' }); - throw error; + return; } let po = r[0].password; @@ -29,11 +34,11 @@ app.post('/loggin', async(req, res) => { //console.log(r, `'${req.body.correo}' and password= '${req.body.password}'`); let ban = bcrypt.compareSync(req.body.password, po); if (ban == true) { - res.status(200).json({ err: false, mjs: 'Bienvenido', idPersona: r[0].idPersona, nombre: r[0].nombre }); + res.status(200).json({ err: false, mjs: `Bienvenid@ ${r[0].nombre}`, idPersona: r[0].idPersona }); return; } else { res.status(400).json({ err: true, mjs: 'Datos Incorrectos' }); - throw error; + return; } }); } @@ -42,12 +47,4 @@ app.post('/loggin', async(req, res) => { -module.exports = app; - - - -// { -// "correo": "daniel.adrian.ramirez.george@gmail.com", -// "password": "georgechido" - -// \ No newline at end of file +module.exports = app; \ No newline at end of file diff --git a/routes/pdf.js b/routes/pdf.js index f338208..0a8d259 100644 --- a/routes/pdf.js +++ b/routes/pdf.js @@ -1,160 +1,114 @@ +'use strict'; + const fs = require('fs'); const PDFDocument = require('./pdfkit-tables'); -const doc = new PDFDocument(); -doc.pipe(fs.createWriteStream('comprobante.pdf')); -// Embed a font, set the font size, and render some text +const connection = require('../conf/connection.js'); +const path = require('path'); +var i_m = require('./g_img.js'); -// Add an image, constrain it to a given size, and center it vertically and horizontally +let g_pdf = async function(idPersona) { + + + const doc = new PDFDocument({ size: 'A4' }); + doc.pipe(fs.createWriteStream(__dirname + `/../public/comprobante-${idPersona}.pdf`)); + + + let inicio = 120; -const table0 = { - headers: ['Word', 'Comment', 'Summary'], - rows: [ - ['Apple', 'Not this one', 'la gravida ultrices. Fusce vitae pulvinar magna.'], - ['Tire', 'Smells like funny', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla viverra at ligula gravida ultrices. Fusce vitae pulvinar magna.'] - ] -}; + doc.image(__dirname + '/Imagenes/logo_unam.png', inicio, 30, { scale: 0.04 }); -doc.table(table0, { - prepareHeader: () => doc.font('Helvetica-Bold'), - prepareRow: (row, i) => doc.font('Helvetica').fontSize(12) -}); + doc.font('Times-Roman') + .fontSize(10) + .text('UNIVERSIDAD NACIONAL AUTONOMA DE MEXICO', inicio + 60, 40); + doc.font('Times-Roman') + .fontSize(10) + .text('FACULTAD DE ESTUDIOS SUPERIORES ACATLÁN', inicio + 66, 50); + doc.font('Times-Roman') + .fontSize(10) + .text('JORNADA DE INSERCIÓN LABORAL', inicio + 95, 60); -const table1 = { - headers: ['Country', 'Conversion rate', 'Trend'], - rows: [ - ['Switzerland', '12%', '+1.12%'], - ['France', '67%', '-0.98%'], - ['England', '33%', '+4.44%'] - ] -}; + doc.image(__dirname + '/Imagenes/Fesa.jpg', inicio + 305, 30, { scale: 0.05 }); + // Add another page -doc.moveDown().table(table1, 100, 350, { width: 300 }); + doc.font('Times-Roman') + .fontSize(8) + .text('COMPROBANTE DE INSCRIPCIÓN', inicio + 120, 80); -doc.end(); -// let inicio = 120; -// doc.image('Imagenes/logo_unam.png', inicio, 30, { scale: 0.04 }); + doc.moveTo(70, 110) + .lineTo(542, 110); -// doc.font('Times-Roman') -// .fontSize(10) -// .text('UNIVERSIDAD NACIONAL AUTONOMA DE MEXICO', inicio + 60, 40); -// doc.font('Times-Roman') -// .fontSize(10) -// .text('FACULTAD DE ESTUDIOS SUPERIORES ACATLÁN', inicio + 66, 50); -// doc.font('Times-Roman') -// .fontSize(10) -// .text('JORNADA DE INSERCIÓN LABORAL', inicio + 95, 60); + let marg = 70; -// doc.image('Imagenes/Fesa.jpg', inicio + 305, 30, { scale: 0.05 }); -// // Add another page + doc.image(__dirname + `/Imagenes/persona_${idPersona}.png`, marg, 120, { scale: 0.85 }); -// doc.font('Times-Roman') -// .fontSize(8) -// .text('COMPROBANTE DE INSCRIPCIÓN', inicio + 120, 80); + const table0 = { + headers: ['Nombre', 'Correo'], + rows: [] + }; -// let marg = 70; -// doc.image('Imagenes/qr_ejemplo.png', marg, 120, { scale: 0.50 }); - - -// // doc.moveTo(marg + 100, 120) -// // .lineTo(marg + 200, 120) -// // .stroke(); + doc.font('Times-Roman') + .fontSize(13) + .text('CONFERENCIAS', inicio + 142, 240); + var table1 = { + headers: ['Nombre', 'Fecha ', 'Hora'], + rows: [] + }; + connection.query(`select * from persona where idPersona=${idPersona}`, + (erro, results, file) => { + if (erro) { + res.status(400).json({ mjs: "Error en traer los datos del alumno" }); + return; + } + table0.rows.push([results[0].nombre + " " + results[0].apellidos, results[0].correo]); + doc.moveDown().table(table0, 200, 150, { width: 300 }); + }); + connection.query(`select * from asistencia a join conferencia c on a.idConferencia=c.idConferencia where idPersona=${idPersona}`, + (erro, results, file) => { + if (erro) { + res.status(400).json({ mjs: "error en las conferencias" }); + return; + } + //console.log(results) + for (let index = 0; index < results.length; index++) { + let po = results[index].fecha; + let dia = po.getDate(); + let mes = po.getMonth(); + let anio = po.getFullYear(); + let hora = po.getHours(); + let min = po.getMinutes(); + if (hora < 10) { + let aux = `0${hora}`; + hora = aux; + } + if (min < 10) { + let aux = `0${min}`; + min = aux; + } + if (dia < 10) { + let aux = `0${dia}`; + dia = aux; + } + if (mes < 10) { + let aux = `0${mes}`; + mes = aux; + } + let uno = `${dia}/${mes}/${anio}`; + let dos = `${hora}:${min}`; + table1.rows.push([results[index].nombre, uno, dos]) - - - - - - - -// doc.addPage() -// .fontSize(25) -// .text('Here is some vector graphics...', 100, 100); - - - -// // Draw a triangle -// doc.save() -// .moveTo(100, 110) -// .lineTo(100, 110) -// .lineTo(100, 150) -// .fill("#FF3300"); - -// // Apply some transforms and render an SVG path with the 'even-odd' fill rule -// doc.scale(0.6) -// .translate(470, -380) -// .path('M 250,75 L 323,301 131,161 369,161 177,301 z') -// .fill('red', 'even-odd') -// .restore(); - -// // Add some text with annotations -// // doc.addPage() -// // .fillColor("blue") -// // .text('Here is a link!', 100, 100) -// // .underline(100, 100, 160, 27, { color: "#0000FF" }) -// // .link(100, 100, 160, 27, 'http://google.com/'); - -// // Finalize PDF file -// doc.end(); - - - - - -// const PDFDocument = require('pdfkit'); -// var fs = require('fs'); -// // Create a document -// const doc = new PDFDocument; - -// // Pipe its output somewhere, like to a file or HTTP response -// // See below for browser usage -// doc.pipe(fs.createWriteStream('output.pdf')); - -// // Embed a font, set the font size, and render some text -// doc.font('fonts/PalatinoBold.ttf') -// .fontSize(25) -// .text('Some text with an embedded font!', 100, 100); - -// // Add an image, constrain it to a given size, and center it vertically and horizontally -// doc.image('path/to/image.png', { -// fit: [250, 300], -// align: 'center', -// valign: 'center' -// }); - -// // Add another page -// doc.addPage() -// .fontSize(25) -// .text('Here is some vector graphics...', 100, 100); - -// // Draw a triangle -// doc.save() -// .moveTo(100, 150) -// .lineTo(100, 250) -// .lineTo(200, 250) -// .fill("#FF3300"); - -// // Apply some transforms and render an SVG path with the 'even-odd' fill rule -// doc.scale(0.6) -// .translate(470, -380) -// .path('M 250,75 L 323,301 131,161 369,161 177,301 z') -// .fill('red', 'even-odd') -// .restore(); - -// // Add some text with annotations -// doc.addPage() -// .fillColor("blue") -// .text('Here is a link!', 100, 100) -// .underline(100, 100, 160, 27, { color: "#0000FF" }) -// .link(100, 100, 160, 27, 'http://google.com/'); - -// // Finalize PDF file -// doc.end \ No newline at end of file + } + doc.moveDown().table(table1, 70, 270, { width: 470 }); + doc.end(); + }); + return; +} +module.exports = g_pdf; \ No newline at end of file diff --git a/routes/pdfkit-tables.js b/routes/pdfkit-tables.js index 91c4c37..5ba08a7 100644 --- a/routes/pdfkit-tables.js +++ b/routes/pdfkit-tables.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict '; const PDFDocument = require('pdfkit'); diff --git a/routes/registro.js b/routes/registro.js index f877ee1..1793e1d 100644 --- a/routes/registro.js +++ b/routes/registro.js @@ -5,28 +5,30 @@ var app = express() app.post('/registro', async(req, res) => { let body = req.body; - + console.log(req.body); await body.alta.forEach(element => { connection.query(`Select capacidad from conferencia where idConferencia=${element};`, (error, results, fields) => { if (error) { res.status(400).json({ msj: `Error al actualizar la asistencia` }); - throw error; + return; } if (results[0].capacidad < 1) { res.status(400).json({ msj: `Capacidad llena de la conferencia ${element}` }); - throw error; + return; } }); }); + await body.alta.forEach(element => { - connection.query(`INSERT INTO asistencia VALUES(null,${element},${body.idPersona},false)`, + console.log('alta'); + connection.query(`INSERT INTO asistencia VALUES(null,${element},${body.idPersona},false);`, (error, results, fields) => { if (error) { res.status(400).json({ msj: `Error al actualizar la asistencia` }); - throw error; + return; } }); @@ -35,22 +37,30 @@ app.post('/registro', async(req, res) => { function(error, results, fields) { if (error) { res.status(400).json({ err: true, msj: 'Error en la actualizacion de asistencia' }); - throw error; + return; } }); }); await body.baja.forEach(element => { + connection.query(`update conferencia set capacidad=capacidad+1 where idConferencia=${element};`, + function(error, results, fields) { + if (error) { + res.status(400).json({ err: true, msj: 'Error en la actualizacion de asistencia' }); + return; + } + }); connection.query(`delete from asistencia where idConferencia=${element} and idPersona=${body.idPersona};`, (error, results, fields) => { if (error) { res.status(400).json({ msj: `Error al actualizar eliminar la asistencia` }); - throw error; + return; } }); }); await res.status(200).json({ err: false, msj: 'exito' }); + return; }); module.exports = app \ No newline at end of file diff --git a/routes/registroPersona.js b/routes/registroPersona.js index 87f118e..5530a41 100644 --- a/routes/registroPersona.js +++ b/routes/registroPersona.js @@ -4,18 +4,18 @@ const bcrypt = require('bcryptjs'); var app = express() app.post('/registroPersona', async(req, res) => { - //console.log(req.body.correo); + console.log(req.body); var pass = await bcrypt.hash(req.body.password, 10); //console.log(pass); + connection.query(`SELECT * from persona where correo='${req.body.correo}'; `, async function(error, results, fields) { if (error) { res.status(200).json({ err: true, mjs: 'error en la comprobacion del correo' }); connection.end(); - throw error; - + return; } - // console.log(results.length); + // console.log(results.length); if (results.length == 0) { @@ -27,7 +27,7 @@ app.post('/registroPersona', async(req, res) => { if (e) { res.status(200).json({ err: true, mjs: 'error al registrar en la base' }); connection.end(); - throw error; + return; } let id = 2; @@ -40,11 +40,11 @@ app.post('/registroPersona', async(req, res) => { mjs: 'error al registrar en select ' }); connection.end(); - throw error; + return; } // console.log(r); //id = r[0]; - res.status(200).json({ err: false, idPerosna: r[0].idPersona, msj: 'Registro completo' }); + res.status(200).json({ err: false, idPersona: r[0].idPersona, msj: 'Registro completo' }); return; }); diff --git a/routes/verificarConferencia.js b/routes/verificarConferencia.js index 9717a5c..00bd0df 100644 --- a/routes/verificarConferencia.js +++ b/routes/verificarConferencia.js @@ -1,29 +1,25 @@ const connection = require('../conf/connection.js'); -const express = require('express'); +const express = require('express') var app = express(); - -app.get('/verificarConferencia', (req, res) => { - - console.log(req.body.idConferencia); - connection.query(`Select capacidad from conferencia where idConferencia=${req.body.idConferencia};`, - function(error, results, fields) { - if (error) { - res.status(200).json({ err: 'error' }); - throw error; - } - if (results[0].capacidad > 0) { - res.status(200).json({ res: true }); - return; - } else { - res.status(200).json({ res: false }); +app.get('/verificarConferencia', async(req, res) => { + if (!req.query.idConferencia || req.query.idConferencia == "") { + res.status(400).json({ err: true, msj: "Faltan datos" }) + return; + } + connection.query(`select capacidad from conferencia where idConferencia=${req.query.idConferencia};`, + (err, results, file) => { + if (err) { + res.status(400).json({ err: true, msj: "error en el select" }) return; } + // console.log(results); + if (results[0].capacidad > 0) + res.status(200).json({ err: false, cap: true }); + else + res.status(200).json({ err: false, cap: false }); }); }); -pp = (req, res) => { - -} module.exports = app; \ No newline at end of file