public function __construct($token, $config = []) { if (empty($token) || !is_string($token)) { throw new InvalidParamException('Неверный token сброса пароля'); } $this->_user = users::findOne(['forgotten_password_code' => $token]); if (!$this->_user) { throw new InvalidParamException('Неверный token сброса пароля'); } parent::__construct($config); }
public function passReset() { $user = users::findOne(['active' => Users::STATUS_ACTIVE, 'username' => $this->username, 'email' => $this->email]); if ($user) { if (empty($user->forgotten_password_code)) { $user->forgotten_password_code = Yii::$app->security->generateRandomString(); } if ($user->save()) { return \Yii::$app->mailer->compose('passReset', ['user' => $user])->setFrom([Yii::$app->params['adminEmail'] => 'Sportforecast'])->setTo($user->email)->setSubject('Восстановление пароля')->send(); } } return false; }