Added a classlist page for getting a list with all your classmates.
This commit is contained in:
parent
d63eabbaeb
commit
f34acd3912
1
auth.js
1
auth.js
|
@ -59,6 +59,7 @@ function logout(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function is(req, res, next) {
|
function is(req, res, next) {
|
||||||
|
console.log('Checked auth stats');
|
||||||
var cookies = qs.parse((req.headers.cookie || '').replace(/\s/g, ''), ';', '=');
|
var cookies = qs.parse((req.headers.cookie || '').replace(/\s/g, ''), ';', '=');
|
||||||
if (!cookies.username || !cookies.password) {next(); return;}
|
if (!cookies.username || !cookies.password) {next(); return;}
|
||||||
|
|
||||||
|
|
21
lookup.js
21
lookup.js
|
@ -24,7 +24,7 @@ function get(req, res, next, search) {
|
||||||
res.render('not_found');
|
res.render('not_found');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
req.found = database_entry;
|
req.match = database_entry;
|
||||||
res.render('multiple_found', req);
|
res.render('multiple_found', req);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -34,7 +34,7 @@ function api(req, callback) {
|
||||||
var index = database.collection('index');
|
var index = database.collection('index');
|
||||||
var query = RegExp(req.query.name, 'i');
|
var query = RegExp(req.query.name, 'i');
|
||||||
|
|
||||||
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}]}).toArray(function (err, database_entry) {
|
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}, {group: query}]}).toArray(function (err, database_entry) {
|
||||||
if (err) callback({'error': err});
|
if (err) callback({'error': err});
|
||||||
else {
|
else {
|
||||||
for (entry of database_entry) {entry.url = make_url(req, entry)}
|
for (entry of database_entry) {entry.url = make_url(req, entry)}
|
||||||
|
@ -43,6 +43,21 @@ function api(req, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function list(req, res, next, list) {
|
||||||
|
var index = database.collection('index');
|
||||||
|
var query = RegExp(list, 'i');
|
||||||
|
|
||||||
|
console.log(list);
|
||||||
|
|
||||||
|
index.find({group: list}).toArray(function (err, database_entry) {
|
||||||
|
if (err) {req.error = err; next();}
|
||||||
|
else {
|
||||||
|
req.match = database_entry;
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Function for making a link out of the given database_entry.
|
//Function for making a link out of the given database_entry.
|
||||||
function make_url(req, database_entry) {
|
function make_url(req, database_entry) {
|
||||||
var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + database_entry.type.charAt(0).toUpperCase() + database_entry.type.slice(1) + 'rooster';
|
var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + database_entry.type.charAt(0).toUpperCase() + database_entry.type.slice(1) + 'rooster';
|
||||||
|
@ -82,7 +97,7 @@ function easter(search) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {'get': get, 'api': api};
|
module.exports = {'get': get, 'api': api, 'list': list};
|
||||||
|
|
||||||
//Testing function, if test is passed in the command line will execute a test.
|
//Testing function, if test is passed in the command line will execute a test.
|
||||||
if (process.argv[2] == "test") {
|
if (process.argv[2] == "test") {
|
||||||
|
|
|
@ -23,6 +23,9 @@ html
|
||||||
a(href="/rooster/#{headers.user.id}") Jouw Rooster
|
a(href="/rooster/#{headers.user.id}") Jouw Rooster
|
||||||
li
|
li
|
||||||
a(href=headers.user.url, target="_blank") Andere roostersite
|
a(href=headers.user.url, target="_blank") Andere roostersite
|
||||||
|
li |
|
||||||
|
li
|
||||||
|
a(href="/klassenlijst/#{headers.user.group}") Jouw Klassenlijst
|
||||||
|
|
||||||
ul.right
|
ul.right
|
||||||
li
|
li
|
||||||
|
|
6
resources/jade/list.jade
Normal file
6
resources/jade/list.jade
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
//- list.jade
|
||||||
|
include header
|
||||||
|
|
||||||
|
div=JSON.stringify(match, null, 2)
|
||||||
|
|
||||||
|
include links
|
|
@ -4,7 +4,7 @@ include search
|
||||||
|
|
||||||
.container
|
.container
|
||||||
ul.found
|
ul.found
|
||||||
for entry in found
|
for entry in match
|
||||||
li
|
li
|
||||||
a(href='/rooster/' + entry.name)=entry.name
|
a(href='/rooster/' + entry.name)=entry.name
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
//- search.jade
|
//- search.jade
|
||||||
input.search(type="text", name="searchterm", placeholder="Je naam, id, klassennaam, docentencode, lokaalcode", value=match ? ((match.first_name || match.name) + '\'s rooster') : '')
|
input.search(type="text", name="searchterm", placeholder="Je naam, id, klassennaam, docentencode, lokaalcode", value=path.split('/')[1] == 'klassenlijst' ? 'Leerlingen van ' + match[0].group : match ? ((match.first_name || match.name) + '\'s rooster') : '')
|
||||||
button.search Zoeken
|
button.search Zoeken
|
||||||
|
|
13
web.js
13
web.js
|
@ -22,9 +22,6 @@ app.use('/css', less(__dirname + '/resources/less'));
|
||||||
app.use('/js', express.static(__dirname + '/resources/js'));
|
app.use('/js', express.static(__dirname + '/resources/js'));
|
||||||
app.use('/other', express.static(__dirname + '/resources/other'));
|
app.use('/other', express.static(__dirname + '/resources/other'));
|
||||||
|
|
||||||
//Other things that need to be setup
|
|
||||||
// app.use(body_parser);
|
|
||||||
|
|
||||||
app.get('/', auth.is, function (req, res) {
|
app.get('/', auth.is, function (req, res) {
|
||||||
req.links = config().links;
|
req.links = config().links;
|
||||||
res.render('homepage', req);
|
res.render('homepage', req);
|
||||||
|
@ -54,6 +51,15 @@ app.param('search', function (req, res) {
|
||||||
res.render('schedule', req);
|
res.render('schedule', req);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.param('list', lookup.list);
|
||||||
|
|
||||||
|
app.get('/klassenlijst/:list',[auth.is, function (req, res) {
|
||||||
|
console.log('did the list');
|
||||||
|
req.links = config().links;
|
||||||
|
req.times = config().hour_times;
|
||||||
|
res.render('multiple_found', req);
|
||||||
|
}]);
|
||||||
|
|
||||||
app.listen(config().web_port);
|
app.listen(config().web_port);
|
||||||
plugins();
|
plugins();
|
||||||
|
|
||||||
|
@ -66,5 +72,4 @@ function plugins() {
|
||||||
var app = require(app)(config().web_port + (1 + plugin.indexOf(plugins_directory)));
|
var app = require(app)(config().web_port + (1 + plugin.indexOf(plugins_directory)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue