-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
296 lines (263 loc) · 8.59 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
const bodyParser = require("body-parser");
const { application, Router } = require("express");
const express = require("express");
const passwordHash = require("password-hash");
const ejs = require('ejs');
const app = express();
const port = 3000;
const { initializeApp, cert } = require("firebase-admin/app");
const { getFirestore } = require("firebase-admin/firestore");
var serviceAccount = require("./key1.json");
initializeApp({
credential: cert(serviceAccount),
});
const db = getFirestore();
app.set("view engine", "ejs");
app.set('views', './views')
app.use(bodyParser.urlencoded({
extended: true
}));
function hashPassword(password) {
return passwordHash.generate(password);
}
app.get("/", (req, res) => {
res.render("index");
});
app.get('/up', (req, res) => { res.render("signup", { data: " " }); });
app.get('/in', (req, res) => { res.render("signin", { data1: " " }); });
app.get('/dashboard', (req, res) => { res.render("studentregister"); });
app.get("/signin", (req, res) => { res.render("signin"); });
app.get("/signup", (req, res) => {
res.render("signup");
});
app.get("/signupsubmit", (req, res) => {
const full_name = req.query.full_name;
const last_name = req.query.last_name;
const email = req.query.email;
const password = req.query.password;
const Status = req.query.status;
// Check if the email address doesn't end with "@vishnu.edu.in"
if (Status === "student" && !email.endsWith("@vishnu.edu.in")) {
res.render("signup", { data: "Student email address must belong to the @vishnu.edu.in domain." });
return;
}
// The email address is unique and meets the domain requirement, proceed with registration
const modifiedEmail = email; // No need to modify the email if it's from the allowed domain
// Hash the password (using password-hash)
const hashedPassword = hashPassword(password);
if (Status === "teacher") {
// Add the teacher to the database with the hashed password
var faculty = db.collection("allusers");
faculty.add({
name: full_name + last_name,
email: modifiedEmail,
password: hashedPassword,
role: Status,
})
.then(() => {
res.render("hodashboard");
});
} else if (Status === "student") {
// Add the student to the database with the hashed password
var student = db.collection("allusers");
student.add({
name: full_name + last_name,
email: modifiedEmail,
password: hashedPassword,
role: Status,
})
.then(() => {
res.render("studashboard");
});
} else {
res.send("Signup failed");
}
});
app.get("/signinsubmit", (req, res) => {
const email = req.query.email;
const password = req.query.password;
const Passcode = req.query.code;
// Query the database to find the user by email
db.collection("allusers")
.where("email", "==", email)
.get()
.then((docs) => {
if (!docs.empty) {
const user = docs.docs[0].data();
const storedHashedPassword = user.password;
// Verify the password using password-hash
if (passwordHash.verify(password, storedHashedPassword)) {
// Password is correct
if (Passcode == "student" && user.role === "student") {
// User is a student
// Query for student data and render the student dashboard
// Example: You can add your code to fetch student data here
res.render("studashboard", { thestud: user });
} else if (Passcode == "teacher" && user.role === "teacher") {
// User is a teacher
// Query for teacher data and render the teacher dashboard
// Example: You can add your code to fetch teacher data here
res.render("hodashboard", { userData: user });
} else {
res.render("signin", { data1: "Invalid user role" });
}
} else {
res.render('signin', { data1: "Invalid password" });
}
} else {
res.render('signin', { data1: "User not found" });
}
})
.catch((error) => {
console.error("Error querying the database:", error);
res.send("An error occurred");
});
});
app.get('/studentregistr', (req, res) => {
const full_name = req.query.First_Name;
const last_name = req.query.Last_Name;
const regId = req.query.RegId;
const email = req.query.Email_Id;
const semno = req.query.Semno;
const branchname = req.query.branch;
const Update = req.query.update
const result = db.collection("student register").add({
name: full_name + " " + last_name,
email: email,
registerNumber: regId,
CurrentSemNumber: semno,
Branch: branchname,
update: Update,
}).then(() => {
res.send("Registered sucessfully");
});
});
app.get('/hodashboard', (req, res) => {
res.render("teacherregister");
});
app.get('/postingcse', (req, res) => {
res.render("postmarks");
});
app.get('/postingece', (req, res) => {
res.render("postmarks");
});
app.get('/postingcivil', (req, res) => {
res.render("postmarks");
});
app.get('/postmark', (req, res) => {
const branchcse = "CSE";
const branchece = "ECE";
const branchcil = "CIVIL";
const studentname = req.query.stud_name;
const registerno = req.query.rol_no;
const bran = req.query.branch;
const semNo = req.query.semnum;
const Cgpa = req.query.cgpa;
const Attend = req.query.attendence;
const remark = req.query.remarks;
const markinfo = db.collection("marksentered").add({
Studentname: studentname,
RegistrationNumber: registerno,
CurrentSemisterNum: semNo,
BranchName: bran,
CGPA: Cgpa,
attendence: Attend,
Remarks: remark,
});
var info = db.collection('student register').where("Branch", "==", branchcse).where("registerNumber", "==", registerno).get().then((querySnapshot) => {
querySnapshot.forEach(function(document) {
document.ref.update({
'update': 'yes',
});
})
});
var info = db.collection('student register').where("Branch", "==", branchece).where("registerNumber", "==", registerno).get().then((querySnapshot) => {
querySnapshot.forEach(function(document) {
document.ref.update({
'update': 'yes',
});
})
});
var info = db.collection('student register').where("Branch", "==", branchcil).where("registerNumber", "==", registerno).get().then((querySnapshot) => {
querySnapshot.forEach(function(document) {
document.ref.update({
'update': 'yes',
});
})
}).then(() => {
res.send("Marks posted sucessfully");
})
});
app.get('/studduecse', (req, res) => {
var datas = [];
db.collection('student register').where("Branch", "==", "CSE").where("update", "==", "no").get()
.then((docs) => {
docs.forEach((doc) => {
datas.push(doc.data());
});
}).then(() => {
res.render("postcse", { thestudent: datas });
console.log(datas);
})
});
app.get('/ece', (req, res) => {
var datak = [];
db.collection('student register').where("Branch", "==", "ECE").where("update", "==", "no").get()
.then((docs) => {
docs.forEach((doc) => {
datak.push(doc.data());
});
})
.then(() => {
res.render("postcse", { thestudent: datak });
console.log(datak);
})
});
app.get('/civil', (req, res) => {
var datav = [];
db.collection('student register').where("Branch", "==", "CIVIL").where("update", "==", "no").get()
.then((docs) => {
docs.forEach((doc) => {
datav.push(doc.data());
});
})
.then(() => {
res.render("postcse", { thestudent: datav });
console.log(datav);
})
});
app.get('/teacherregistr', (req, res) => {
const full_name = req.query.First_Name;
const last_name = req.query.Last_Name;
const regId = req.query.RegId;
const email = req.query.Email_Id;
const Branc = req.query.branch;
const techerinfo = db.collection("teacherregister");
techerinfo.add({
name: full_name + last_name,
email: email,
Branch: Branc,
}).then(() => {
res.send("Registered sucessfully");
});
});
app.get('/markget', (req, res) => {
res.render("ask");
});
app.get('/hark', (req, res) => {
const roll = req.query.Regid;
const bran = req.query.branchh;
var datax = [];
db.collection("student register").where('registerNumber', '==', roll).where('Branch', '==', bran).get().then(async (docs) => {
var refer = await db.collection("marksentered").where('RegistrationNumber', '==', roll).where('BranchName', '==', bran).get();
refer.forEach((doc) => {
datax.push(doc.data());
});
}).then(() => {
res.render("marks", { marks: datax });
console.log(datax);
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});