public function actionRequestPasswordReset() { $model = new PasswordResetRequestForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail()) { Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); return $this->goHome(); } else { Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); } } return $this->render('requestPasswordResetToken', ['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); }); }
public function actionForgot_password() { $this->layout = 'login'; $model = new PasswordResetRequestForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendMail()) { Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); return $this->redirect(Yii::$app->urlManager->createAbsoluteUrl('site/login')); } else { Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); } } return $this->render('requestPasswordResetToken', ['model' => $model]); }
/** * Generate and send token to user's email for resetting password. * * @return string|\yii\web\Response */ public function actionRequestPasswordReset() { // Change layout and body class of register page $this->layout = 'blank'; Yii::$app->params['bodyClass'] = 'register-page'; $model = new PasswordResetRequestForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail()) { Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); return $this->goHome(); } else { Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); } } return $this->render('request-password-reset-token', ['model' => $model]); }
public function actionRepass() { $model = new PasswordResetRequestForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail()) { Yii::$app->getSession()->setFlash('repass-success', 'На Email выслано письмо с дальнейшими инструкциями.'); } else { Yii::$app->getSession()->setFlash('repass-error', 'Ошибка восстановления пароля. Обратитесь к администратору.'); } return $this->redirect(['/repass']); } return $this->render('requestPasswordResetToken', ['model' => $model]); }