Beispiel #1
0
 public function beforeAction($action)
 {
     parent::beforeAction($action);
     if (!in_array(Yii::$app->user->identity->username, ['ming.lin', 'wuying.hai'])) {
         $AuthManagerModel = new AuthManager();
         $userid = Yii::$app->user->identity->id;
         $route = strtolower(Yii::$app->controller->route);
         $routeArr = explode('/', $route);
         $controller = !empty($routeArr[0]) ? $routeArr[0] : 'welcome';
         $ac = !empty($routeArr[1]) ? $routeArr[1] : 'index';
         $permission = strtolower($controller . '_' . $ac);
         if (!$AuthManagerModel->checkAccess($userid, $permission)) {
             $this->redirect(['site/sys-error']);
         }
     }
     return true;
 }
Beispiel #2
0
 public static function checkAccess($permission)
 {
     $AuthManagerModel = new AuthManager();
     $userid = Yii::$app->user->identity->id;
     $username = Yii::$app->user->identity->username;
     if (in_array($username, Yii::$app->params['systemAdmin'])) {
         return true;
     } else {
         return $AuthManagerModel->checkAccess($userid, $permission);
     }
 }