-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
141 lines (105 loc) · 3.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
const lessonPlans = require('./data/lessonplans.json')
const planets = require('./data/planets.json')
const dictionary = require('./data/dictionary.json')
const express = require("express");
const bodyParser = require("body-parser")
const mongoose = require("mongoose")
const ejs = require("ejs")
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
let users = [
{name: "Simon Nguyen", password: "ChatGPT", progress: [0, 0, 0, 0, 0]},
]
let loggedIn = false
let user
app.get("/", function(req, res) {
if (loggedIn === true) {
res.render("app", {user: user})
} else {
res.render("index")
}
})
app.post("/", function(req, res) {
const username = req.body.username;
const password = req.body.password;
console.log(username, password)
users.forEach(function(login) {
if (login.name === username && login.password === password) {
user = login
loggedIn = true
res.render("app", {user: user})
}
})
})
app.get("/app", function(req, res) {
res.render("app")
})
const lesson1 = lessonPlans.lessons[0]
console.log(lesson1)
app.get("/lesson1", function(req, res) {
res.render("lesson", {lesson1: lesson1, index: 0})
})
const lesson2 = lessonPlans.lessons[1]
console.log(lesson2)
app.get("/lesson2", function(req, res) {
res.render("lesson", {lesson1: lesson2, index: 1})
})
const lesson3 = lessonPlans.lessons[2]
console.log(lesson3)
app.get("/lesson3", function(req, res) {
res.render("lesson", {lesson1: lesson3, index: 2})
})
const lesson4 = lessonPlans.lessons[3]
console.log(lesson4)
app.get("/lesson4", function(req, res) {
res.render("lesson", {lesson1: lesson4, index: 3})
})
const lesson5 = lessonPlans.lessons[4]
console.log(lesson5)
app.get("/lesson5", function(req, res) {
res.render("lesson", {lesson1: lesson5, index: 4})
})
app.get("/dictionary", function(req, res) {
res.render("dictionary", {dictionary: dictionary})
})
const Mercury = planets.planets[0]
app.get("/Mercury", function(req, res) {
res.render("planets", {planet: Mercury});
});
const Venus = planets.planets[1]
app.get("/Venus", function(req, res) {
res.render("planets", {planet: Venus});
});
const Earth = planets.planets[2]
app.get("/Earth", function(req, res) {
res.render("planets", {planet: Earth});
});
const Mars = planets.planets[3]
app.get("/Mars", function(req, res) {
res.render("planets", {planet: Mars});
});
const Jupiter = planets.planets[4]
app.get("/Jupiter", function(req, res) {
res.render("planets", {planet: Jupiter});
});
const Saturn = planets.planets[5]
app.get("/Saturn", function(req, res) {
res.render("planets", {planet: Saturn});
});
const Uranus = planets.planets[6]
app.get("/Uranus", function(req, res) {
res.render("planets", {planet: Uranus});
});
const Neptune = planets.planets[7]
app.get("/Neptune", function(req, res) {
res.render("planets", {planet: Neptune});
});
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port, function() {
console.log("Server started successfully");
});