filters.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. Also, a "guest" filter is
  27. | responsible for performing the opposite. Both provide redirects.
  28. |
  29. */
  30. Route::filter('auth', function()
  31. {
  32. if (Auth::guest()) return Redirect::route('login');
  33. });
  34. Route::filter('guest', function()
  35. {
  36. if (Auth::check()) return Redirect::to('/');
  37. });
  38. /*
  39. |--------------------------------------------------------------------------
  40. | CSRF Protection Filter
  41. |--------------------------------------------------------------------------
  42. |
  43. | The CSRF filter is responsible for protecting your application against
  44. | cross-site request forgery attacks. If this special token in a user
  45. | session does not match the one given in this request, we'll bail.
  46. |
  47. */
  48. Route::filter('csrf', function()
  49. {
  50. if (Session::getToken() != Input::get('csrf_token'))
  51. {
  52. throw new Illuminate\Session\TokenMismatchException;
  53. }
  54. });