/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = Member::findOne(['status' => Member::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['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 resetPasswordMail() { $this->scenario = 'resetPassword'; $this->attributes = Yii::$app->request->post(); if ($this->validate()) { $user = static::findByEmail(['email' => $this->email, 'status' => self::STATUS_ACTIVE]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } // $this->db->createCommand()->update('user', [ // 'email' => $this->email, // 'status' => User::STATUS_NOT_ACTIVE, // 'created_at' => time(), // ])->execute(); if ($user->save()) { Yii::$app->session->setFlash('success', 'Спасибо! На ваш Email было отправлено письмо со ссылкой на восстановление пароля.'); \Yii::$app->mailer->compose(['text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); Yii::$app->response->redirect('/index'); } } else { Yii::$app->session->setFlash('error', 'Извините. У нас возникли проблемы с отправкой.'); } } else { print_r($this->errors); } }