Files
FHC-Core/application/core/APIv1_Controller.php
T
Paolo 8f566e0499 Auth_Controller is now able to display a better message if the user is unauthorized
This message contains:
- the name of the called controller
- the name of the called method of the called controller
- all the possible permissions and related modes needed to acces to this content
2018-06-28 16:09:12 +02:00

38 lines
1.0 KiB
PHP

<?php
require_once APPPATH.'/libraries/REST_Controller.php';
class APIv1_Controller extends REST_Controller
{
/**
* Standard constructor for all the RESTful resources
*/
public function __construct($requiredPermissions)
{
parent::__construct();
// Loads helper message to manage returning messages
$this->load->helper('message');
// Loads permission lib
$this->load->library('PermissionLib');
log_message('debug', 'Called API: '.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
$this->_isAllowed($requiredPermissions);
}
/**
* Checks if the caller is allowed to access to this content with the given permissions
* If it is not allowed will set the HTTP header with code 401
* Wrapper for permissionlib->isEntitled
*/
private function _isAllowed($requiredPermissions)
{
if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method))
{
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
}
}
}