Created
January 12, 2013 21:48
-
-
Save crisu83/4520627 to your computer and use it in GitHub Desktop.
AuthFilter class from the Auth module for the Yii PHP framework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* AuthFilter class file. | |
* @author Christoffer Niska <[email protected]> | |
* @copyright Copyright © Christoffer Niska 2012- | |
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | |
* @package auth.components | |
*/ | |
/** | |
* Filter that automatically checks if the user has access to the current controller action. | |
*/ | |
class AuthFilter extends CFilter | |
{ | |
/** | |
* @var array name-value pairs that would be passed to business rules associated | |
* with the tasks and roles assigned to the user. | |
*/ | |
public $params = array(); | |
/** | |
* Performs the pre-action filtering. | |
* @param CFilterChain $filterChain the filter chain that the filter is on. | |
* @return boolean whether the filtering process should continue and the action should be executed. | |
* @throws CHttpException if the user is denied access. | |
*/ | |
protected function preFilter($filterChain) | |
{ | |
$itemName = ''; | |
$controller = $filterChain->controller; | |
if (($module = $controller->getModule()) !== null) | |
$itemName .= $module->getId() . '.'; | |
$itemName .= $controller->getId(); | |
/* @var $user CWebUser */ | |
$user = Yii::app()->getUser(); | |
if ($user->checkAccess($itemName . '.*')) | |
return true; | |
$itemName .= '.' . $controller->action->getId(); | |
if ($user->checkAccess($itemName, $this->params)) | |
return true; | |
throw new CHttpException(401, Yii::t('AuthModule.main', 'Access denied.')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment