filters.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Application & Route Filters
  5. |--------------------------------------------------------------------------
  6. |
  7. | Below you will find the "before" and "after" events for the application
  8. | which may be used to do any work before or after a request into your
  9. | application. Here you may also register your custom route filters.
  10. |
  11. */
  12. App::before(function($request)
  13. {
  14. //
  15. });
  16. App::after(function($request, $response)
  17. {
  18. //
  19. });
  20. /*
  21. |--------------------------------------------------------------------------
  22. | Authentication Filters
  23. |--------------------------------------------------------------------------
  24. |
  25. | The following filters are used to verify that the user of the current
  26. | session is logged into this application. The "basic" filter easily
  27. | integrates HTTP Basic authentication for quick, simple checking.
  28. |
  29. */
  30. Route::filter('auth', function()
  31. {
  32. if (Auth::guest())
  33. {
  34. if (Request::ajax())
  35. {
  36. return Response::make('Unauthorized', 401);
  37. }
  38. else
  39. {
  40. return Redirect::guest('login');
  41. }
  42. }
  43. });
  44. Route::filter('auth.basic', function()
  45. {
  46. return Auth::basic();
  47. });
  48. /*
  49. |--------------------------------------------------------------------------
  50. | Guest Filter
  51. |--------------------------------------------------------------------------
  52. |
  53. | The "guest" filter is the counterpart of the authentication filters as
  54. | it simply checks that the current user is not logged in. A redirect
  55. | response will be issued if they are, which you may freely change.
  56. |
  57. */
  58. Route::filter('guest', function()
  59. {
  60. if (Auth::check()) return Redirect::to('/');
  61. });
  62. /*
  63. |--------------------------------------------------------------------------
  64. | CSRF Protection Filter
  65. |--------------------------------------------------------------------------
  66. |
  67. | The CSRF filter is responsible for protecting your application against
  68. | cross-site request forgery attacks. If this special token in a user
  69. | session does not match the one given in this request, we'll bail.
  70. |
  71. */
  72. Route::filter('csrf', function()
  73. {
  74. if (Session::token() != Input::get('_token'))
  75. {
  76. throw new Illuminate\Session\TokenMismatchException;
  77. }
  78. });