Skip to content

Commit 8091fbc

Browse files
committed
Add middleware check for admin routes
1 parent af31e1b commit 8091fbc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ include/config.php
44
nbproject/
55
lang/French
66
.htaccess
7+
vendor
8+
composer.lock

include/routes.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
88
*/
99

10+
/**
11+
* middleware to check if user is admin, if it's not redirect to homepage.
12+
*/
13+
$isAdmin = function() use ($feather) {
14+
if($feather->user->g_id != $feather->forum_env['FEATHER_ADMIN']) {
15+
redirect(get_link('/'), __('No permission'));
16+
}
17+
};
1018

1119
// Index
1220
$feather->get('/', '\controller\index:display');
@@ -88,7 +96,7 @@
8896
});
8997

9098
// Admin routes
91-
$feather->group('/admin', function() use ($feather) {
99+
$feather->group('/admin', $isAdmin, function() use ($feather) {
92100

93101
// Admin index
94102
$feather->get('(/action/:action)(/)', '\controller\admin\index:display');
@@ -163,4 +171,4 @@
163171
// 404 not found
164172
$feather->notFound(function () {
165173
message(__('Bad request'), '404');
166-
});
174+
});

0 commit comments

Comments
 (0)