-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
180 lines (132 loc) · 3.13 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//Ejs TEmplate adding
const express=require('express')
const fs=require('fs')
const path=require('path')
const uuid=require('uuid')
const bcry=require('bcryptjs')
//app.use(express.json())
const db=require('./MONGO_D/database.js');
const app=express();
app.use(express.static('styles'));
app.use(express.urlencoded({extended:true}))
app.set('views',path.join(__dirname,'views'));
app.set('view engine','ejs');
app.get('/',function(req,res)
{
res.render('index');
})
app.get('/userdetail',function(req,res)
{
const filepath=path.join(__dirname,'views','members.json')
const filedata=fs.readFileSync(filepath)
const memberdata=JSON.parse(filedata)
res.render('/userdetail.ejs',{ members:memberdata})
})
app.get('/Home',function(req,res)
{
res.render('index')
})
app.get('/data',function(req,res){
const filepath=path.join(__dirname,'views','members.json')
const filedata=fs.readFileSync(filepath)
const memberdata=JSON.parse(filedata)
res.send(memberdata);
})
app.get('/form',function(req,res)
{
res.render('tt')
})
app.get('/login',function(req,res)
{
res.render('login')
})
app.get('/admin',function(req,res)
{
res.send("<h2>Welcome User</h2>")
})
//Signup functionality
app.post('/signup',async function(req,res)
{
const userdata=req.body;
const mail=userdata.mail;
const password=userdata.password;
const alreadyuser=await db.getDb().collection('users').findOne({email:mail})
if(alreadyuser)
{
res.redirect("/login")
}
else{
const passwordd=await bcry.hash(password,12)
const users={
email:mail,
passkey:passwordd
};
await db.getDb().collection('users').insertOne(users);
res.redirect('/login')
//USe it to Successful Page or Login Page
}
})
//Login Functionality
app.post('/login',async function(req,res)
{
const userdata=req.body;
const mail=userdata.mail;
const epassword=userdata.epassword;
const existdata=await db.getDb().collection('users').findOne({email:mail})
if(!existdata)
{
res.redirect('/form')
}
const passkeycheck=await bcry.compare(epassword,existdata.passkey)
if(!passkeycheck)
{
res.redirect('/form')
}
else{
res.redirect('/admin')
}
})
app.get('/User/:id',function(req,res)
{
const memberId=req.params.id;
const filepath=path.join(__dirname,'views','members.json')
const filedata=fs.readFileSync(filepath)
const memberdata=JSON.parse(filedata)
for(const member of memberdata)
{
if(member.id==memberId)
{
return res.render('userdetail',{member:member})
}
}
})
app.get('/faculty',function(req,res)
{
res.render('faculty')
})
app.get('/Nature',function(req,res)
{
res.render('nature')
})
app.get('/devs',function(req,res)
{
res.render('devs')
})
app.get('/tech',function(req,res)
{
res.render('tech')
})
app.get('/about',function(req,res)
{
res.render('about')
})
//Not found
app.use(function(req,res)
{
res.send("<h1>Sorry,Page is not found</h1>");
})
module.exports=app;
db.connectToDatabase().then(function () {
app.listen(80);
});
app.listen(7000)