/** * Lists all Estate models. * * @return mixed */ public function actionIndex() { $searchModel = new EstateSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $user = User::findOne(Yii::$app->user->id); $isManager = LinkManager::isAccessible($user->id); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'user' => $user, 'isManager' => $isManager]); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /** @var User $user */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { $user->generatePasswordResetToken(); if ($user->save()) { return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * Редактируем пользователя */ public function actionEdit() { // Выбераем текущего пользователя if ($model = User::findOne(Yii::$app->user->id)) { $model->setScenario('edit'); if ($model->load(Yii::$app->request->post()) && $model->save()) { // В случае успешного обновления данных, оповещаем пользователя об этом, и перенаправляем его на страницу профиля. Yii::$app->session->setFlash('success', Yii::t('user', 'Данные профиля были успешно обновлены!')); return $this->redirect(['view', 'username' => $model->username]); } // Рендерим представление. return $this->render('edit', ['model' => $model]); } }
public function testSendEmailCorrectUser() { $model = new PasswordResetRequestForm(); $model->email = $this->user[0]['email']; $user = User::findOne(['password_reset_token' => $this->user[0]['password_reset_token']]); expect('email sent', $model->sendEmail())->true(); expect('user has valid token', $user->password_reset_token)->notNull(); $this->specify('message has correct format', function () use($model) { expect('message file exists', file_exists($this->getMessageFile()))->true(); $message = file_get_contents($this->getMessageFile()); expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']); expect('message "to" is correct', $message)->contains($model->email); }); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /** @var $user User * */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'phone' => $this->phone]); if ($user && !($this->haveEmail = mb_strlen($user->getEmail()) > 5)) { return false; } if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=UTF-8\r\n"; $headers .= "From: Bulk.kz ROBOT <*****@*****.**>\r\n"; return mail($user->getEmail(), Yii::t('app', 'RESET_EMAIL_SUBJECT') . $user->getUsername(), Yii::t('app', 'RESET_EMAIL_MESSAGE') . Html::a(Yii::t('app', 'RESET_EMAIL_LINK'), 'http://bulk.kz/reset-password?token=' . $user->getPasswordResetToken()), $headers); } return false; }
/** * 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('The requested page does not exist.'); } }
public function actionServiceItem($id) { $service = Services::findOne($id); if ($service && !\Yii::$app->user->isGuest) { $user = User::findOne(\Yii::$app->user->id); $persAcc = PersonalAccount::find()->where('user_id = :user_id', [':user_id' => $user->id])->andWhere('service_id = :service_id', [':service_id' => $id])->one(); $history = PaymentData::find()->where('service_id = :service_id', [':service_id' => $id])->andWhere('personal_acc_id = :personal_acc_id', [':personal_acc_id' => $persAcc->id])->all(); return $this->render('service-item', ['service' => $service, 'history' => $history, 'persAcc' => $persAcc]); } else { return false; } }
/** * Getter current User * * @return User */ public function getUser() { return User::findOne($this->user_id); }
<?php use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\ActiveForm; use yii\web\JsExpression; use yii\widgets\Pjax; use common\modules\user\models\User; /** * @var $this yii\web\View * @var $comments array Array of common\models\Comment * @var $commentForm common\models\Comment **/ $user = User::findOne(Yii::$app->user->id); $avatar = $user->getAsset(); ?> <?php $form = ActiveForm::begin(['id' => 'comment-form', 'options' => ['class' => 'default-form'], 'action' => Url::to('/site/comment-add')]); ?> <div class="user-photo"> <a href="<?php echo Url::to(['user/profile']); ?> "><img src="<?php echo $avatar->getFileUrl(); ?> "></a> </div> <div class="field textarea-field comment-field">