Beispiel #1
0
 /**
  * Check if user has access to current route
  *
  * @param Action $action the action to be executed.
  *
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if ($action->id == 'captcha') {
         return true;
     }
     $route = '/' . $action->uniqueId;
     if (Route::isFreeAccess($route, $action)) {
         return true;
     }
     if (Yii::$app->user->isGuest) {
         $this->denyAccess();
     }
     // If user has been deleted, then destroy session and redirect to home page
     if (!Yii::$app->user->isGuest and Yii::$app->user->identity === null) {
         Yii::$app->getSession()->destroy();
         $this->denyAccess();
     }
     // Superadmin owns everyone
     if (Yii::$app->user->identity->isSuperadmin) {
         return true;
     }
     if (Yii::$app->user->identity and Yii::$app->user->identity->status != User::STATUS_ACTIVE) {
         Yii::$app->user->logout();
         Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl());
     }
     if (User::canRoute($route)) {
         return true;
     }
     if (isset($this->denyCallback)) {
         call_user_func($this->denyCallback, null, $action);
     } else {
         $this->denyAccess();
     }
     return false;
 }
Beispiel #2
0
 /**
  * Hide link if user hasn't access to it
  *
  * @inheritdoc
  */
 public static function a($text, $url = null, $options = [])
 {
     if (in_array($url, [null, '', '#'])) {
         return parent::a($text, $url, $options);
     }
     return User::canRoute($url) ? parent::a($text, $url, $options) : '';
 }
Beispiel #3
0
					<?php 
echo GridPageSize::widget(['pjaxId' => 'user-grid-pjax']);
?>
				</div>
			</div>


			<?php 
Pjax::begin(['id' => 'user-grid-pjax']);
?>

			<?php 
echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'pager' => ['options' => ['class' => 'pagination pagination-sm'], 'hideOnSinglePage' => true, 'lastPageLabel' => '>>', 'firstPageLabel' => '<<'], 'filterModel' => $searchModel, 'layout' => '{items}<div class="row"><div class="col-sm-8">{pager}</div><div class="col-sm-4 text-right">{summary}' . GridBulkActions::widget(['gridId' => 'user-grid', 'actions' => [Url::to(['bulk-activate', 'attribute' => 'status']) => GridBulkActions::t('app', 'Activate'), Url::to(['bulk-deactivate', 'attribute' => 'status']) => GridBulkActions::t('app', 'Deactivate'), '----' => [Url::to(['bulk-delete']) => GridBulkActions::t('app', 'Delete')]]]) . '</div></div>', 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['style' => 'width:30px']], ['class' => 'kuzmiand\\users\\components\\StatusColumn', 'attribute' => 'superadmin', 'visible' => Yii::$app->user->identity->isSuperadmin, 'options' => ['style' => 'width:100px']], ['attribute' => 'username', 'value' => function (User $model) {
    return Html::a($model->username, ['view', 'id' => $model->id], ['data-pjax' => 0]);
}, 'format' => 'raw', 'options' => ['style' => 'width:auto']], ['attribute' => 'email', 'format' => 'raw', 'visible' => User::hasPermission('viewUserEmail'), 'options' => ['style' => 'width:auto']], ['attribute' => 'gridRoleSearch', 'filter' => ArrayHelper::map(Role::getAvailableRoles(Yii::$app->user->identity->isSuperAdmin), 'name', 'description'), 'value' => function (User $model) {
    return implode(', ', ArrayHelper::map($model->roles, 'name', 'description'));
}, 'format' => 'raw', 'visible' => User::hasPermission('viewUserRoles')], ['attribute' => 'registration_ip', 'value' => function (User $model) {
    return Html::a($model->registration_ip, "http://ipinfo.io/" . $model->registration_ip, ["target" => "_blank"]);
}, 'format' => 'raw', 'visible' => User::hasPermission('viewRegistrationIp'), 'options' => ['style' => 'width:100px']], ['value' => function (User $model) {
    return GhostHtml::a('Roles and permissions', ['/user/user-permission/set', 'id' => $model->id], ['class' => 'btn btn-sm btn-primary', 'data-pjax' => 0]);
}, 'format' => 'raw', 'visible' => User::canRoute('/user/user-permission/set'), 'options' => ['width' => '165px']], ['class' => 'kuzmiand\\users\\components\\StatusColumn', 'attribute' => 'status', 'optionsArray' => [[User::STATUS_ACTIVE, 'Active', 'success'], [User::STATUS_NEW, 'Inactive', 'warning'], [User::STATUS_BLOCKED, 'Blocked', 'danger']]], ['class' => 'yii\\grid\\CheckboxColumn', 'options' => ['style' => 'width:30px']], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['style' => 'width:70px; text-align:center;']]]]);
?>

			<?php 
Pjax::end();
?>

		</div>
	</div>
</div>