-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
117 lines (117 loc) · 2.89 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
const express = require("express");
const app = express();
app.set("view engine", "ejs");
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname + "/public"));
var mysql = require("mysql2");
var connection = mysql.createConnection({
localhost: "3306",
user: "root", // your root username
password: "Hemanth@123",
database: "cameradotcom", // the name of your db
});
app.get("/", function (req, res) {
res.render("home");
});
app.get("/camera", function (req, res) {
res.render("camera");
});
app.get("/camerasetup", function (req, res) {
res.render("camerasetup");
});
app.get("/profile", function (req, res) {
res.render("profile");
});
app.get("/checknow", function (req, res) {
res.render("checknow");
});
app.get("/booknow", function (req, res) {
res.render("booknow");
});
app.get("/menu", function (req, res) {
connection.query("select * from profile", function (error, result, fields) {
if (!error) {
res.render("menu", { data: result });
} else {
res.redirect("/");
}
res.end();
});
});
app.post("/update", function (req, res) {
var data = {
name: req.body.name,
age: req.body.age,
camera: req.body.camera,
color: req.body.color,
};
// console.log(name + " " + age + " " + camera + " " + color);
res.render("card", {
personname: data.name,
personage: data.age,
personcamera: data.camera,
personcolor: data.color,
});
});
app.get("/login", function (req, res) {
res.render("login");
});
app.get("/signuppage", function (req, res) {
res.render("signup");
});
app.post("/signin", function (req, res) {
var username = req.body.username;
var password = req.body.password;
connection.query(
"select * from signin where username=? and password=?",
[username, password],
function (error, result, fields) {
if (result.length > 0) {
res.render("home");
} else {
res.render("login");
}
res.end();
}
);
});
app.post("/signup", function (req, res) {
var username = req.body.username;
var password = req.body.password;
connection.query(
"insert into signin(username,password) values(?,?)",
[username, password],
function (error, result, fields) {
if (!error) {
res.render("login");
} else {
res.redirect("/");
}
res.end();
}
);
});
app.post("/add", function (req, res) {
var name = req.body.name;
var age = req.body.age;
var sex = req.body.sex;
connection.query(
"insert into profile (name,age,sex) values(?,?,?)",
[name, age, sex],
function (error, result, fields) {
if (!error) {
res.redirect("/menu");
} else {
res.render("/");
}
res.end();
}
);
});
app.get("/home", function (req, res) {
res.render("home");
});
app.listen(3001, function () {
console.log("server running at port numver 3001!");
});