-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
166 lines (146 loc) · 4.15 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
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mysql = require("mysql");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
app.use(express.static("public"));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({
extended: true
}));
let usn;
//Declaratory stuff ends......
let con = mysql.createConnection({
host: "localhost",
user: "root",
password: "Human_17!",
database: "Xprt_Findr"
});
con.connect(function(err){
if(err)
{
throw err;
}
else
{
console.log("Connected");
}
});
con.query("use Xprt_Findr;", function(err, res){
if(err)
{
throw err;
}
else
{
console.log("Connected to database");
}
});
app.get('/', (req,res) => {
res.render("home");
});
app.get('/register', (req,res) => {
res.render("register");
});
app.post('/reg', (req,response) => {
const username = req.body.username;
const password = req.body.password;
const college = req.body.college;
const branch= req.body.branch;
const year = req.body.year;
const email = req.body.email;
const phonenumber = req.body.phonenumber;
const name = req.body.name;
const semester = req.body.semester;
const degree = req.body.degree
con.query(`insert into authentication values("${username}", "${password}", "${college}", "${branch}", "${year}", "${email}", "${phonenumber}", "${name}", NULL, "${semester}", "${degree}");`, function(err, res){
if(err){
throw err;
}
else{
con.query(`create table ${username}_questable(username varchar(25),queshead varchar(255), quesbod varchar(255), quesdate datetime, status varchar(15), meeting_rating int, role varchar(15))`, (error, resp) => {
if(error){
throw error;
}
});
response.render("login");
}
});
});
app.get('/login', (req,res) => {
res.render("login");
});
app.post('/auth', (req,response) => {
const username = req.body.username;
const password = req.body.password;
con.query(`select* from authentication where username="${username}" and password="${password}";`, (err, res) => {
if(err){
throw err;
}
else{
if(res.length!==0){
console.log(res);
usn = username;
response.redirect("/yourprofile");
}
else{
response.send("Wrong username or password");
}
}
});
});
app.get('/yourprofile', (req,response) => {
let questaught;
con.query(`select* from ${usn}_questable where username="${usn}" and role="taught";`, (err, res) => {
if(err){
throw err;
}
else{
questaught = res;
}
});
con.query(`select* from ${usn}_questable where username="${usn}" and role="learnt";`, (err, res) => {
if(err){
throw err;
}
else{
response.render("yourprofile",{queslearnt:res, questaught:questaught});
}
});
});
app.get('/teach', (req,response) => {
con.query(`select* from questable where status="active";`, (err, res) => {
if(err){
throw err;
}
else{
response.render("teach", {queslist: res});
}
});
});
app.get('/learn', (req,res) => {
res.render("learn");
});
app.post('/post', (req,response) => {
const queshead = req.body.queshead;
const quesbod = req.body.quesbod;
let datetime;
con.query(`insert into questable values("${usn}", "${queshead}", "${quesbod}", NULL, "active");`, (err, res) => {
if(err){
throw err;
}
else{
con.query(`insert into ${usn}_questable values("${usn}", "${queshead}", "${quesbod}", NULL, "active", NULL, "learnt");`, (error, resp) => {
if(err){
throw err;
}
else{
response.render("learn");
}
});
}
});
});