public function getUser() { if ($this->_user == null) { $this->_user = User::findByEmail($this->email); } return $this->_user; }
public function actionConfirm($id, $token) { $user = User::find()->where(['id' => $id, 'confirmation_token' => $token])->one(); if ($user === null || !$user->confirm()) { return $this->render('invalidToken'); } return $this->render('finish'); }
/** * @inheritdoc */ public function rules() { return [['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'exist', 'targetClass' => \Yii::$app->user->identityClass, 'message' => Yii::t('users', 'There is no user with such email.')], ['email', function ($attribute) { $this->_user = User::findByEmail($this->email); if ($this->_user !== null && $this->getModule()->confirmable && !$this->_user->getIsConfirmed()) { $this->addError($attribute, Yii::t('users', 'You need to confirm your email address')); } }], ['password', 'required', 'on' => 'reset'], ['password', 'string', 'min' => 6, 'on' => 'reset']]; }
public function beforeValidate() { if (parent::beforeValidate()) { $this->user = User::findByUsername($this->login); return true; } else { return false; } }
/** * Displays page where user can reset password. * * @param $id * @param $token * @return string * @throws \yii\web\NotFoundHttpException */ public function actionReset($id, $token) { $model = new RecoveryForm(['scenario' => 'reset']); $user = User::find()->where(['id' => $id, 'recovery_token' => $token])->one(); if (!$user) { return $this->render('invalidToken'); } if ($model->load(\Yii::$app->getRequest()->post()) && $user->resetPassword($model->password)) { return $this->render('finish'); } return $this->render('reset', ['model' => $model]); }
/** * Redirects to current user's profile. * * @return \yii\web\Response */ public function actionIndex($id = null) { if (is_null($id)) { $id = Yii::$app->user->id; } $model = User::find()->where(['id' => $id])->one(); $model->setScenario('update'); $profile = $model->profile ? $model->profile : new Profile(); $profile->setScenario($profile->isNewRecord ? 'insert' : 'update'); $models = ['User' => $model, 'Profile' => $profile]; if (Yii::$app->request->isPjax && $_POST['removeAvatar']) { $profile->setScenario('removeAvatar'); $session = Yii::$app->session; $profile->avatar = null; if ($profile->update()) { $session->setFlash('success', 'Аватар успешно удалён.'); } return $this->renderAjax('@app/views/layouts/response.php'); } if (Yii::$app->request->isPjax && Model::loadMultiple($models, Yii::$app->request->post(), '') && Model::validateMultiple($models)) { $session = Yii::$app->session; $languageChanged = $profile->isAttributeChanged('language'); $profile->upload(); if ($model->update() || $profile->save()) { $session->setFlash('success', 'Данные пользователя успешно обновлены.'); if ($languageChanged) { return $this->refresh(); } } echo $this->renderAjax('@app/views/layouts/response.php'); $model = User::find()->where(['id' => $id])->one(); $model->setScenario('update'); $profile = $model->profile ? $model->profile : new Profile(); return $this->renderPartial('index', ['model' => $model, 'profile' => $profile]); } if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } return $this->render('index', ['model' => $model, 'profile' => $profile]); }
<?php $this->title = 'менеджер пользователей'; $this->params['breadcrumbs'][] = $this->title; use yii\grid\GridView; use yii\data\ActiveDataProvider; use yii\bootstrap\Button; use kartik\widgets\Select2; yii\widgets\PjaxAsset::register($this); $dataProvider = new ActiveDataProvider(['query' => \fourteenmeister\users\models\User::find(), 'pagination' => ['pageSize' => 20]]); echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', 'username', 'email', ['class' => 'yii\\grid\\DataColumn', 'header' => 'статус', 'content' => function ($model, $key, $index, $column) { return Select2::widget(['model' => $model, 'attribute' => 'status', 'data' => [0 => 'удалён', 1 => 'забанен', 2 => 'не активен', 10 => 'активен'], 'options' => ['id' => 'status-' . $model->id], 'pluginEvents' => ["change" => "function(val, added, removed) {\n \$.pjax({\n url: 'users',\n container: '#response',\n method: 'POST',\n data: {\n User: {\n id: {$model->id},\n status: val.val\n }\n }\n })\n }"], 'pluginOptions' => ['minimumResultsForSearch' => -1, 'allowClear' => false]]); }, 'headerOptions' => ['class' => 'text-center', 'style' => 'width: 200px;']], ['class' => 'yii\\grid\\DataColumn', 'header' => 'действия', 'content' => function ($model, $key, $index, $column) { return Button::widget(['label' => 'Профиль', 'id' => 'profile_' . $model->id, 'tagName' => 'a', 'options' => ['href' => \yii\helpers\Url::to(['/users/profile', 'id' => $model->id]), 'class' => 'btn-info']]); }, 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']]]]);