-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
70 lines (58 loc) · 1.85 KB
/
server.js
File metadata and controls
70 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var express = require("express");
const nodemailer = require('nodemailer');
var app = express();
app.use(express.urlencoded({ extended: false }));
app.get("/", function(req, res) {
res.sendFile(__dirname + "/login.html");
})
let nome = [];
let email = [];
let senha = [];
app.post("/enviar-email", async (req, res) => {
var transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "3ab3ee54a82786",
pass: "bfb3039e0af76c"
}
});
var message = {
from: req.body.remetente,
to: req.body.destinatario,
subject: req.body.titulo,
text: req.body.mensagem,
html: "<p>HTML version of the message</p>"
};
transport.sendMail(message, function(err) {
if (err) return res.status(400).json({
erro: true,
mensagem: "Erro: E-mail não enviado com sucesso!"
});
});
return res.json({
erro: false,
mensagem: "E-mail enviado com sucesso!"
});
});
app.post("/logar", function(req, res) {
for(let i=0; i<email.length; i++) {
if(nome[i] == req.body.nome && senha[i] == req.body.senha){
res.sendFile(__dirname + "/email.html");
console.log("[LOGADO] " + req.body.nome + " " + req.body.senha);
}
}
})
app.post("/cadastrar", function(req, res) {
for(let i=0; i<email.length; i++) {
if(nome[i] == req.body.nome && email[i] == req.body.email && senha[i] == req.body.senha){
res.send("Erro ao cadastrar: email já sendo utilizado!");
return;
}
}
nome.push(req.body.nome);
email.push(req.body.email);
senha.push(req.body.senha);
console.log("[CADASTRO] " + req.body.nome + " | " + req.body.email + " | " + req.body.senha);
})
app.listen(3000, () => console.log('Server started...'));