-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
70 lines (62 loc) · 1.55 KB
/
server.js
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
require("dotenv").config();
const express = require("express");
const mysql = require("mysql");
const cors = require("cors");
const nodemailer = require("nodemailer");
const PASS = process.env.PASS;
const app = express();
app.use(express.json());
app.use(cors());
const db = mysql.createConnection({
host: "192.168.1.26",
user: "Your Device Name",
password: "1234",
port: 3306,
database: "athena",
});
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "freeplay.cha@gmail.com",
pass: PASS,
},
});
app.post("/send-email", (req, res) => {
const { to, subject, text } = req.body;
const mailOptions = {
from: "freeplay.cha@gmail.com",
to,
subject,
text,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error("Error sending email:", error);
return res.status(500).send("Error sending email: " + error.message);
}
res.status(200).send("Email sent: " + info.response);
});
});
app.post("/login", (req, res) => {
const username = req.body.username;
const password = req.body.password;
db.query(
"SELECT * FROM users WHERE username = ? AND password = ?",
[username, password],
(err, result) => {
if (err) {
res.send({ err: err });
}
if (result.length > 0) {
const user = result[0];
res.send({ user });
} else {
res.send({ message: "Invalid Credentials" });
}
}
);
});
app.listen(3008, () => {
console.log("running server on port 3008");
});
module.exports = app;