-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
143 lines (105 loc) · 2.86 KB
/
app.js
File metadata and controls
143 lines (105 loc) · 2.86 KB
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
const express= require('express')
const mongoose =require('mongoose')
const ejs =require('ejs')
const bodyParser = require("body-parser");
const User = require('./models/user')
const passport = require('passport')
const LocalStrategy = require('passport-local')
const indexRoute = require('./routes/index')
mongoose.connect("mongodb+srv://admin-hospital:hospital123@cluster0.5mlfk.mongodb.net/Api?retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true
})
const app = express()
app.set('view engine', 'ejs')
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static("public"));
app.use(require('express-session')({
secret: 'this is my secret',
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
passport.use(new LocalStrategy(User.authenticate()))
passport.serializeUser(User.serializeUser())
passport.deserializeUser(User.deserializeUser())
app.use((req, res, next) => {
res.locals.currentUser = req.user
next();
})
app.use(indexRoute)
const companySchema = mongoose.Schema({
Address: String,
CompanyType:String,
ContractType: String,
Crop: String,
Name: String,
Price: String,
Cin: String,
email: String,
contactNo: String,
img:String
});
const yojnaSchema = mongoose.Schema({
Title:String,
Description:String,
Image:String,
link:String
});
const blogSchema = mongoose.Schema({
Technology: String,
Use: String,
image: String,
});
const Yojna_info = mongoose.model("Yojna_info", yojnaSchema);
const Blog_info = mongoose.model('Blog_info', blogSchema)
const Company_info = mongoose.model('Company_info', companySchema)
app.get('/', (req, res) => {
Blog_info.find((err, blog) => {
if (err)
console.log(err)
else
res.render('blog',{blog:blog})
})
})
app.get('/schemes', (req, res) => {
Yojna_info.find((err, yojna) => {
if (err)
console.log(err)
else
res.render('scheme',{yojna:yojna})
})
})
app.get('/company', (req, res) => {
Company_info.find((err, company) => {
if (err)
console.log(err)
else
res.render('company',{company:company})
})
})
app.post('/schemes', isLoggedIn,function (req, res) {
var newblog = {
Technology: req.body.Technology,
Use: req.body.Use,
image: req.body.image
}
Blog_info.create(newblog, function (err, newlyCreated) {
if (err)
console.log(err)
else
res.redirect('/')
})
})
app.get('/schemes/new',isLoggedIn, function (req, res) {
res.render('new')
})
function isLoggedIn(req, res, next) {
if (req.isAuthenticated())
return next()
res.redirect('/login')
}
app.listen(3000, () => console.log('server started on port 3000'))