-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
102 lines (87 loc) · 3.23 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
97
98
99
100
101
102
<?php
require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/init.php';
use Bramus\Router\Router;
use Package\App\Session;
use Package\App\Input;
$app = new Router();
$app->set404(function(){
http_response_code(404);
view('404');
});
//* Landing Page
$app->get('/', function(){
view('landing');
});
//* User Dashboard
$app->get('/home', function(){
if (Session::get('userauth')) {
view('home');
} else {
Session::set('flashmsg', 'Anda harus memverifikasi akun terlebih dahulu !');
redirect(baseurl().'/auth');
}
if (!Session::get('userlogin')) {
Session::set('flashmsg', 'Anda harus login terlebih dahulu !');
redirect(baseurl().'/login');
}
});
$app->get('/auth', function(){
if (Session::get('userlogin') && !Session::get('userauth')) {
view('auth');
return;
}
if (!Session::get('userlogin')) {
Session::set('flashmsg', 'Anda harus login terlebih dahulu !');
}
redirect(baseurl().'/login');
});
$app->get('/login', function(){
if (!Session::get('userlogin')){
view('login');
return;
}
if (Session::get('userauth')) redirect(baseurl().'/home');
else redirect(baseurl().'/auth');
});
$app->get('/register', function(){
if (!Session::get('userlogin')){
view('register');
return;
}
if (Session::get('userauth')) redirect(baseurl().'/home');
else redirect(baseurl().'/auth');
});
$app->get('/m', function(){
view('index', 'mobile');
});
$app->get('/send_verification', (Session::get('userlogin') && !Session::get('userauth')) ? 'Package\Controller\UserController@sendAccountVerification' : function (){
redirect(baseurl().'/login');
});
$app->get('/verification', (Session::get('userlogin') && !Session::get('userauth')) ? 'Package\Controller\UserController@verify' : function (){
if (!Session::get('userlogin')) {
Session::set([
'verificationurl' => requesturl(),
'flashmsg' => 'Anda harus login terlebih dahulu !'
]);
}
redirect(baseurl().'/login');
});
$app->post('/login', 'Package\Controller\UserController@login');
$app->post('/register', 'Package\Controller\UserController@register');
$app->get('/logout', 'Package\Controller\UserController@logout');
$app->get('/users/(\w+)', 'Package\Controller\UserController@showProfile');
$app->post('/users/load', 'Package\Controller\UserController@loadMoreUsers');
$app->post('/users/edit', 'Package\Controller\UserController@edit');
$app->post('/users/changepass', 'Package\Controller\UserController@changePassword');
// TEST BOOK
$app->post('/books/upload', 'Package\Controller\BookController@upload');
$app->post('/books/load', 'Package\Controller\BookController@loadMoreBooks');
$app->get('/books/(\w+)', 'Package\Controller\BookController@showBook');
// TEST API
$app->get('/api/list_all_users', 'Package\Controller\UserController@listAllUsers');
$app->get('/api/list_all_categories', 'Package\Controller\BookController@listAllCategories');
$app->get('/api/list_all_books', 'Package\Controller\BookController@listAllBooks');
$app->post('/api/list_user_collections', 'Package\Controller\BookController@listUserCollections');
$app->run();
?>