-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
108 lines (88 loc) · 2.75 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
// ++++++++++++ Required packages +++++++++++++++++++
var express=require("express")
var app=express();
app.use(express.static("public"))
app.set("view engine","ejs")
var bodyparser=require("body-parser")
app.use(bodyparser.urlencoded({extended:true}))
var methodOverride= require("method-override")
app.use(methodOverride("method"))
require('dotenv').config();
var flash=require("connect-flash")
app.use(flash())
// +++++++++++++++ Mongoose setup +++++++++++++++++++
var mongoose=require("mongoose")
mongoose.connect("mongodb://localhost/smart-parking",{useNewUrlParser:true,useUnifiedTopology:true,useCreateIndex:true,useFindAndModify:false},function(err){
if(err){
console.log("Cannot connect to database")
}
})
// ++++++++++++++++++ Models +++++++++++++++++++
var slot=require("./models/slot")
var user=require("./models/user")
//++++++++++++ Passport initilize ++++++++++++++++++++
var passport=require("passport")
var localStratagy=require("passport-local")
var expressSessions=require("express-session")
app.use(expressSessions({
secret:process.env.SECRET,
resave: false,
saveUninitialized :false
}))
app.use(passport.initialize())
app.use(passport.session())
//++++++++++++ Passport use ++++++++++++++++++++
passport.use(new localStratagy(user.authenticate()))
passport.serializeUser(user.serializeUser())
passport.deserializeUser(user.deserializeUser())
app.use(function(req, res, next){
res.locals.currentUser = req.user,
res.locals.error=req.flash("error")
res.locals.success= req.flash("success")
next();
});
// +++++++++++++ Routes +++++++++++++++++++++
app.get("/",function(req,res){
res.render("landing")
})
app.get("/dashboard",function(req,res){
res.render('dashboard')
})
// +++++++++++++ user routes +++++++++++++++
var userRoutes=require("./routes/user")
app.use(userRoutes)
var bookingRoutes=require("./routes/booking")
app.use(bookingRoutes)
// +++++++++++ App listening ++++++++++++++++++++
app.listen(3000,"127.0.0.1",function(){
console.log("app is listening")
})
// ++++++++++++++++ Creation of slots ++++++++++++++++++++
// var count=1
// for(var i=0;i<20;i++){
// size=2
// avl=true
// if(count>1 && count <10){
// size=1
// }
// if(count%5==0){
// size=3
// }
// if(count%3==0){
// avl=false
// }
// newslot={
// slotnumber:count,
// slotCapacity:size,
// avaliablity:avl
// }
// count++
// slot.create(newslot,function(err,slot){
// if(err){
// console.log(err)
// }else{
// console.log(slot)
// }
// })
// }
// console.log("Done creation of slots")