No Description

filters.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. Log::debug('START ' . Request::getClientIp() . ': ' . Request::method() . ' ' . Request::path());
  14. //if (!Request::secure()) {
  15. // return Redirect::secure(Request::path());
  16. //}
  17. });
  18. App::after(function ($request, $response) {
  19. //
  20. });
  21. /*
  22. |--------------------------------------------------------------------------
  23. | Authentication Filters
  24. |--------------------------------------------------------------------------
  25. |
  26. | The following filters are used to verify that the user of the current
  27. | session is logged into this application. The "basic" filter easily
  28. | integrates HTTP Basic authentication for quick, simple checking.
  29. |
  30. */
  31. Route::filter('auth', function () {
  32. if (Auth::guest()) {
  33. if (Request::ajax()) {
  34. return Response::make('Unauthorized', 401);
  35. } else {
  36. return Redirect::guest('/');
  37. }
  38. }
  39. });
  40. Route::filter('auth.basic', function () {
  41. return Auth::basic();
  42. });
  43. Route::filter('has_access', function () {
  44. if (!Auth::user()->has_access) {
  45. Session::flash('status', 'info');
  46. Session::flash('message', 'At this time, access to OLAS is limited to some users. Check back later or contact an administrator.');
  47. Auth::logout();
  48. return Redirect::action('AuthController@showLogin');
  49. }
  50. });
  51. /*
  52. |--------------------------------------------------------------------------
  53. | Guest Filter
  54. |--------------------------------------------------------------------------
  55. |
  56. | The "guest" filter is the counterpart of the authentication filters as
  57. | it simply checks that the current user is not logged in. A redirect
  58. | response will be issued if they are, which you may freely change.
  59. |
  60. */
  61. Route::filter('guest', function () {
  62. if (Auth::check()) {
  63. switch (Auth::user()->role) {
  64. case 1:
  65. return Redirect::to('administrator');
  66. break;
  67. case 2:
  68. return Redirect::to('school-coordinator');
  69. break;
  70. case 3:
  71. return Redirect::to('program-coordinator');
  72. break;
  73. case 4:
  74. return Redirect::to('professor');
  75. break;
  76. }
  77. }
  78. });
  79. /*
  80. |--------------------------------------------------------------------------
  81. | Administrator Filter
  82. |--------------------------------------------------------------------------
  83. |
  84. | This filter redirects logged in users except administrators to their
  85. | default page if they try to access a forbidden page.
  86. |
  87. */
  88. Route::filter('admin', function () {
  89. if (Auth::user()->role != 1) {
  90. switch (Auth::user()->role) {
  91. case 2:
  92. return Redirect::to('school-coordinator');
  93. break;
  94. case 3:
  95. return Redirect::to('program-coordinator');
  96. break;
  97. case 4:
  98. return Redirect::to('professor');
  99. break;
  100. }
  101. }
  102. });
  103. /*
  104. |--------------------------------------------------------------------------
  105. | School Coordinator Filter
  106. |--------------------------------------------------------------------------
  107. |
  108. | This filter redirects logged in users below school coordinators to their
  109. | default page if they try to access a forbidden page.
  110. |
  111. */
  112. Route::filter('scoord', function () {
  113. if (!(Auth::user()->role == 2 || Auth::user()->role == 1)) {
  114. switch (Auth::user()->role) {
  115. case 3:
  116. return Redirect::to('program-coordinator');
  117. break;
  118. case 4:
  119. return Redirect::to('professor');
  120. break;
  121. }
  122. }
  123. });
  124. /*
  125. |--------------------------------------------------------------------------
  126. | Program Coordinator Filter
  127. |--------------------------------------------------------------------------
  128. |
  129. | This filter redirects logged in users below program coordinators to their
  130. | default page if they try to access a forbidden page.
  131. |
  132. */
  133. Route::filter('pcoord', function () {
  134. if (!(Auth::user()->role == 3 || Auth::user()->role == 2 || Auth::user()->role == 1)) {
  135. return Redirect::to('professor');
  136. }
  137. });
  138. /*
  139. |--------------------------------------------------------------------------
  140. | Professor Filter
  141. |--------------------------------------------------------------------------
  142. |
  143. | This filter redirects logged in users except profesors to their
  144. | default page if they try to access a forbidden page.
  145. |
  146. */
  147. Route::filter('prof', function () {
  148. // If user has no courses then s/he is not a professor
  149. // and must be redirected to her/his overview page
  150. if (!count(Auth::user()->courses)) {
  151. switch (Auth::user()->role) {
  152. case 1:
  153. return Redirect::to('administrator');
  154. break;
  155. case 2:
  156. return Redirect::to('school-coordinator');
  157. break;
  158. case 3:
  159. return Redirect::to('program-coordinator');
  160. break;
  161. }
  162. }
  163. });
  164. /*
  165. |--------------------------------------------------------------------------
  166. | CSRF Protection Filter
  167. |--------------------------------------------------------------------------
  168. |
  169. | The CSRF filter is responsible for protecting your application against
  170. | cross-site request forgery attacks. If this special token in a user
  171. | session does not match the one given in this request, we'll bail.
  172. |
  173. */
  174. Route::filter('csrf', function () {
  175. $token = Request::ajax() ? Request::header('X-CSRF-Token') : Input::get('_token');
  176. if (Session::token() !== $token) {
  177. throw new Illuminate\Session\TokenMismatchException;
  178. }
  179. });