forked from wizardd254/Devdeck_VoyageVista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
122 lines (97 loc) · 2.9 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
const express = require("express");
const app = express();
const path = require("path");
const ejs = require("ejs");
const templatepath= path.join(__dirname,'./templates')
const collection = require("./src/mongodb");
const mongoose = require('mongoose');
const { Console } = require("console");
const { ObjectId } = mongoose.Types;
app.use(express.json());
app.set("view engine","ejs");
app.set("views",templatepath);
app.use(express.urlencoded({extended:false}));
// Set the path to the directory containing your static files
const publicDirectoryPath = path.join(__dirname, "./public");
// Serve static files from the public directory
app.use(express.static(publicDirectoryPath));
app.get("/",(req,res)=>{
res.render("login");
});
app.get("/signup",(req,res)=>{
res.render("signup");
});
app.post("/signup",async (req,res)=>{
try{
const data = {
name:req.body.name,
password:req.body.password
}
await collection.insertMany([data])
console.log("added to database");
res.redirect('/');
}
catch(err){
console.log(err.body);
res.render("signup");
}
})
app.post("/login",async (req,res)=>{
try {
const check = await collection.findOne({name:req.body.name});
if (check.password==req.body.password) {
res.redirect(`/search`);
} else {
console.log("wrongpassword");
res.redirect('/login');
}
} catch (error) {
console.log("invalid");
res.redirect('/login');
}
})
// You need to add a GET route for login
app.get("/login", (req, res) => {
res.render("login");
});
app.get("/blog", (req, res) => {
res.render("blog");
});
app.get("/aboutus", (req, res) => {
res.render("aboutus");
});
app.get("/contactus", (req, res) => {
res.render("contactus");
});
app.get("/destination", (req, res) => {
res.render("destination");
});
app.get("/search",(req,res)=>{
const id=req.params.id;
res.render("search",{id:id});
})
app.get("/plans", (req, res) => {
const id = req.params.id;
const city = req.query.city;
const placelistParam = req.query.placelist; // Retrieve placelist from query parameters
const descriptionListParam = req.query.description_list;
console.log("hello");
console.log(typeof(descriptionListParam))
console.log(descriptionListParam)
let placelist = [];
let descriptionList=[];
if (placelistParam) {
placelist = placelistParam.split(','); // Split placelist into an array
}
try{
descriptionList=JSON.parse(descriptionListParam);
}catch{
console.log(Error);
}
console.log(placelist)
console.log(descriptionList);
res.render("myplans", { id: id, city: city, placelist: placelist, descriptionList: descriptionList });
});
app.listen(8080,()=>{
console.log("port connected");
});