|
| Check that the current user is logged in and has a the permission corresponding to the config menu file
|
*/
Route::filter('can_see', function () {
    $route_helper = new FileRouteHelper();
    if (!$route_helper->hasPermForRoute(Route::currentRouteName())) {
        App::abort('401');
    }
});
/*
 * Check that the user has one of the permission given
 */
Route::filter('has_perm', function () {
    $permissions = array_slice(func_get_args(), 2);
    $authentication_helper = App::make('authentication_helper');
    if (!$authentication_helper->hasPermission($permissions)) {
        App::abort('401');
    }
});
/*
|--------------------------------------------------------------------------
| Other Filters
|--------------------------------------------------------------------------
|
*/
Route::filter('ajax', function () {
    if (!Request::ajax()) {
        return Response::error('404');
    }
});
Пример #2
0
 /**
  * This is method fault
  *
  * @param mixed $exception
  *        	This is a description
  * @param mixed $format
  *        	This is a description
  * @param mixed $httpCode
  *        	This is a description
  * @return mixed This is the return value description
  */
 public function fault($exception = null, $format = 'json', $httpCode = null)
 {
     $error = false;
     if ($exception instanceof OAuthException) {
         $error = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
     } else {
         if ($exception instanceof \Exception) {
             $error = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
         } else {
             $error = ['code' => BAD_URL, 'message' => static::getError(BAD_URL)];
         }
     }
     switch ($format) {
         case 'xml':
             $errorXml = Response::error($error['code'], $error['message']);
             return $errorXml;
         case 'plain-text':
             return Response::plain($error);
         case 'json':
             $errorXml = Response::error($error['code'], $error['message'], false);
             return Zend_Json::fromXml($errorXml);
     }
 }