Skip to content

Commit 4ae8a45

Browse files
committed
Clean up routes and middleware checking
1 parent 99a6712 commit 4ae8a45

File tree

16 files changed

+322
-102
lines changed

16 files changed

+322
-102
lines changed

app/Http/Controllers/API/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UserController extends Controller
1919
*/
2020
public function __construct()
2121
{
22-
$this->middleware('api');
22+
//
2323
}
2424

2525
public function getAllUsers(Request $request)

app/Http/Controllers/Admin/AccountsController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ class AccountsController extends Controller
2020
*/
2121
public function __construct()
2222
{
23-
24-
// All routes in this controller are protected by the authentication middleware.
25-
$this->middleware('auth');
26-
$this->middleware('admin');
27-
23+
//
2824
}
2925

3026
public function getIndex(Request $request)

app/Http/Controllers/Admin/BaseController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ class BaseController extends Controller
1515
*/
1616
public function __construct()
1717
{
18-
19-
// All routes in this controller are protected by the authentication middleware.
20-
$this->middleware('auth');
21-
$this->middleware('admin');
22-
18+
//
2319
}
2420

2521
public function getIndex(Request $request)

app/Http/Controllers/Admin/ServersController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ class ServersController extends Controller
2323
*/
2424
public function __construct()
2525
{
26-
27-
// All routes in this controller are protected by the authentication middleware.
28-
$this->middleware('auth');
29-
$this->middleware('admin');
30-
26+
//
3127
}
3228

3329
public function getIndex(Request $request)

app/Http/Controllers/Auth/AuthController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AuthController extends Controller
6464
*/
6565
public function __construct()
6666
{
67-
$this->middleware('guest', ['except' => 'getLogout']);
67+
//
6868
}
6969

7070
/**

app/Http/Controllers/Base/IndexController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class IndexController extends Controller
2121
*/
2222
public function __construct()
2323
{
24-
25-
// All routes in this controller are protected by the authentication middleware.
26-
$this->middleware('auth');
24+
//
2725
}
2826

2927
/**

app/Http/Controllers/Server/AjaxController.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ class AjaxController extends Controller
3838
*/
3939
public function __construct()
4040
{
41-
42-
// All routes in this controller are protected by the authentication middleware.
43-
$this->middleware('auth');
44-
45-
// Routes in this file are also checked aganist the server middleware. If the user
46-
// does not have permission to view the server it will not load.
47-
$this->middleware('server');
48-
41+
//
4942
}
5043

5144
/**

app/Http/Controllers/Server/ServerController.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ class ServerController extends Controller
2626
*/
2727
public function __construct()
2828
{
29-
30-
// All routes in this controller are protected by the authentication middleware.
31-
$this->middleware('auth');
32-
33-
// Routes in this file are also checked aganist the server middleware. If the user
34-
// does not have permission to view the server it will not load.
35-
$this->middleware('server');
36-
29+
//
3730
}
3831

3932
/**

app/Http/Middleware/CheckServer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ public function handle($request, Closure $next)
2323
return redirect()->guest('auth/login');
2424
}
2525

26-
if (!Server::getByUUID($request->route()->server)) {
27-
return redirect('/');
26+
$server = Server::getByUUID($request->route()->server);
27+
if (!$server) {
28+
return redirect()->route('index');
29+
}
30+
31+
if ($server->installed !== 1) {
32+
return response()->view('errors.installing', [], 503);
2833
}
2934

3035
return $next($request);

app/Http/Routes/AdminRoutes.php

Lines changed: 115 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,136 @@
77
class AdminRoutes {
88

99
public function map(Router $router) {
10-
$router->group(['prefix' => 'admin'], function ($server) use ($router) {
11-
$router->get('/', [ 'as' => 'admin.index', 'uses' => 'Admin\BaseController@getIndex' ]);
1210

13-
// Account Routes
14-
$router->group(['prefix' => 'accounts'], function ($server) use ($router) {
11+
// Admin Index
12+
$router->get('admin', [
13+
'as' => 'admin.index',
14+
'middleware' => [
15+
'auth',
16+
'admin'
17+
],
18+
'uses' => 'Admin\BaseController@getIndex'
19+
]);
1520

16-
$router->get('/new', [ 'as' => 'admin.accounts.new', 'uses' => 'Admin\AccountsController@getNew' ]);
17-
$router->post('/new', [ 'as' => 'admin.accounts.new', 'uses' => 'Admin\AccountsController@postNew' ]);
21+
$router->group([
22+
'prefix' => 'admin/accounts',
23+
'middleware' => [
24+
'auth',
25+
'admin'
26+
]
27+
], function () use ($router) {
1828

19-
$router->get('/', [ 'as' => 'admin.accounts', 'uses' => 'Admin\AccountsController@getIndex' ]);
20-
$router->get('/view/{id}', [ 'as' => 'admin.accounts.view', 'uses' => 'Admin\AccountsController@getView' ]);
29+
// View All Accounts on System
30+
$router->get('/', [
31+
'as' => 'admin.accounts',
32+
'uses' => 'Admin\AccountsController@getIndex'
33+
]);
34+
35+
// View Specific Account
36+
$router->get('/view/{id}', [
37+
'as' => 'admin.accounts.view',
38+
'uses' => 'Admin\AccountsController@getView'
39+
]);
40+
41+
// Show Create Account Page
42+
$router->get('/new', [
43+
'as' => 'admin.accounts.new',
44+
'uses' => 'Admin\AccountsController@getNew'
45+
]);
2146

22-
$router->post('/update', [ 'as' => 'admin.accounts.update', 'uses' => 'Admin\AccountsController@postUpdate' ]);
23-
$router->get('/delete/{id}', [ 'as' => 'admin.accounts.delete', 'uses' => 'Admin\AccountsController@getDelete' ]);
24-
});
47+
// Handle Creating New Account
48+
$router->post('/new', [
49+
'uses' => 'Admin\AccountsController@postNew'
50+
]);
2551

26-
// Server Routes
27-
$router->group(['prefix' => 'servers'], function ($server) use ($router) {
52+
// Update A Specific Account
53+
$router->post('/update', [
54+
'uses' => 'Admin\AccountsController@postUpdate'
55+
]);
2856

29-
$router->get('/', [ 'as' => 'admin.servers', 'uses' => 'Admin\ServersController@getIndex' ]);
30-
$router->get('/new', [ 'as' => 'admin.servers.new', 'uses' => 'Admin\ServersController@getNew' ]);
31-
$router->get('/view/{id}', [ 'as' => 'admin.servers.view', 'uses' => 'Admin\ServersController@getView' ]);
57+
// Delete an Account Matching an ID
58+
$router->get('/delete/{id}', [
59+
'uses' => 'Admin\AccountsController@getDelete'
60+
]);
3261

33-
$router->post('/view/{id}/details', [ 'uses' => 'Admin\ServersController@postUpdateServerDetails' ]);
34-
$router->post('/view/{id}/rebuild', [ 'uses' => 'Admin\ServersController@postUpdateServerToggleBuild' ]);
35-
$router->post('/view/{id}/build', [ 'uses' => 'Admin\ServersController@postUpdateServerUpdateBuild' ]);
36-
$router->delete('/view/{id}/{force?}', [ 'uses' => 'Admin\ServersController@deleteServer' ]);
62+
});
63+
64+
// Server Routes
65+
$router->group([
66+
'prefix' => 'admin/servers',
67+
'middleware' => [
68+
'auth',
69+
'admin'
70+
]
71+
], function () use ($router) {
72+
73+
// View All Servers
74+
$router->get('/', [
75+
'as' => 'admin.servers',
76+
'uses' => 'Admin\ServersController@getIndex' ]);
77+
78+
// View Create Server Page
79+
$router->get('/new', [
80+
'as' => 'admin.servers.new',
81+
'uses' => 'Admin\ServersController@getNew'
82+
]);
83+
84+
// Handle POST Request for Creating Server
85+
$router->post('/new', [
86+
'uses' => 'Admin\ServersController@postNewServer'
87+
]);
3788

38-
$router->post('/new', [ 'uses' => 'Admin\ServersController@postNewServer']);
39-
$router->post('/new/get-nodes', [ 'uses' => 'Admin\ServersController@postNewServerGetNodes' ]);
40-
$router->post('/new/get-ips', [ 'uses' => 'Admin\ServersController@postNewServerGetIps' ]);
41-
$router->post('/new/service-options', [ 'uses' => 'Admin\ServersController@postNewServerServiceOptions' ]);
42-
$router->post('/new/service-variables', [ 'uses' => 'Admin\ServersController@postNewServerServiceVariables' ]);
89+
// Assorted Page Helpers
90+
$router->post('/new/get-nodes', [
91+
'uses' => 'Admin\ServersController@postNewServerGetNodes'
92+
]);
93+
94+
$router->post('/new/get-ips', [
95+
'uses' => 'Admin\ServersController@postNewServerGetIps'
96+
]);
97+
98+
$router->post('/new/service-options', [
99+
'uses' => 'Admin\ServersController@postNewServerServiceOptions'
100+
]);
101+
102+
$router->post('/new/service-variables', [
103+
'uses' => 'Admin\ServersController@postNewServerServiceVariables'
104+
]);
105+
// End Assorted Page Helpers
106+
107+
// View Specific Server
108+
$router->get('/view/{id}', [
109+
'as' => 'admin.servers.view',
110+
'uses' => 'Admin\ServersController@getView'
111+
]);
112+
113+
// Change Server Details
114+
$router->post('/view/{id}/details', [
115+
'uses' => 'Admin\ServersController@postUpdateServerDetails'
116+
]);
117+
118+
// Rebuild Server
119+
$router->post('/view/{id}/rebuild', [
120+
'uses' => 'Admin\ServersController@postUpdateServerToggleBuild'
121+
]);
122+
123+
// Change Build Details
124+
$router->post('/view/{id}/build', [
125+
'uses' => 'Admin\ServersController@postUpdateServerUpdateBuild'
126+
]);
43127

44-
});
45128
// Change Install Status
46129
$router->post('/view/{id}/installed', [
47130
'uses' => 'Admin\ServersController@postToggleInstall'
48131
]);
49132

133+
// Delete [force delete]
134+
$router->delete('/view/{id}/{force?}', [
135+
'uses' => 'Admin\ServersController@deleteServer'
136+
]);
137+
50138
});
139+
51140
}
52141

53142
}

0 commit comments

Comments
 (0)