예제 #1
0
 public function actionInit()
 {
     $authManager = \Yii::$app->authManager;
     // Create roles
     $user = $authManager->createRole('user');
     $moderator = $authManager->createRole('moderator');
     $admin = $authManager->createRole('administrator');
     //$guest->ruleName  = 'guest';
     //$user->ruleName  = 'user';
     //$moderator->ruleName = 'moderator';
     //$admin->ruleName = 'administrator';
     // Add roles in Yii::$app->authManager
     $authManager->add($user);
     $authManager->add($moderator);
     $authManager->add($admin);
     $role = $authManager->getRole(UserType::getUserTypeText(UserType::ADMINISTRATOR));
     $authManager->assign($role, 1);
 }
예제 #2
0
파일: index.php 프로젝트: apuc/NDFL
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Добавить пользователя', ['create'], ['class' => 'btn btn-success']);
?>
        <?php 
echo Html::a('Назад', ['/'], ['class' => 'btn btn-info']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'email:email', 'name', 'surname', ['attribute' => 'status', 'format' => 'text', 'value' => function ($model) {
    return \common\constants\Status::getStatusText($model->status);
}, 'filter' => [-1 => "Забанен", 0 => "Не активирован", 1 => 'Активирован']], ['attribute' => 'user_type', 'format' => 'text', 'value' => function ($model) {
    return \common\constants\UserType::getUserTypeNumber($model->user_type);
}, 'filter' => [\common\constants\UserType::MODERATOR => 'Модератор', \common\constants\UserType::ADMINISTRATOR => 'Администратор']], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
예제 #3
0
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $oldPassword = $model->password;
     $oldUserType = $model->user_type;
     $oldImage = $model->image;
     if ($model->load(Yii::$app->request->post())) {
         $model->updated_at = time();
         if ($oldPassword != $model->password) {
             $model->generatePassword($model->password);
         }
         if (!$model->validate()) {
             throw new Exception($model->errors);
         }
         $image = UploadedFile::getInstance($model, 'image');
         if ($image) {
             /**
              * удаление старой картинки, загрузка новой3
              */
             $oldFileUrl = Yii::getAlias('@frontend') . '/web/image/' . $oldImage;
             if (strlen($oldImage)) {
                 unlink($oldFileUrl);
             }
             $model->image = md5(time()) . '.' . $image->extension;
             $image->saveAs(Yii::getAlias('@frontend') . '/web/image/' . $model->image);
         } else {
             $model->image = $oldImage;
         }
         if ($oldUserType != $model->user_type) {
             AuthAssignment::findOne(['user_id' => $model->id, 'item_name' => \common\constants\UserType::getUserTypeText($oldUserType)])->delete();
             $authManager = Yii::$app->authManager;
             $role = $authManager->getRole(\common\constants\UserType::getUserTypeText($model->user_type));
             $authManager->assign($role, $model->id);
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
예제 #4
0
파일: view.php 프로젝트: apuc/NDFL
/* @var $this yii\web\View */
/* @var $model backend\modules\manager\models\db\User */
$this->title = 'Профиль: ' . $model->email;
$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 
echo Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('Удалить', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Вы уверены что хотите удалить профиль ' . $model->email . '?', 'method' => 'post']]);
?>
        <?php 
echo Html::a('Назад', ['/manager'], ['class' => 'btn btn-info']);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['email:email', 'surname', 'name', 'patronymic', ['attribute' => 'status', 'value' => \common\constants\Status::getStatusText($model->status)], 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'user_type', 'value' => \common\constants\UserType::getUserTypeNumber($model->user_type)], ['attribute' => 'image', 'format' => 'html', 'value' => Html::img('/image/' . $model->image)]]]);
?>

</div>