コード例 #1
0
 public function behaviors()
 {
     //        return parent::behaviors(); // TODO: Change the autogenerated stub
     return ['access' => ['class' => \yii\filters\AccessControl::className(), 'only' => ['index'], 'rules' => [['actions' => ['index'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) {
         return PermissionHelpers::requireStatus('Active');
     }]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]]];
 }
コード例 #2
0
 public function behaviors()
 {
     return ['access' => ['class' => \yii\filters\AccessControl::className(), 'only' => ['index', 'view', 'create', 'update', 'delete'], 'rules' => [['actions' => ['index', 'view'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) {
         return PermissionHelpers::requireMinimumRole('Admin') && PermissionHelpers::requireStatus('Active');
     }], ['actions' => ['update', 'delete'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) {
         return PermissionHelpers::requireMinimumRole('SuperUser') && PermissionHelpers::requireStatus('Active');
     }]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]]];
 }
コード例 #3
0
ファイル: LoginForm.php プロジェクト: khoa002/-yii2build
 public function loginAdmin()
 {
     if ($this->validate() && PermissionHelpers::requireMinimumRole('Admin', $this->getUser()->id)) {
         return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
     } else {
         throw new NotFoundHttpException('You Shall Not Pass.');
     }
 }
コード例 #4
0
 /**
  * Updates an existing Profile model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate()
 {
     PermissionHelpers::requireUpgradeTo('Paid');
     if ($model = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one()) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view']);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     } else {
         throw new NotFoundHttpException('Нет такого профиля');
     }
 }
コード例 #5
0
ファイル: view.php プロジェクト: wangjulong/advancedBak
use yii\widgets\DetailView;
use common\models\PermissionHelpers;
/**
 * @var yii\web\View $this
 * @var frontend\models\Profile $model
 */
$this->title = $model->user->username . "'s Profile";
$this->params['breadcrumbs'][] = ['label' => 'Profile', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="profile-view">
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
//this is not necessary but in here as example
if (PermissionHelpers::userMustBeOwner('profile', $model->id)) {
    echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
}
?>
        <?php 
echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure to delete this item?'), 'method' => 'post']]);
?>
    </p>
    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['user.username', 'first_name', 'last_name', 'birthdate', 'gender.gender_name', 'created_at', 'updated_at']]);
?>
</div>
コード例 #6
0
ファイル: view.php プロジェクト: santhika29/yii2build
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use common\models\PermissionHelpers;
/* @var $this yii\web\View */
/* @var $model common\models\user */
$this->title = $model->username;
$show_this_nav = PermissionHelpers::requireMinimumRole('SuperUser');
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-view">

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

     <p>

<?php 
if (!Yii::$app->user->isGuest && $show_this_nav) {
    echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
}
?>

<?php 
if (!Yii::$app->user->isGuest && $show_this_nav) {
    echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
}
コード例 #7
0
ファイル: SiteController.php プロジェクト: Anselm21/yii2build
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['login', 'error'], 'allow' => true], ['actions' => ['index'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) {
         return PermissionHelpers::requireMinimumRole('Admin') && PermissionHelpers::requireStatus('Active');
     }], ['actions' => ['logout'], 'allow' => true, 'roles' => ['@']]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['logout' => ['get', 'post']]]];
 }
コード例 #8
0
ファイル: main.php プロジェクト: wangjulong/advancedBak
    <title><?php 
echo Html::encode($this->title);
?>
</title>
    <?php 
$this->head();
?>
</head>
<body>
<?php 
$this->beginBody();
?>
<div class="wrap">
    <?php 
if (!Yii::$app->user->isGuest) {
    $is_admin = PermissionHelpers::requireMinimumRole('Admin');
    NavBar::begin(['brandLabel' => 'Yii 2 Build <i class="fa fa-plug"></i> Admin', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
} else {
    NavBar::begin(['brandLabel' => 'Yii 2 Build <i class="fa fa-plug"></i>', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
    $menuItems = [['label' => 'Home', 'url' => ['site/index']]];
}
if (!Yii::$app->user->isGuest && $is_admin) {
    $menuItems[] = ['label' => 'Users', 'url' => ['user/index']];
    $menuItems[] = ['label' => 'Profiles', 'url' => ['profile/index']];
    $menuItems[] = ['label' => 'Roles', 'url' => ['role/index']];
    $menuItems[] = ['label' => 'User Types', 'url' => ['user-type/index']];
    $menuItems[] = ['label' => 'Statuses', 'url' => ['status/index']];
}
if (Yii::$app->user->isGuest) {
    $menuItems[] = ['label' => 'Login', 'url' => ['site/login']];
} else {
コード例 #9
0
 /**
  * Updates an existing Profile model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate()
 {
     //        $model = $this->findModel($id);
     //
     //        if ($model->load(Yii::$app->request->post()) && $model->save()) {
     //            return $this->redirect(['view', 'id' => $model->id]);
     //        } else {
     //            return $this->render('update', [
     //                'model' => $model,
     //            ]);
     //        }
     PermissionHelpers::requireUpgradeTo('Paid');
     if ($model = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one()) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view']);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     } else {
         throw new NotFoundHttpException('No such profile');
     }
 }
コード例 #10
0
ファイル: main.php プロジェクト: AntoshaPro/intranet.portal
        <?php 
$this->head();
?>

    </head>

    <body>
    <?php 
$this->beginBody();
?>

    <div class="wrap">

        <?php 
if (!Yii::$app->user->isGuest) {
    $is_admin = PermissionHelpers::requireMinimumRole('SuperUser');
    NavBar::begin(['brandLabel' => 'НПЦАП АДМИНКА <i class="fa fa-plug"></i> Админ', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
} else {
    NavBar::begin(['brandLabel' => 'НПЦАП <i class="fa fa-plug"></i>', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
}
if (Yii::$app->user->isGuest) {
    $menuItemsLogOut[] = ['label' => 'Войти', 'url' => ['site/login']];
} else {
    $menuItemsLogOut[] = ['label' => 'Выйти (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']];
}
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItemsLogOut]);
if (!Yii::$app->user->isGuest && $is_admin) {
    echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => [['label' => 'Пользователи', 'items' => [['label' => 'Пользователи', 'url' => ['user/index']], ['label' => 'Профили', 'url' => ['profile/index']]]], ['label' => 'Поддержка', 'items' => [['label' => 'Запрос в поддержку', 'url' => ['content/index']], ['label' => 'Найстройка автоответчика', 'url' => ['status-message/index']], ['label' => 'ЧАВО', 'url' => ['faq/index']], ['label' => 'ЧАВО Категории', 'url' => ['faq-category/index']]]], ['label' => 'Контроль доступа', 'items' => [['label' => 'Роли', 'url' => ['role/index']], ['label' => 'Типы пользователей', 'url' => ['user-type/index']], ['label' => 'Статусы', 'url' => ['status/index']]]], ['label' => 'Контент', 'items' => [['label' => 'Контент', 'url' => ['content/index']], ['label' => 'Автоответчик', 'url' => ['status-message/index']], ['label' => 'ЧАВО', 'url' => ['faq/index']], ['label' => 'Категории ЧАВО', 'url' => ['faq-category/index']], ['label' => 'Дракон-Тест', 'url' => ['drakon/index']]]]]]);
}
$menuItems = [['label' => 'Главная', 'url' => ['site/index']]];
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItems]);