login crate #2

Merged
danielGe merged 1 commits from CrateLogin into master 2020-08-04 03:19:06 +00:00
2 changed files with 50 additions and 75 deletions
+46 -72
View File
@@ -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 👻" <foo@example.com>', // sender address
to: "bar@example.com, baz@example.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
from: '"Hackaton UNAM-AWS" <hackatonaws@unam.mx>', // 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: "<b>Hello world?</b>",
});
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: `<!doctype html>
<html ⚡4email>
<head>
<meta charset="utf-8">
<style amp4email-boilerplate>body{visibility:hidden}</style>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
</head>
<body>
<p>Image: <amp-img src="https://cldup.com/P0b1bUmEet.png" width="16" height="16"/></p>
<p>GIF (requires "amp-anim" script in header):<br/>
<amp-anim src="https://cldup.com/D72zpdwI-i.gif" width="500" height="350"/></p>
</body>
</html>`
};
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}`;
+4 -3
View File
@@ -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` (