public function testSendEmailCorrectUser()
 {
     $model = new PasswordResetRequestForm();
     $model->email = $this->user[0]['email'];
     $user = User::findOne(['passwordResetToken' => $this->user[0]['passwordResetToken']]);
     expect('email sent', $model->send())->true();
     expect('user has valid token', $user->passwordResetToken)->notNull();
     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['appEmail']);
     expect('message "to" is correct', $message)->contains($model->email);
 }
Ejemplo n.º 2
0
 /**
  * Requests password reset.
  * @return mixed response
  */
 public function actionRequestPasswordReset()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new PasswordResetRequestForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->send()) {
             Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
             return $this->goHome();
         } else {
             Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
         }
     }
     return $this->render('requestPasswordResetToken', ['model' => $model]);
 }