Preparing a SetupController

This commit is contained in:
James Brooks 2014-11-23 21:34:31 +00:00
parent 8d4bf3f5ea
commit e5a70aef0b
7 changed files with 99 additions and 81 deletions

View File

@ -0,0 +1,7 @@
<?php
class SetupController extends Controller {
public function showSetup() {
return View::make('setup');
}
}

View File

@ -1,90 +1,70 @@
<?php <?php
/* Route::filter('no_setup', 'NoSetupFilter');
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function($request) /*
{ |--------------------------------------------------------------------------
// | Authentication Filters
}); |--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function()
App::after(function($request, $response)
{
//
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function()
{
if (Auth::guest())
{ {
if (Request::ajax()) if (Auth::guest())
{ {
return Response::make('Unauthorized', 401); if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
else
{
return Redirect::guest('login');
}
} }
else });
{
return Redirect::guest('login');
}
}
});
Route::filter('auth.basic', function() Route::filter('auth.basic', function()
{
return Auth::basic();
});
/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/
Route::filter('guest', function()
{
if (Auth::check()) return Redirect::to('/');
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function()
{
if (Session::token() !== Input::get('_token'))
{ {
throw new Illuminate\Session\TokenMismatchException; return Auth::basic();
} });
});
/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/
Route::filter('guest', function()
{
if (Auth::check()) return Redirect::to('/');
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function()
{
if (Session::token() !== Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
});

View File

@ -0,0 +1,10 @@
<?php
class NoSetupFilter {
public function filter($route, $request, $settingName) {
$setting = Setting::get($settingName);
if ($setting === null) {
return Response::make('Unauthorized', 401);
}
}
}

View File

@ -2,3 +2,7 @@
Route::get('/', 'HomeController@showIndex'); Route::get('/', 'HomeController@showIndex');
Route::get('/incident/{incident}', 'HomeController@showIncident'); Route::get('/incident/{incident}', 'HomeController@showIncident');
Route::group(['before' => 'no_setup:app_name'], function() {
Route::get('/setup', 'SetupController@showSetup');
});

View File

@ -17,6 +17,7 @@ ClassLoader::addDirectories(array(
app_path().'/controllers', app_path().'/controllers',
app_path().'/models', app_path().'/models',
app_path().'/database/seeds', app_path().'/database/seeds',
app_path().'/filterss',
)); ));

15
app/views/setup.blade.php Normal file
View File

@ -0,0 +1,15 @@
@extends('layout.master')
@section('content')
<div class='page-header'>
<ul class='list-group components'>
@foreach(Component::get() as $component)
<li class='list-group-item component '>
<!-- <span class='badge badge-{{ $component->color }}'><i class='glyphicon glyphicon-stop'></i></span> -->
<h4>{{ $component->name }} <small class='{{ $component->color }}'>{{ $component->humanStatus }}</small></h4>
<p>{{ $component->description }}</p>
</li>
@endforeach
</ul>
</div>
@stop

View File

@ -15,7 +15,8 @@
"app/models", "app/models",
"app/database/migrations", "app/database/migrations",
"app/database/seeds", "app/database/seeds",
"app/tests/TestCase.php" "app/tests/TestCase.php",
"app/filters"
] ]
}, },
"extra": { "extra": {