Exemplo n.º 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.';
     }
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         $query->andWhere('status!=:status', [':status' => User::STATUS_DELETED]);
         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 (strlen($this->status) === 0) {
         $query->andWhere('status!=:status', [':status' => User::STATUS_DELETED]);
     }
     if (count($this->getRoles())) {
         $auth = Yii::$app->authManager;
         $query->leftJoin($auth->assignmentTable . ' roles', 'roles.user_id=id');
         $query->andWhere(['roles.item_name' => $this->getRoles()]);
     }
     return $dataProvider;
 }
Exemplo n.º 4
0
 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)) {
         return Yii::$app->mailer->compose('@gromver/platform/frontend/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;
 }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'created_by']);
 }
Exemplo n.º 6
0
    </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' => 'yii\\grid\\CheckboxColumn'], ['attribute' => 'id', 'width' => '50px'], 'username', 'email:email', ['attribute' => 'status', 'value' => function ($model) {
    /** @var User $model */
    return $model->getStatusLabel();
}, 'filter' => ['' => 'Не выбрано'] + User::statusLabels()], ['attribute' => 'roles', 'value' => function ($model) {
    /** @var User $model */
    return implode(", ", $model->getRoles());
}, 'filter' => \yii\helpers\ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')], ['class' => 'kartik\\grid\\ActionColumn', 'template' => '{params} {view} {update} {delete}', 'deleteOptions' => ['data-method' => 'delete'], 'buttons' => ['params' => function ($url, $model, $key) {
    /** @var User $model */
    return Html::a('<i class="glyphicon glyphicon-user"></i>', ['params', 'id' => $model->id]);
}]]], '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-plus"></i> ' . Yii::t('gromver.platform', 'Add'), ['create'], ['class' => 'btn btn-success', '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-repeat"></i> ' . Yii::t('gromver.platform', 'Reset List'), ['index'], ['class' => 'btn btn-info']), 'showFooter' => false]]);
?>

</div>
<script>
    function processAction(el) {
        var $el = $(el),
            $grid = $('#table-grid'),
            selection = $grid.yiiGridView('getSelectedRows')
        if(!selection.length) {
Exemplo n.º 7
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\common\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']);
Exemplo n.º 8
0
 /**
  * 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.'));
     }
 }