-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
149 lines (143 loc) · 4.13 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var express = require("express");
require("dotenv").config();
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
const path = require("path");
const app = express();
app.use(bodyParser.json());
app.use(express.static("."));
app.use(
bodyParser.urlencoded({
extended: true,
})
);
const Schema = mongoose.Schema;
const userSchema = new Schema({
satisfaction: { type: Number, required: true },
recommend: { type: Number, required: true },
rate: { type: Number, required: true },
expectation: { type: Number, required: true },
service: { type: Number, required: true },
navigation: { type: Number, required: true },
features: { type: Number, required: true },
value: { type: Number, required: true },
processing: { type: Number, required: true },
deliver: { type: Number, required: true },
responsive: { type: Number, required: true },
ease_of_use: { type: Number, required: true },
effectiveness: { type: Number, required: true },
packaging: { type: Number, required: true },
availability: { type: Number, required: true },
overall: { type: Number, required: true },
});
const User = mongoose.model("feedback", userSchema);
mongoose.connect("mongodb://localhost:27017/coderone", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
var db = mongoose.connection;
db.on("error", () => console.log("Error in connecting to database"));
db.once("open", () => console.log("Connected to Database"));
app
.get("/", (req, res) => {
res.set({
"Allow-Control-Allow-Origin": "*",
});
return res.redirect("./feedback.html");
})
.listen(5000);
app.post("/feedback", (req, res) => {
var satisfaction = req.body.satisfaction;
var recommend = req.body.recommend;
var rate = req.body.rate;
var expectation = req.body.expectation;
var service = req.body.service;
var navigation = req.body.navigation;
var features = req.body.features;
var value = req.body.value;
var processing = req.body.processing;
var deliver = req.body.deliver;
var responsive = req.body.responsive;
var ease_of_use = req.body.ease_of_use;
var effectiveness = req.body.effectiveness;
var packaging = req.body.packaging;
var availability = req.body.availability;
var overall = req.body.overall;
var data = {
satisfaction: satisfaction,
recommend: recommend,
rate: rate,
expectation: expectation,
service: service,
navigation: navigation,
features: features,
value: value,
processing: processing,
deliver: deliver,
responsive: responsive,
ease_of_use: ease_of_use,
effectiveness: effectiveness,
packaging: packaging,
availability: availability,
overall: overall,
};
db.collection("feedback").insertOne(data, (err, collection) => {
if (err) {
throw err;
}
console.log(
JSON.stringify(
db.collection("feedback").find({}, function (result) {
console.log(result);
})
)
);
console.log("Record Inserted Successfully");
});
return res.redirect("./feedback.html");
});
app.post("/sign_up", (req, res) => {
var username = req.body.username;
var password = req.body.password;
var repeat_password = req.body.repeat_password;
var emailid = req.body.email;
var data = {
username: username,
password: password,
repeat_password: repeat_password,
emailid: emailid,
};
db.collection("users").insertOne(data, (err, collection) => {
if (err) {
throw err;
}
console.log(
JSON.stringify(
db.collection("users").find({}, function (result) {
console.log(result);
})
)
);
console.log("Record Inserted Successfully");
});
return res.redirect("./mainform.html");
});
app.post("/login", async (req, res) => {
try {
const user = await db
.collection("users")
.findOne({ username: req.body.username });
if (user) {
const result = req.body.password === user.password;
if (result) {
res.redirect("./mainform.html");
} else {
res.redirect("./feedback.html?pass");
}
} else {
res.redirect("./feedback.html?uname");
}
} catch {
res.send("wrong details");
}
});