-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin-routes.js
132 lines (130 loc) · 3.15 KB
/
admin-routes.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
module.exports = function(app, db)
{
app.get('/admin', function(req, res) {
if(req.cookies.remember)
{
res.render('admin-panel')
}
else
{
res.render('admin-login');
}
})
app.post('/admin', function(req, res) {
if(req.body.password == process.env.dbPass && req.body.username == process.env.dbUser)
{
res.cookie('remember', '1', {maxAge: 3600000*24*30, httpOnly: true, path: '/admin'});
res.redirect('/admin');
}
else
{
res.send("Credentials don't match.");
}
})
app.get('/admin/:listId', function(req, res) {
if(req.params.listId == 'logout')
{
res.clearCookie('remember', {path: '/admin'});
return res.redirect('/admin');
}
if(!req.cookies.remember) return res.redirect('/admin');
routes = ['registrations', 'nlp', 'cogser', 'cloud', 'networking', 'robotics', 'allworkshops', 'codher'];
var registrations = db.collection('registrations');
var payments = db.collection('payments');
var codher = db.collection('codher');
if(routes.indexOf(req.params.listId) == -1)
{
res.send(req.params.listId+' does not exist!');
}
else
{
if(req.params.listId == 'registrations')
{
registrations.find({}, function(err, docs) {
if(err)
{
console.log(err);
errorlog.write(err+'\n');
res.send('Woah! An error occurred while trying to fetch User registrations.');
}
else
{
if(docs)
{
res.render(req.params.listId, {docs: docs});
}
else
{
res.send('Bummer! No user registrations found.');
}
}
});
}
else if(req.params.listId == 'codher')
{
codher.find({}, function(err, docs) {
if(err)
{
console.log(err);
errorlog.write(err+'\n');
res.send('Woah! An error occurred while trying to fetch codHer registrations.');
}
else
{
if(docs)
{
res.render(req.params.listId, {docs: docs});
}
else
{
res.send('Bummer! No codHer registrations found.');
}
}
});
}
else
{
query = {};
query.status = "Credit";
switch(req.params.listId)
{
case 'nlp':
query.offer_title = 'NLP Workshop by IBM';
break;
case 'cogser':
query.offer_title = 'Cognitive Service Workshop By Microsoft';
break;
case 'cloud':
query.offer_title = 'Cloud & IOT Workshop by Oracle';
break;
case 'networking':
query.offer_title = 'CISCO Networking Workshop';
break;
case 'robotics':
query.offer_title = 'Mind-Controlled Robot Workshop';
break;
case 'allworkshops':
break;
default:
res.send('Woah! An error occured while trying to fetch ' + req.params.listId + ' registrations.');
}
payments.find(query, function(err, docs) {
if(err)
{
console.log(err);
errorlog.write(err+'\n');
res.send('Woah! An error occured while trying to fetch ' + req.params.listId + ' registrations.');
}
else
{
if(docs)
{
if(query.offer_title == undefined) query.offer_title = 'All Workshops';
res.render('workshop', {docs: docs, workshop: query.offer_title});
}
}
});
}
}
})
}