-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
120 lines (93 loc) · 3.08 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
const express = require('express');
const bodyParser=require('body-parser');
const cors=require('cors');
const ejs = require("ejs");
const mongoose=require('mongoose');
const path = require('path');
const Mentor = require('./server/models/mentor')
const Student = require('./server/models/student')
const Manager = require('./server/models/manager')
// const Test = require('./server')
const app = express();
require('dotenv').config()
const PORT = process.env.PORT || 5000;
app.use(express.json())
app.use(cors());
app.use(bodyParser.urlencoded({extended: true}));
app.set("views", path.join(__dirname,"views", "components"));
app.set("view engine", "ejs");
app.use(express.static(path.join(__dirname,'views/public')));
const CONNECTION_URL = process.env.MONGO_URI;
mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true})
.then(()=> console.log(`Mongoose connected successfully!`))
.catch((error) => console.log(error.message));
app.get('/', (req, res)=> {
// var newMentee = new Student({
// username: "mentee",
// password: "mentee",
// mentor: ""
// })
// newMentee.save();
res.render('index');
})
app.post('/',(req,res)=> {
var username = req.body.username;
var password = req.body.password;
var input= req.body.input;
switch (input) {
case "mentor":
Mentor.findOne({username,password}, (err, user)=>{
if(err){
console.log(err);
}
if(!user){
console.log("user not found");
}
else{
console.log(user);
res.render("mentor");
}
})
break;
case "mentee":
Student.findOne({username,password}, (err, user)=>{
if(err){
console.log(err);
}
if(!user){
console.log("user not found");
}
else{
console.log(user);
res.render("mentee", {mentor: user.mentor});
}
})
break;
case "manager":
Manager.findOne({username,password}, (err, user)=>{
if(err){
console.log(err);
}
if(!user){
console.log("user not found");
}
else{
console.log(user);
res.render("manager");
}
})
break;
}
})
var MentorRoute = require('./server/routes/mentor_route');
app.use('/mentor',MentorRoute);
var MenteeRoute = require('./server/routes/mentee_route');
app.use('/mentee',MenteeRoute);
var ManagerRoute = require('./server/routes/manager_route');
app.use('/manager',ManagerRoute);
app.get('/mentee', (req,res)=> {
res.send('/mentee');
})
app.listen(PORT, () => {
console.log(`Server is running on port: ${PORT}`);
});