-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
126 lines (85 loc) · 2.24 KB
/
index.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
import express from "express";
import bodyParser from "body-parser";
import pg from "pg";
import bcrypt from "bcrypt";
import { spawn } from "child_process";
import path from "path";
// import multer from "multer";
// import { spawn } from "child_process";
// import path from "path";
// const { spawn } = require("child_process");
// const storage = multer.diskStorage({
// destination: function (req, file, cb) {
// cb(null, './uploads/')
// },
// filename: function (req, file, cb) {
// cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname))
// }
// })
// const upload = multer({ storage: storage })
const app = express();
const port = 3000;
const saltRounds = 10;
const db = new pg.Client({
user: "postgres",
host: "localhost",
database: "secrets",
password: "vishnu2004",
port: 5432,
});
db.connect();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.get("/", (req, res) => {
res.render("home.ejs");
});
app.get("/sign-in", (req, res) => {
res.render("sign-in.ejs");
});
app.get("/login", (req, res) => {
res.render("login.ejs");
});
app.get("/imgver", (req,res) => {
res.render("imgver.ejs");
})
app.get("/fakenews", (req,res) => {
res.render("fakenews.ejs");
})
app.get("/chat", (req,res) => {
res.render("newsupdates.ejs");
})
app.post("/sign-in", async (req, res) => {
const email = req.body.username;
const password = req.body.password;
try {
const checkResult = await db.query("SELECT * FROM users WHERE email = $1", [
email,
]);
if (checkResult.rows.length > 0) {
res.send("Email already exists. Try logging in.");
} else {
bcrypt.hash(password,saltRounds, async(err,hash) => {
if(err){
console.log(err)
}
else{
const result = await db.query(
"INSERT INTO users (email, passwor) VALUES ($1, $2)",
[email, hash]
);
console.log(result);
res.render("postlogin.ejs");
}
})
}
} catch (err) {
console.log(err);
}
});
app.post("/imgver", (req, res) => {
});
app.post("/fakenews", (req, res) => {
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});