Files
FHC-Core/application/core/APIv1_Controller.php
T
Paolo fdddb52259 - Moved REST_Controller from libraries to core directory
- Changed the relatives includes
- Changed the controller api/v1/CheckUserAuth to be adapted to the AuthLib changes
- Removed function auth from helpers/hlp_authentication_helper
- Adapted function getAuthUID of helpers/hlp_authentication_helper to the AuthLib changes
- Adapted constructor of PermissionLib to the AuthLib changes
2019-02-27 11:24:27 +01:00

39 lines
1.0 KiB
PHP

<?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('hlp_message');
// Loads helper with generic utility function
$this->load->helper('hlp_common');
// 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);
}
}
}