-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouter.js
31 lines (27 loc) · 982 Bytes
/
router.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
var auth = require("./api/auth");
var pages = ["account", "noauth", "writeups", "about", "updates", "feedback", "login", "logout", "passreset", "teamnamelookup", "contact", "learn", "faq", "teachers", "register", "sponsors", "scoreboard", "forgot"];
var auth_pages = ["problems", "exec", "irc", "compete", "shell"];
for(var i=0; i<auth_pages.length; i++) {
pages.push(auth_pages[i]);
}
module.exports = function(app) {
for(var i=0; i<pages.length; i++) {
(function(i) {
app.get("/" + pages[i], function(req, res) {
// console.dir(auth.is_authorized(req));
if (auth_pages.indexOf(pages[i]) > -1) {
if (auth.is_authorized(req).success !== 1) {
res.sendfile("pages/noauth.html", { root: __dirname });
return;
}
}
res.sendfile("pages" + req.url + ".html", { root: __dirname });
});
})(i);
}
app.get("/forgot/:code", function(req, res) {
res.render("verify", {
code: req.params.code
});
});
};