-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
96 lines (83 loc) · 2.61 KB
/
index.php
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
<?php $debug = false;
/**
* CONTROLLER
*/
// Third party libraries
require("vendor/autoload.php");
// Debugging functionality
if ($debug) {
error_reporting(E_ALL);
}
// Main model
require("model/model.php");
// Page models
require("model/auth.php");
require("model/assignment.php");
require("model/questionnaire.php");
require("model/megaupload.php");
// Reroute HTTP traffic to HTTPS
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
if(!headers_sent()) {
header("Status: 301 Moved Permanently");
header(sprintf(
'Location: https://%s%s',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
));
exit();
}
}
// Initiate router
$router = new \Bramus\Router\Router();
/*
* Page routers
*
* Provides routes to the individual parts of the system
*/
/**
* Authentication
*
* Provides routes for logging on and off, as well as registering a new account.
*/
// Authentication check: check if each request has a user ID set in session.
$router->before('GET|POST', '/assignment/.*', "auth@auth_check");
$router->before('GET|POST', '/assignment/', "auth@auth_check");
$router->before('GET|POST', '/questionnaire/.*', "auth@auth_check");
$router->before('GET|POST', '/questionnaire/', "auth@auth_check");
/**
* Auth
*
* Handles authentication and registration of students.
*/
$router->get("/", "auth@login");
$router->mount("/login", function() use ($router){
$router->get("/", "auth@loginpage");
$router->post("/", "auth@performLogin");
});
$router->get('/logout/', "auth@performLogout");
$router->get("/register/", "auth@startRegistration");
$router->post("/register/", "auth@finishRegistration");
/**
* Assignments
*
* Provides access to assignments and enables submission.
*/
$router->mount('/assignment', function() use ($router){
$router->get("/", "assignment@overview");
$router->get("/(.*)/", "assignment@individualAssignment");
$router->post("/(.*)/submit", "assignment@submitAssignment");
});
/**
* Questionnaires
*
* Provides access to questionnaires.
*/
$router->get("/questionnaire/", "questionnaire@overview");
/**
* Megaupload
*
* Provides a POST interface for batch uploading of missing assignment.
* For developer use only.
*/
$router->post('/megaupload/', "megaupload@upload");
$router->run();