当前位置: 首页>>代码示例>>PHP>>正文


PHP User::isAdmin方法代码示例

本文整理汇总了PHP中common\models\User::isAdmin方法的典型用法代码示例。如果您正苦于以下问题:PHP User::isAdmin方法的具体用法?PHP User::isAdmin怎么用?PHP User::isAdmin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\User的用法示例。


在下文中一共展示了User::isAdmin方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionView

 public function actionView()
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         $link = new ActiveDataProvider(['query' => Comments::find(), 'pagination' => ['pageSize' => 50]]);
         return $this->render('view', compact('link'));
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
开发者ID:Sywooch,项目名称:find-parser,代码行数:9,代码来源:CommentsController.php

示例2: actionIndex

 /**
  * @return string
  * @throws ForbiddenHttpException
  */
 public function actionIndex()
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         $model = PaymentPlans::find()->where(['!=', 'name', 'Free'])->all();
         return $this->render('index', compact('model'));
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
开发者ID:Sywooch,项目名称:find-parser,代码行数:13,代码来源:PlansController.php

示例3: loginAdmin

 /**
  * Logs in an admin user
  * 
  * @return boolean whether the admin user is logged in successfully
  */
 public function loginAdmin()
 {
     if ($this->validate() && User::isAdmin($this->username)) {
         return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
     } else {
         $this->addError('password', 'Incorrect username or password.');
         return false;
     }
 }
开发者ID:leoshtika,项目名称:crowd-notes,代码行数:14,代码来源:LoginForm.php

示例4: actionSave

 public function actionSave()
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         $model = new Answers();
         if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 return $this->redirect('/answers/view');
             }
         }
         return $this->render('save', compact('model'));
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
开发者ID:Sywooch,项目名称:find-parser,代码行数:14,代码来源:AnswersController.php

示例5: actionLogin

 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
     }
     if (User::isAdmin($model->username)) {
         if ($model->login()) {
             return $this->goBack();
         } else {
             return $this->render('login', ['model' => $model]);
         }
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
开发者ID:Sywooch,项目名称:find-parser,代码行数:19,代码来源:SiteController.php

示例6: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     if (User::isAdmin()) {
         $query = User::find();
     } else {
         $query = User::find()->where(['status' => ['10', '0']]);
     }
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'level' => $this->level]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
开发者ID:Bladefidz,项目名称:ocfa_yii,代码行数:27,代码来源:UserSearch.php

示例7: behaviors

 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'only' => ['logout', 'signup', 'about'], 'rules' => [['actions' => ['signup'], 'allow' => true, 'roles' => ['?']], ['actions' => ['logout'], 'allow' => true, 'roles' => ['@']], ['actions' => ['about'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) {
         return User::isAdmin(Yii::$app->user->identity->username);
     }]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['logout' => ['post']]]];
 }
开发者ID:leoshtika,项目名称:crowd-notes,代码行数:9,代码来源:SiteController.php

示例8: behaviors

 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['index', 'view', 'create', 'delete', 'update'], 'allow' => User::isAdmin()]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]]];
 }
开发者ID:antonio74,项目名称:daduu42,代码行数:4,代码来源:User_groupController.php

示例9: Notes

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

<div class="wrap">
    <?php 
NavBar::begin(['brandLabel' => 'Crowd Notes (frontend)', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]);
$menuItems = [['label' => 'Home', 'url' => ['/site/index']], ['label' => 'About', 'url' => ['/site/about']], ['label' => 'Contact', 'url' => ['/site/contact']]];
if (Yii::$app->user->isGuest) {
    $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
    $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
    $menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']];
    if (User::isAdmin(Yii::$app->user->identity->username)) {
        $menuItems[] = ['label' => Yii::t('app', 'Backend'), 'url' => Yii::$app->urlManagerBackend->createUrl(['site/index']), 'linkOptions' => ['style' => 'background-color:#394754; color:#FFFFFF;']];
    }
}
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItems]);
NavBar::end();
?>

    <div class="container">
        <?php 
echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
?>
        <?php 
echo Alert::widget();
?>
        <?php 
开发者ID:leoshtika,项目名称:crowd-notes,代码行数:31,代码来源:main.php

示例10: actionUnblock_user

 public function actionUnblock_user($id)
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         if (User::updateAll(['status' => User::STATUS_ACTIVE], ['id' => $id])) {
             return $this->redirect('/user/view');
         } else {
             throw new ForbiddenHttpException('Ошибка разблокирования пользователя', 404);
         }
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
开发者ID:Sywooch,项目名称:find-parser,代码行数:12,代码来源:UserController.php

示例11: function

use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\Url;
$this->title = 'Пользователи сайта';
Pjax::begin(['id' => 'tableData']);
?>


    <div class="site-parser-data">
        <div class="row">
            <?php 
echo GridView::widget(['id' => 'tableData', 'dataProvider' => $link, 'summary' => false, 'tableOptions' => ['class' => 'table table-striped table-responsive'], 'columns' => [['label' => '№', 'value' => function ($model) {
    return $model->id;
}], ['label' => 'Логин', 'value' => function ($model) {
    return $model->username;
}], ['label' => 'Ф.И.О.', 'value' => function ($model) {
    return $model->fio;
}], ['label' => 'Электронная почта', 'value' => function ($model) {
    return $model->email;
}], ['label' => 'Телефон', 'value' => function ($model) {
    return $model->phone;
}], ['label' => '', 'format' => 'raw', 'contentOptions' => ['class' => 'text-left mnw250'], 'value' => function ($model) {
    return \common\models\User::isBlock($model->username) ? '<a href="' . Url::to('/user/unblock_user/' . $model->id) . '" class="btn btn-mini btn-default">Разблокировать пользователя</a>' : '<a href="' . Url::to('/user/block_user/' . $model->id) . '" class="btn btn-mini btn-default">Заблокировать пользователя</a>';
}], ['label' => '', 'format' => 'raw', 'contentOptions' => ['class' => 'text-left mnw250'], 'value' => function ($model) {
    return \common\models\User::isAdmin($model->username) ? '<a href="' . Url::to('/user/deladmin/' . $model->id) . '" class="btn btn-mini btn-default">Удалить статус администатора</a>' : '<a href="' . Url::to('/user/setadmin/' . $model->id) . '" class="btn btn-mini btn-default">Сделать администратором</a>';
}]]]);
?>
        </div>
    </div>
<?php 
Pjax::end();
开发者ID:Sywooch,项目名称:find-parser,代码行数:31,代码来源:view.php

示例12: function

				<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'username', 'email:email', 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'status', 'format' => 'html', 'value' => function ($data) {
    $stat = '';
    switch ($data->status) {
        case '0':
            $stat = "<span class='label label-danger'>Tidak Aktif</span>";
            break;
        case '10':
            $stat = "<span class='label label-success'>Aktif</span>";
            break;
        case '20':
            $stat = "<span class='label label-warning'>Pending</span>";
            break;
        case '30':
            $stat = "<span class='label label-danger'>Blocked</span>";
            break;
    }
    return $stat;
}, 'filter' => User::isAdmin() ? array('10' => 'Aktif', '0' => 'Tidak Aktif', '20' => 'Pending', '30' => 'Blocked') : array('10' => 'Aktif', '0' => 'Tidak Aktif')], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {deactivate}', 'buttons' => ['deactivate' => function ($url, $model) {
    $hide = $model->status == 0 ? 'hidden' : '';
    return Html::a("<span class='fa fa-ban " . $hide . "'></span>", $url, ['title' => Yii::t('app', 'Deactivate'), 'data-confirm' => Yii::t('app', 'Apakah Anda yakin ingin menonaktifkan status user ' . $model->username . '?')]);
}]]]]);
?>
				<?php 
Pjax::end();
?>
			</div><!--box footer-->
		</div><!--box-->
    </div>
</div>
开发者ID:Bladefidz,项目名称:ocfa_yii,代码行数:30,代码来源:index.php


注:本文中的common\models\User::isAdmin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。