Files
FHC-Core/application/core/FHC_Controller.php
T
Paolo 1f2450cf17 - Moved _checkPermissions from FHC_Controller to PermissionLib (now is public and it's renamed checkPermissions)
- Added include of PermissionLib in APIv1_Controller
- Added method _isAllowed to APIv1_Controller to call checkPermissions from PermissionLib
- Now the APIv1_Controller constructor requires an array of permissions as parameter
2018-03-20 13:00:35 +01:00

39 lines
979 B
PHP

<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class FHC_Controller extends CI_Controller
{
/**
* Standard construct for all the controllers, loads the authentication system
* Checks the caller permissions
*/
public function __construct($requiredPermissions)
{
parent::__construct();
// Loads authentication helper
$this->load->helper('fhcauth');
// Loads permission lib
$this->load->library('PermissionLib');
$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 _checkPermissions
*/
private function _isAllowed($requiredPermissions)
{
if (!$this->permissionlib->checkPermissions($requiredPermissions, $this->router->method))
{
header('HTTP/1.0 401 Unauthorized');
echo 'You are not allowed to access to this content';
exit;
}
}
}