-
Notifications
You must be signed in to change notification settings - Fork 32
/
app.js
181 lines (156 loc) · 4.24 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
181
const express = require ('express');
var bodyParser = require ('body-parser');
const mongoose = require ('mongoose');
const fs = require('fs');
var app = express ();
var port = 3000;
const bcrypt = require('bcryptjs')
var length;
app.use (bodyParser.json ());
app.use (bodyParser.urlencoded ({extended: true}));
app.use(express.static(__dirname + '/css'));
app.use(express.static(__dirname + '/images'));
app.set ('view engine', 'ejs');
mongoose.Promise = global.Promise;
mongoose.connect ('mongodb://localhost:27017/js-basics', {
useNewUrlParser: true,
useUnifiedTopology: true
});
var db = mongoose.connection;
db.on ('error', console.log.bind (console, 'Connection error'));
db.once ('open', function (callback) {
console.log ('Connection Succeded');
});
var nameSchema = new mongoose.Schema ({
firstName: String,
branch: String,
sem: Number,
sec: String,
email: String,
num: Number,
git: String,
assginee : String,
status : String
});
var AdmSchema = new mongoose.Schema ({
firstName: String,
lastname: String,
org: String,
email: String,
phno: Number,
pass: String,
github : String,
linkedin : String
});
var StuSchema = new mongoose.Schema ({
firstName: String,
lastname: String,
branch: String,
sem: Number,
sec: String,
email: String,
phno: Number,
pass: String,
github : String,
linkedin : String
});
var User = mongoose.model ('User', nameSchema);
var User_Adm = mongoose.model ('User_Adm', AdmSchema);
var User_Stu = mongoose.model ('User_Stu', StuSchema);
//mongodb search
var findit=User.find({});
app.set('views','./Views');
app.use(express.static('views'));
//go to http://localhost:3000/details to get the required data
app.get('/details',(req, res) => {
findit.exec(function(err,data){
if(err) throw err;
res.render('fetch_details',{members : data});
console.log(data);
});
}).listen(3000);
console.log('running on 3000');
app.post ('/sign_up_adm', (req, res) => {
const newUser = new User_Adm ({
firstName: req.body.firstname,
lastname: req.body.lastname,
org: req.body.org,
email: req.body.email,
phno: req.body.phno,
pass: req.body.pass,
github : req.body.github,
linkedin : req.body.linkedin
})
// Hashing password
bcrypt.genSalt(8,(err,salt) => {
bcrypt.hash(req.body.pass , salt , (err,hash) => {
if(err) throw err
newUser.pass = hash
newUser.save (function (err, doc) {
if (err) res.json (err);
else {
console.log (doc);
res.redirect('/');
}
});
});
});
});
app.post ('/sign_up_stu', (req, res) => {
// password and confirm password matched
if(req.body.pass != req.body.conpass) res.json ('Password do not match ')
const newUser = new User_Stu ({
firstName: req.body.firstname,
lastname: req.body.lastname,
branch: req.body.branch,
sem: req.body.sem,
sec: req.body.sec,
clg: req.body.clg,
email: req.body.email,
phno: req.body.phno,
pass : req.body.pass,
github : req.body.github,
linkedin : req.body.linkedin
})
// Hashing password
bcrypt.genSalt(8,(err,salt) => {
bcrypt.hash(req.body.pass , salt , (err,hash) => {
if(err) throw err
newUser.pass = hash
newUser.save (function (err, doc) {
if (err) res.json (err);
else {
console.log (doc);
res. redirect('/');
}
});
})
})
});
app.post ('/insertData', (req, res) => {
new User ({
firstName: req.body.name,
branch: req.body.branch,
sem: req.body.sem,
sec: req.body.sec,
email: req.body.email,
num: req.body.num,
git: req.body.git,
assginee : "",
status : ""
}).save (function (err, doc) {
if (err) res.json (err);
else {
console.log (doc);
res.send ('Successfully Inserted!');
}
});
});
app.get('/', (req, res) => res.render ('index'));
app.get('/student', (req, res) => res.render ('scrum1'));
app.get('/fetch_details', (req, res) => res.render('fetch_details'));
app.get('/regadm', (req, res) => res.render('registeradm'));
app.get('/teamsPage', (req, res) => res.render('teams'));
/*app.listen (port, () => {
console.log ('server listening on port ' + port);
});*/