-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
124 lines (104 loc) · 2.81 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
const dotenv = require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const session = require("express-session")
const Sequelize = require('sequelize');
const sequelize = new Sequelize(process.env.DB_NAME,process.env.DB_USER,
process.env.DB_PSWD,{ host: process.env.DB_HOST,
dialect: 'mysql' })
const db_tools = require('./Database/database_tools')
let db_tool = new db_tools(sequelize)
const app = express();
const port = process.env.PORT || 8000;
const views = `${__dirname}/views/`;
//middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(cookieParser());
app.use(session({
key: 'user_sid',
secret: '323123123',
resave: true,
saveUninitialized: false,
cookie: {
expires: 600000
}
}));
app.get("/", (req,res)=>{
res.sendFile(views + 'login.html');
});
app.get("/about",(req,res) => {
res.sendFile(views + 'about.html');
});
app.get("/contact", (req,res) => {
res.sendFile(views + 'contact.html');
});
app.get("/login", (req,res) => {
res.sendFile(views + 'login.html');
});
app.get("/signup", (req,res) => {
res.sendFile(views + 'signup.html');
});
// TEST GET REQUEST to return true
app.get("/professortest", (req,res) => {
res.send( { isprofessor: true });
});
app.post("/signup", (req,res) => {
db_tool.users.create_user(
req.body.firstname,
req.body.lastname,
req.body.inputEmail,
req.body.password
);
// res.redirect("/");
res.send({ signup: true });
});
app.post("/login", (req, res) => {
console.log(req.body);
db_tool.users.verify_user(req.body.inputEmail, req.body.password)
.then((result) => {
res.send({ verified: result });
})
.catch((err) => {
console.log(err);
});
});
app.post("/get_events", (req, res) => {
db_tool.events.get_events(req.body.userid)
.then((result) => {
res.send(result);
})
.catch((err) => {
console.log(err);
});
});
app.post("/add_event", (req, res) => {
db_tool.events.add_event(
req.body.classid,
req.body.eventtype,
req.body.eventtitle,
req.body.eventdescription,
req.body.eventdate
);
});
app.post("/update_event", (req, res) => {
db_tool.events.update_event(
req.body.eventid,
req.body.eventtype,
req.body.eventtitle,
req.body.eventdescription,
req.body.eventdate
);
});
app.post("/delete_event", (req, res) => {
db_tool.events.delete_event(
req.body.eventid
);
});
app.get("*", (req,res) => {
res.sendFile(views + '404.html');
});
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
});