示例#1
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
 public function down()
 {
     if ($user = User::find()->where(['username' => 'admin'])->one()) {
         /** @var $user User */
         $user->delete();
         echo 'User "' . $user->username . '" deleted.';
     }
 }
 /**
  * Creates data provider instance with search query applied
  * @param array $params
  * @param bool $trashed
  * @return ActiveDataProvider
  */
 public function search($params, $trashed = false)
 {
     $query = User::find();
     if ($trashed) {
         $query->trashed();
     } else {
         $query->published();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at, 'last_visit_at' => $this->last_visit_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'auth_key', $this->auth_key]);
     if (count($this->getRoles())) {
         /** @var \yii\rbac\DbManager $auth */
         $auth = Yii::$app->authManager;
         $query->leftJoin($auth->assignmentTable . ' roles', 'roles.user_id=id');
         $query->andWhere(['roles.item_name' => $this->getRoles()]);
     }
     return $dataProvider;
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'created_by']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
示例#6
0
<div class="user-form">

    <?php 
$form = ActiveForm::begin(['layout' => 'horizontal']);
?>

    <?php 
echo $form->field($model, 'username')->textInput(['maxlength' => 64, 'disabled' => $model->scenario !== 'create' ? true : false]);
?>

    <?php 
echo $form->field($model, 'email')->textInput(['maxlength' => 128, 'disabled' => $model->scenario !== 'create' ? true : false]);
?>

    <?php 
echo $form->field($model, 'status')->dropDownList(\gromver\platform\basic\modules\user\models\User::statusLabels());
?>

    <?php 
echo $form->field($model, 'password')->passwordInput(['autocomplete' => 'off']);
?>

    <?php 
echo $form->field($model, 'password_confirm')->passwordInput(['autocomplete' => 'off']);
?>

    <?php 
if ($model->getIsSuperAdmin()) {
    echo $form->field($model, 'roles')->textInput(['value' => Yii::t('gromver.platform', 'Super Administrator'), 'disabled' => true]);
} else {
    echo $form->field($model, 'roles')->listBox(\yii\helpers\ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name'), ['multiple' => 'multiple']);
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
 private function sendPasswordResetEmail($email)
 {
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $email]);
     if (!$user) {
         return false;
     }
     $user->password_reset_token = Yii::$app->security->generateRandomString();
     if ($user->save(false)) {
         $mailer = Instance::ensure($this->mailer, BaseMailer::className());
         return $mailer->compose('@gromver/platform/basic/modules/auth/views/emails/passwordResetToken', ['user' => $user])->setFrom(Yii::$app->grom->params['supportEmail'], Yii::t('gromver.platform', '{name} robot', ['name' => Yii::$app->grom->siteName]))->setTo($user->email)->setSubject(Yii::t('gromver.platform', 'Password reset for {name}.', ['name' => Yii::$app->grom->siteName]))->send();
     }
     return false;
 }
    </div>
    <?php 
/*// echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('gromver.platform', 'Create {modelClass}', [
    'modelClass' => 'User',
]), ['create'], ['class' => 'btn btn-success']) ?>
    </p>*/
?>

    <?php 
echo GridView::widget(['id' => 'table-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true], 'columns' => [['class' => '\\kartik\\grid\\CheckboxColumn'], ['attribute' => 'id', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px'], ['attribute' => 'username', 'vAlign' => GridView::ALIGN_MIDDLE], ['attribute' => 'email', 'vAlign' => GridView::ALIGN_MIDDLE, 'format' => 'email'], ['attribute' => 'status', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var User $model */
    return $model->getStatusLabel();
}, 'filter' => User::statusLabels()], ['attribute' => 'roles', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var User $model */
    return $model->getIsSuperAdmin() ? '<span class="text-muted">superadmin</span>' : implode(", ", $model->getRoles());
}, 'format' => 'html', 'filter' => \yii\helpers\ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')], 'deleted_at:datetime', ['class' => 'kartik\\grid\\ActionColumn', 'width' => '100px', 'template' => '{view} {restore} {delete}', 'deleteOptions' => ['data-method' => 'delete'], 'buttons' => ['restore' => function ($url, $model, $key) {
    /** @var User $model */
    return Html::a('<i class="glyphicon glyphicon-open"></i>', ['restore', 'id' => $model->id], ['title' => Yii::t('gromver.platform', 'Restore'), 'data-method' => 'delete', 'data-pjax' => '0']);
}]]], 'responsive' => true, 'hover' => true, 'condensed' => true, 'floatHeader' => true, 'bordered' => false, 'panel' => ['heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> ' . Html::encode($this->title) . ' </h3>', 'type' => 'info', 'before' => Html::a('<i class="glyphicon glyphicon-circle-arrow-left"></i> ' . Yii::t('gromver.platform', 'Users'), ['index'], ['class' => 'btn btn-default', 'data-pjax' => 0]), 'after' => Html::a('<i class="glyphicon glyphicon-trash"></i> ' . Yii::t('gromver.platform', 'Delete'), ['bulk-delete'], ['class' => 'btn btn-danger', 'data-pjax' => '0', 'onclick' => 'processAction(this); return false']) . ' ' . Html::a('<i class="glyphicon glyphicon-open"></i> ' . Yii::t('gromver.platform', 'Restore'), ['bulk-restore'], ['class' => 'btn btn-default', 'data-pjax' => '0', 'onclick' => 'processAction(this); return false']) . ' ' . Html::a('<i class="glyphicon glyphicon-repeat"></i> ' . Yii::t('gromver.platform', 'Reset List'), ['index-trash'], ['class' => 'btn btn-info']), 'showFooter' => false]]);
?>

</div>
<script>
    function processAction(el) {
        var $el = $(el),
            $grid = $('#table-grid'),
            selection = $grid.yiiGridView('getSelectedRows')
        if(!selection.length) {