inicio del proyecto
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
const connection = require('../conf/connection');
|
||||
const express = require('express');
|
||||
const bcrypt = require('bcrypt');
|
||||
var app = express();
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
app.post('/loggin', async(req, res) => {
|
||||
|
||||
var aux = req.body.usuario;
|
||||
aux = aux.toLowerCase();
|
||||
let usuario = req.body.usuario;
|
||||
var password = req.body.password;
|
||||
var pass = await bcrypt.hash(password, 10);
|
||||
console.log(usuario, " ", pass, " ", password);
|
||||
var text = true;
|
||||
for (let i = 0; i < aux.length; i++) {
|
||||
if ((aux[i] < 'a' || aux[i] > 'z') && aux[i] != '_') {
|
||||
text = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let caadena = `select * from usuario;`
|
||||
let resuesta = await query(caadena)
|
||||
console.log("esta es la respuesta", resuesta);
|
||||
|
||||
|
||||
if (text == false) {
|
||||
res.status(400).json({ err: true, msj: "Correo o contraseña invalidos" });
|
||||
false;
|
||||
}
|
||||
|
||||
let password_consulta;
|
||||
try {
|
||||
|
||||
let select = `select * from usuario where usuario="${usuario}";`;
|
||||
|
||||
password_consulta = query(select);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: true, msj: "Error en la consulta en del usuario" });
|
||||
return;
|
||||
}
|
||||
let exite;
|
||||
let comparar;
|
||||
let id;
|
||||
await password_consulta.then(function(v) {
|
||||
existe = v.length;
|
||||
console.log(existe);
|
||||
if (existe == 1) {
|
||||
comparar = v[0].password
|
||||
id = v[0].id_usuario;
|
||||
}
|
||||
})
|
||||
if (existe == 0) {
|
||||
res.status(400).json({ err: true, mjs: 'Correo o contraseña invalidos' });
|
||||
return;
|
||||
}
|
||||
// var pass = await bcrypt.hash(password, 10);
|
||||
//console.log(pass);
|
||||
console.log(comparar);
|
||||
|
||||
let correcto = bcrypt.compareSync(password, comparar);
|
||||
if (correcto == true) {
|
||||
res.status(200).json({ err: false, mjs: `Bienvenido`, id_usuario: id });
|
||||
return;
|
||||
} else {
|
||||
res.status(400).json({ err: true, mjs: 'Correo o contraseña invalidos' });
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = app;
|
||||
+65
-12
@@ -1,6 +1,41 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express');
|
||||
var nodemailer = require('nodemailer');
|
||||
const nodemailer = require("nodemailer");
|
||||
|
||||
async function main() {
|
||||
// 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
|
||||
},
|
||||
});
|
||||
|
||||
// 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
|
||||
});
|
||||
|
||||
console.log("Message sent: %s", info.messageId);
|
||||
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
|
||||
|
||||
// Preview only available when sending through an Ethereal account
|
||||
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
||||
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
|
||||
}
|
||||
|
||||
var app = express()
|
||||
|
||||
@@ -55,6 +90,7 @@ app.post('/registro', async(req, res) => {
|
||||
let n_correo = depurado( body.correoLider);
|
||||
let cad = `SELECT * FROM Persona WHERE correo='${n_correo}' AND lider = true;`;
|
||||
let respuesta = await query(cad);
|
||||
console.log(respuesta);
|
||||
if (respuesta.length != 0) {
|
||||
|
||||
console.log( "El correo del lider ya fue registrado anteriormente");
|
||||
@@ -133,8 +169,8 @@ app.post('/registro', async(req, res) => {
|
||||
var transporter = nodemailer.createTransport({
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
user: 'hackatonaws@unam.mx',
|
||||
pass: 'H4ck4#20'
|
||||
user: 'hackaton-test@pcpuma.acatlan.unam.mx',
|
||||
pass: 'H4cka-T3st'
|
||||
}
|
||||
});
|
||||
|
||||
@@ -142,25 +178,41 @@ app.post('/registro', async(req, res) => {
|
||||
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
|
||||
// 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.`
|
||||
// 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){
|
||||
if (error) {
|
||||
// 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 });
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
}else {
|
||||
|
||||
console.log('Email sent: ' + info.response);
|
||||
res.status(200).json({ error: false, msj: "exito"});
|
||||
@@ -169,6 +221,7 @@ app.post('/registro', async(req, res) => {
|
||||
|
||||
}
|
||||
});
|
||||
// );
|
||||
}
|
||||
catch(error){
|
||||
let men = `Error al enviar mensaje: ${error}`;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
drop database hackDB;
|
||||
CREATE database hackDB;
|
||||
use hackDB
|
||||
CREATE TABLE `admin` (
|
||||
`idAdmin` integer PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
||||
`nombre` varchar(100),
|
||||
`password` varchar(100)
|
||||
);
|
||||
CREATE TABLE `Equipo` (
|
||||
`idEquipo` integer PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
||||
`nombre` varchar(100),
|
||||
|
||||
Reference in New Issue
Block a user