* @copyright (c), Thread */ class PasswordResetRequestForm extends CommonForm { /** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ /** * @return array */ public function rules() { return ArrayHelper::merge(parent::rules(), [ [['email'], 'trim'], ['email', 'exist', 'targetClass' => User::class, 'targetAttribute' => 'email'], ]); } /** * Создаем токкен для сброса пароля * @return bool */ public function generateResetToken() { $success = false; $user = $this->getUserByEmail(); if ($user) { $user->setScenario('resetPassword'); $user->generatePasswordResetToken(); if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } $success = $user->save(); } return $success; } /** * @return bool */ public function sendEmail() { /** @see runtime/fronend/debug/mail directory */ return Yii::$app ->mailer ->compose( ['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $this->getUserByEmail()] ) ->setFrom(['support@email.ua']) ->setTo($this->email) ->setSubject('Password reset for ' . \Yii::$app->name) ->send(); } /** * @return array */ public function scenarios() { return [ 'remind' => ['email'], ]; } }