diff --git a/routes/registro.js b/routes/registro.js index 11e450f..19e4049 100644 --- a/routes/registro.js +++ b/routes/registro.js @@ -1,32 +1,42 @@ const connection = require('../conf/connection.js'); const express = require('express'); const nodemailer = require("nodemailer"); +var app = express() -async function main() { +async function sendEmail( destination ) { // Generate test SMTP service account from ethereal.email // Only needed if you don't have a real mail account for testing let testAccount = await nodemailer.createTestAccount(); // create reusable transporter object using the default SMTP transport let transporter = nodemailer.createTransport({ - host: "smtp.ethereal.email", - port: 587, - secure: false, // true for 465, false for other ports - auth: { - // user: 'hackatonaws@unam.mx', - // pass: 'H4ck4#20' - user: 'hackaton-test@pcpuma.acatlan.unam.mx', // generated ethereal user - pass: 'H4cka-T3st', // generated ethereal password - }, + host: "smtp-mail.outlook.com", + port: 587, + secure: false, // true for 465, false for other ports + auth: { + user: 'hackatonaws@unam.mx', // generated ethereal user + pass: 'H4ck4#20' + }, }); // send mail with defined transport object let info = await transporter.sendMail({ - from: '"Fred Foo 👻" ', // sender address - to: "bar@example.com, baz@example.com", // list of receivers - subject: "Hello ✔", // Subject line - text: "Hello world?", // plain text body - html: "Hello world?", // html body + from: '"Hackaton UNAM-AWS" ', // sender address + to: `"${destination}"`, // list of receivers + subject: "Registro Exitoso Hackaton UNAM-AWS 2020", // Subject line + text: `Tu registro se ha realizado de manera correcta es importante que considere el equipo la asistencia a las siguientes actividades + Capacitación 5 de agosto al 10 de septiembre 2020 + + Hackaton 11 al 12 de + septiembre 2020 + + Presentación proyectos + 13 de septiembre 2020 + + Premiación 13 de septiembre 2020 + + Una vez inscrito, se compartirán más detalles ¡Preparte!.`, // plain text body + html: "Hello world?", }); console.log("Message sent: %s", info.messageId); @@ -37,9 +47,6 @@ async function main() { // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... } -var app = express() - -// ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'georgechido' function query(consulta) { @@ -109,7 +116,7 @@ app.post('/registro', async(req, res) => { } try{ - let cad = `INSERT INTO Equipo VALUES (null, '${body.nombreEqui}', '${body.desafio}', '${body.campus}', ${body.numeroIntegrantes});`; + let cad = `INSERT INTO Equipo VALUES (null, '${body.nombreEqui}', '${body.desafio}', '${body.campus}', ${body.numeroIntegrantes}, false);`; await query(cad); cad = `SELECT COUNT(*) as num FROM Equipo;`; let ans = await query(cad); @@ -164,64 +171,31 @@ app.post('/registro', async(req, res) => { try{ - var nodemailer = require('nodemailer'); - var transporter = nodemailer.createTransport({ - service: 'gmail', - auth: { - user: 'hackaton-test@pcpuma.acatlan.unam.mx', - pass: 'H4cka-T3st' - } - }); - - var mailOptions = { - from: ` hackatonaws@unam.mx`, - to: `${body.correoLider}`, - subject: 'Registro HACKATHON VIRTUAL', - // text: `Tu registro se ha realizado de manera correcta es importante que considere el equipo la asistencia a las siguientes actividades - // Primer Taller: Julio 14   - // Segundo Taller: Julio 16 - // Tercer Taller: Julio 22 - // Cuarto Taller: Julio 28 - // Hackathon: Agosto 1-2 - - // Una vez inscrito, se compartirán más detalles.` - html: ` - - - - - - - - -

Image:

-

GIF (requires "amp-anim" script in header):
-

- - ` - }; - - await transporter.sendMail(mailOptions, function(error, info){ - // main().catch(error =>{ - // console.error - if(error){ - let men = `Error al enviar mensaje: ${error}`; - console.log(men); - res.status(400).json({ error: true, msj: men }); - + await sendEmail(`${body.correoLider}`).catch(async error =>{ + + console.log('Not email: ' + error); + res.status(400).json({ error: true, msj: "No se pudo enviar el Correo pero tu incripción fue exitosa", correo: false}); return; - - }else { - - console.log('Email sent: ' + info.response); + }).then( async ans=>{ + + let queryCad = `UPDATE Equipo SET notificaInscripcion=true WHERE idEquipo=${idEquipo};` + await query(queryCad).catch(error=> { + console.log('Not send: ' + error); + res.status(400).json({ error: true, msj: "No se pudo enviar el Correo pero tu incripción fue exitosa", correo: false}); + return; + + }); + console.log('Email si fue enviado: ' + ans); res.status(200).json({ error: false, msj: "exito"}); - return; - - } }); - // ); + + + + + + } catch(error){ let men = `Error al enviar mensaje: ${error}`; diff --git a/sql/script.sql b/sql/script.sql index bfbde51..8f2dad0 100644 --- a/sql/script.sql +++ b/sql/script.sql @@ -2,14 +2,14 @@ drop database hackDB; CREATE database hackDB; use hackDB CREATE TABLE `Admin` ( - `idUsuario` integer PRIMARY KEY NOT NULL AUTO_INCREMENT, + `idUsuario` integer PRIMARY KEY NOT NULL AUTO_INCREMENT, `usuario` varchar(100), `password` varchar(100) ); -- h4ch4#2020 -INSERT INTO admin VALUES (null, 'Administrador', '$2b$10$qM.oRmpQ3FjmPkq4m.l2JOx20X3grzTH71hP8emEQzUtApNqkie.G'); +INSERT INTO Admin VALUES (null, 'Administrador', '$2b$10$qM.oRmpQ3FjmPkq4m.l2JOx20X3grzTH71hP8emEQzUtApNqkie.G'); CREATE TABLE `Equipo` ( @@ -17,7 +17,8 @@ CREATE TABLE `Equipo` ( `nombre` varchar(100), `desafio` varchar(100), `campus` varchar(100), - `numeroIntegrantes` varchar(100) + `numeroIntegrantes` varchar(100), + `notificaInscripcion` boolean ); CREATE TABLE `Persona` (