/**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     $actionId = $action->getUniqueId();
     $user = $this->getUser();
     if (Helper::checkRoute('/' . $actionId, Yii::$app->getRequest()->get(), $user)) {
         return true;
     }
     $this->denyAccess($user);
 }
Exemple #2
0
 /**
  * Assign or remove items
  * @param array $routes
  * @return array
  */
 public function remove($routes)
 {
     $manager = Yii::$app->getAuthManager();
     foreach ($routes as $route) {
         try {
             $item = $manager->createPermission('/' . trim($route, '/'));
             $manager->remove($item);
         } catch (Exception $exc) {
             Yii::error($exc->getMessage(), __METHOD__);
         }
     }
     Helper::invalidate();
 }
Exemple #3
0
 /**
  * Revokes a roles from a user.
  * @param array $items
  * @return integer number of successful revoke
  */
 public function revoke($items)
 {
     $manager = Yii::$app->getAuthManager();
     $success = 0;
     foreach ($items as $name) {
         try {
             $item = $manager->getRole($name);
             $item = $item ?: $manager->getPermission($name);
             $manager->revoke($item, $this->id);
             $success++;
         } catch (\Exception $exc) {
             Yii::error($exc->getMessage(), __METHOD__);
         }
     }
     Helper::invalidate();
     return $success;
 }
Exemple #4
0
$this->title = $model->username;
$this->params['breadcrumbs'][] = ['label' => Yii::t('rbac-admin', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$controllerId = $this->context->uniqueId . '/';
?>
<div class="user-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
if ($model->status == 0 && Helper::checkRoute($controllerId . 'activate')) {
    echo Html::a(Yii::t('rbac-admin', 'Activate'), ['activate', 'id' => $model->id], ['class' => 'btn btn-primary', 'data' => ['confirm' => Yii::t('rbac-admin', 'Are you sure you want to activate this user?'), 'method' => 'post']]);
}
?>
        <?php 
if (Helper::checkRoute($controllerId . 'delete')) {
    echo Html::a(Yii::t('rbac-admin', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
}
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['username', 'email:email', 'created_at:date', 'status']]);
?>

</div>
 /**
  * Deletes an existing AuthItem model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param  string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     Yii::$app->getAuthManager()->remove($model->item);
     Helper::invalidate();
     return $this->redirect(['index']);
 }
Exemple #6
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use thinkwill\admin\components\Helper;
/* @var $this yii\web\View */
/* @var $searchModel thinkwill\admin\models\searchs\User */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('rbac-admin', 'Users');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'username', 'email:email', 'created_at:date', ['attribute' => 'status', 'value' => function ($model) {
    return $model->status == 0 ? 'Inactive' : 'Active';
}, 'filter' => [0 => 'Inactive', 10 => 'Active']], ['class' => 'yii\\grid\\ActionColumn', 'template' => Helper::filterActionColumn(['view', 'activate', 'delete']), 'buttons' => ['activate' => function ($url, $model) {
    if ($model->status == 10) {
        return '';
    }
    $options = ['title' => Yii::t('rbac-admin', 'Activate'), 'aria-label' => Yii::t('rbac-admin', 'Activate'), 'data-confirm' => Yii::t('rbac-admin', 'Are you sure you want to activate this user?'), 'data-method' => 'post', 'data-pjax' => '0'];
    return Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, $options);
}]]]]);
?>
</div>
Exemple #7
0
 /**
  * Remove an item as a child of another item.
  * @param array $items
  * @return int
  */
 public function removeChildren($items)
 {
     $manager = Yii::$app->getAuthManager();
     $success = 0;
     if ($this->_item !== null) {
         foreach ($items as $name) {
             $child = $manager->getPermission($name);
             if ($this->type == Item::TYPE_ROLE && $child === null) {
                 $child = $manager->getRole($name);
             }
             try {
                 $manager->removeChild($this->_item, $child);
                 $success++;
             } catch (\Exception $exc) {
                 Yii::error($exc->getMessage(), __METHOD__);
             }
         }
     }
     if ($success > 0) {
         Helper::invalidate();
     }
     return $success;
 }
 /**
  * Deletes an existing Menu model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param  integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Helper::invalidate();
     return $this->redirect(['index']);
 }