filters.php 2.14 KB
Newer Older
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
<?php

/*
|--------------------------------------------------------------------------
| 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)
{
	//
});


App::after(function($request, $response)
{
	//
});

/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
Taylor Otwell committed
31 32
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
33 34 35 36 37
|
*/

Route::filter('auth', function()
{
Joseph Silber committed
38 39
	if (Auth::guest())
	{
40 41 42 43 44 45 46 47
		if (Request::ajax())
		{
			return Response::make('Unauthorized', 401);
		}
		else
		{
			return Redirect::guest('login');
		}
Joseph Silber committed
48
	}
49 50 51
});


Taylor Otwell committed
52 53 54 55 56 57 58 59 60 61 62
Route::filter('auth.basic', function()
{
	return Auth::basic();
});

/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
Taylor Otwell committed
63
| it simply checks that the current user is not logged in. A redirect
Taylor Otwell committed
64 65 66 67
| response will be issued if they are, which you may freely change.
|
*/

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
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()
{
86
	if (Session::token() != Input::get('_token'))
87 88 89
	{
		throw new Illuminate\Session\TokenMismatchException;
	}
Graham Campbell committed
90
});