-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
82 lines (62 loc) · 1.91 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
<?php
use Middlewares\LoginCheckMiddleware;
use Middlewares\CSRFProtectionMiddleware;
use Models\UserModel;
use Models\NoticeModel;
session_start();
$request = preg_replace("|/*(.+?)/*$|", "\\1", $_SERVER['REQUEST_URI']);
$uri = explode('/', $request);
require_once "lib/Database.php";
require_once "models/UserModel.php";
require_once "models/NoticeModel.php";
require_once "controllers/UserController.php";
require_once "controllers/NoticeController.php";
require_once "middlewares/LoginCheck.php";
require_once "middlewares/CSRFProtection.php";
$db = new Database();
$loginCheck = new LoginCheckMiddleware();
$csrfCheck = new CSRFProtectionMiddleware();
$userModel = new UserModel($db);
$noticeModel = new NoticeModel($db);
$Controllers = [
'user' => new Controllers\UserController($userModel, $loginCheck, $csrfCheck),
'notice' => new Controllers\NoticeController($userModel, $noticeModel, $loginCheck, $csrfCheck)
];
switch ($uri[0]) {
case 'login':
$Controllers['user']->login();
break;
case 'register':
$Controllers['user']->register();
break;
case 'change-password':
$Controllers['user']->resetPassword();
break;
case 'my':
$Controllers['user']->my();
break;
case 'logout':
$Controllers['user']->logout();
break;
case 'notices':
if (sizeof($uri) == 1) {
$Controllers['notice']->getAll();
} else {
$action = $uri[1];
switch ($action) {
case 'create':
$Controllers['notice']->create();
break;
case 'delete':
$Controllers['notice']->delete();
break;
default:
header('Location: /notice');
die;
}
}
break;
default:
header('Location: /login');
die;
}