forked from the-evocative-eye/Tech-Mirror
-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.js
124 lines (121 loc) · 3.3 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const express = require("express");
const bodyparser = require("body-parser");
const logger = require("morgan");
const mongoose = require("mongoose");
const IP = require("ip");
const nodemailer = require("nodemailer");
const os = require("os");
const si = require("systeminformation");
const app = express();
app.use(bodyparser.json());
const port = 5000;
const path = require("path");
//serving static files
app.use(express.static("public")); //to use public folder
app.set("views", "./views");
app.set("view engine", "ejs");
app.use(bodyparser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "public")));
app.use(logger("dev"));
const homeRouter = require("./routes/homeroute");
const newsRouter = require("./routes/newsroute");
const chatRouter = require("./routes/chatRoutes");
app.use("/", homeRouter);
app.use("/article", newsRouter);
app.use("/chat",chatRouter)
app.get("/audio", (req, res) => {
res.render("audio");
});
app.get("/about", (req, res) => {
res.render("about");
});
app.get("/contact", (req, res) => {
res.render("contact");
});
app.get("/ebook", (req, res) => {
res.render("ebook");
});
app.get("/signup", (req, res) => {
res.render("signup");
});
let db = mongoose.connection; // this db is not working. Enter your db here
db.once("open", () => {
console.log("successfully connected");
});
db.on("err", () => {
console.log("error in connecting to database");
});
app.get("/signup_success", (req, res) => {
res.render("signup_success");
});
app.post("/signup", (req, res) => {
var name = req.body.name;
var email = req.body.email;
var tech_stack=req.body.tech_stack;
var purpose=req.body.purpose;
var data = {
name: name,
email: email,
tech_stack:tech_stack,
purpose:purpose
};
console.log("database");
connection.collection("users").insertOne(data, (err, collection) => {
if (err) {
console.log(err.messsage);
} else {
console.log("Successfully saved to database");
sendmail(email, "You have successfully logged in.");
}
alert("You have successfully logged in");
res.json({message: "You have successfully logged in."})
});
});
async function sendmail(email, bodystring) {
try {
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false,
requireTLS: true,
auth: {
user: "mirrortech8@gmail.com",
pass: "wrul wxov fvyd fvmv",
},
});
const data = await si.system();
const mailOptions = {
from: "mirrortech8@gmail.com",
to: email,
subject: "New login at Tech mirror",
html:
"<h1>From Tech mirror</h1><h2>" +
bodystring +
"</h2>" +
"<h3>System Information:</h3>" +
"<h4>IP: " +
IP.address() +
"</h4><h4>Operating System: " +
os.platform() +
"</h4><h4>Version: " +
os.version() +
"</h4><h4>Manufacturer: " +
data.manufacturer +
"</h4><h4>Model: " +
data.model +
"</h4>",
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
// console.log("Email has been sent");
}
});
} catch (error) {
console.log(error);
}
}
app.listen(port, () => {
console.log(`App is listening at ${port}`);
});