...
|
...
|
@@ -30,18 +30,50 @@ class AccessControl extends \yii\filters\AccessControl |
|
|
public function init()
|
|
|
{
|
|
|
$rules = [];
|
|
|
|
|
|
/**
|
|
|
* 验证用户访问权限
|
|
|
*/
|
|
|
$route = Yii::$app->controller->id.'/'.Yii::$app->controller->action->id;
|
|
|
//var_dump($route);
|
|
|
if (!self::verifyAccess($route)){
|
|
|
$rules = [['allow'=>false]];
|
|
|
}
|
|
|
|
|
|
$this->rules = ArrayHelper::merge($rules, $this->rules);
|
|
|
|
|
|
$this->denyCallback = function ($rule, $action) {
|
|
|
if (Yii::$app->user->getIsGuest()) {
|
|
|
Yii::$app->user->loginRequired();
|
|
|
} else {
|
|
|
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
|
|
|
//throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
|
|
|
Yii::$app->response->content = Yii::$app->view->render('@app/views/site/403',['_refer'=>Yii::$app->request->referrer]);
|
|
|
Yii::$app->response->send();
|
|
|
Yii::$app->end(1);
|
|
|
}
|
|
|
};
|
|
|
parent::init();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证用户访问权限
|
|
|
* @param type $permission 权限标签
|
|
|
* @return boolean
|
|
|
*/
|
|
|
static function verifyAccess($permission)
|
|
|
{
|
|
|
$auth = Yii::$app->authManager;
|
|
|
$permission = $auth->getPermission($permission);
|
|
|
if (!$permission){
|
|
|
return false;
|
|
|
}
|
|
|
$permissions = $auth->getPermissionsByUser(Yii::$app->user->getId());
|
|
|
if (in_array($permission,$permissions)){
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public function beforeAction($action)
|
|
|
{
|
|
|
return parent::beforeAction($action);
|
...
|
...
|
|