/** * @inheritdoc */ public function checkAccess($userId, $permissionName, $params = []) { if (!isset($this->_users[$userId])) { $this->_users[$userId] = User::findOne($userId); } $user = $this->_users[$userId]; if ($user instanceof User && $user->is_super_admin) { return true; } else { return parent::checkAccess($userId, $permissionName, $params); } }
/** * @inheritdoc */ public function checkAccess($userId, $permissionName, $params = []) { if (!empty($params)) { return parent::checkAccess($userId, $permissionName, $params); } $cacheKey = 'checkAccess:' . $userId . ':' . $permissionName; $cached = $this->getCache($cacheKey); if (empty($cached)) { $cached = parent::checkAccess($userId, $permissionName); $this->setCache($cacheKey, $cached); } return $cached; }
public function checkAccess($userId, $permissionName, $params = []) { if (count($params) > 0) { return parent::checkAccess($userId, $permissionName, $params); } $cacheKey = $this->cachePrefix . 'userAccessCheck:' . $userId . ':' . $permissionName; /* Due to yii2 cache system, where we receive 'false' from cache component we have to store array in cache to ensure that 'false' doesn't mean that access is restricted */ $check = $this->getCache()->get($cacheKey); if (!is_array($check)) { $check = [parent::checkAccess($userId, $permissionName, $params)]; $this->getCache()->set($cacheKey, $check, $this->lifetime); } return $check[0]; }
public function beforeAction($action) { // 判断是否登录 $isLogin = AdminBaseInfo::isLogin(); if (!$isLogin) { return $this->redirect(['login/login']); } $session = Yii::$app->getSession(); $Jurisdiction = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id; $dbManager = new DbManager(); $id = $session[AdminBaseInfo::SESSION_KEY_ADMIN]['id']; if (Yii::$app->authManager->getRolesByUser($id)['admin']->name == 'admin') { parent::beforeAction($action); return true; } if ($dbManager->checkAccess($id, $Jurisdiction)) { parent::beforeAction($action); return true; } else { return $this->redirect(['login/no-authority']); } parent::beforeAction($action); return true; }
<div class="service-base-info-index" style='margin-left:50px;width:auto;margin-right:50px;'> <h3><?php echo Html::encode($this->title); ?> </h3> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php $dbManager = new DbManager(); $session = Yii::$app->getSession(); $id = $session[AdminBaseInfo::SESSION_KEY_ADMIN]['id']; if ($dbManager->checkAccess($id, 'admin')) { echo Html::a(Yii::t('app', '创建服务'), ['create'], ['class' => 'btn btn-success']); } ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'header' => '序号'], 'service_name', 'service_id', 'service_key', 'service_desc', 'api_url:url', ['attribute' => 'create_time', 'value' => function ($model, $row) { return date('Y-m-d H:i:s', ServiceBaseInfo::getServiceById($row)['create_time']); }], ['attribute' => 'update_time', 'value' => function ($model, $row) { return date('Y-m-d H:i:s', ServiceBaseInfo::getServiceById($row)['update_time']); }], 'user_id', ['attribute' => 'status', 'value' => function ($model, $row) { $status = ServiceBaseInfo::getServiceById($row)['status']; if ($status == 1) { return '正常'; } else {
/** * Deletes an existing ApplicationBaseInfo model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $session = Yii::$app->getSession(); $Jurisdiction = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id; $dbManager = new DbManager(); $sessionId = $session[AdminBaseInfo::SESSION_KEY_ADMIN]['id']; $result = $dbManager->checkAccess($sessionId, $Jurisdiction); if (!$result && array_keys(Yii::$app->authManager->getRolesByUser($sessionId))[0] != 'admin') { return $this->redirect(['login/no-authority']); } $model = $this->findModel($id); $model->update_time = time(); $model->status = ApplicationBaseInfo::APPLICATION_DISABLE_STATUS; if ($model->save()) { return $this->redirect(['index']); } else { echo '操作失败'; } // $this->findModel($id)->delete(); // return $this->redirect(['index']); }
<li> <a href="#"><i class="icon-th" ></i>应用管理</a> <ul class='closed'> <li><a href="<?php echo Url::toRoute(['application/index'], true); ?> ">应用列表</a></li> </ul> </li> <?php } ?> <?php $dbManager = new DbManager(); if ($dbManager->checkAccess($info['id'], 'rbac/index') || array_keys(Yii::$app->authManager->getRolesByUser($info['id']))[0] == 'admin') { ?> <li> <a href="#"><i class="icon-wrench" ></i>权限管理</a> <ul class='closed'> <li><a href="<?php echo Url::toRoute(['rbac/index'], true); ?> ">权限列表</a></li> </ul> </li> <?php } ?> </ul> </div>