-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
90 lines (73 loc) · 2.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
const express = require('express');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
const PORT = 3000;
dotenv.config();
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + "/client"));
mongoose.pluralize(null);
mongoose.set('strictQuery', false);
mongoose.connect(process.env.URI);
const loginSchema = {
username: String,
password: String,
email: String
};
const studentSchema = {
name: String,
last_name: String,
class: String,
optone: String,
opttwo: String,
optthree: String
};
const Login = mongoose.model('Login', loginSchema);
const Student = mongoose.model('Students', studentSchema);
app.get("/", (req, res) => {
res.sendFile(__dirname + "/client/index.html");
});
app.get("/register", (req, res) => {
res.sendFile(__dirname + "/client/register.html");
});
app.get("/main", (req, res) => {
res.sendFile(__dirname + "/client/main.html");
});
app.post("/register", async (req, res) => {
let newLogin = new Login({
username: req.body.username,
password: req.body.password,
email: req.body.email
});
let loginUser = newLogin.get("username");
let loginEmail = newLogin.get("email");
let userTest = await Login.find({username: loginUser});
let emailTest = await Login.find({email: loginEmail});
if (userTest.length == 0 && emailTest.length == 0) {
newLogin.save();
}
else if (userTest.length != 0 || emailTest.length != 0) {
res.redirect("/");
}
});
app.post("/", async (req, res) => {
let username = req.body.username;
let password = req.body.password;
let userTest = await Login.find({username: username});
let passTest = await Login.find({password: password});
if (passTest.length != 0) {
if (userTest.length != 0 && passTest[0].get("password") == password) {
res.redirect("/main");
}
else {
res.send('gay');
}
}
else {
res.redirect('/register');
}
});
app.listen(PORT, () => {
console.log(`listening on port ${PORT}`);
});