addOption( 'send-email', 's', InputOption::VALUE_NONE, description: 'Send password reset email to the user' ); } public function __invoke($input, $output): int { $client = $this->askForClient($output, $input); if (!$client) { $output->error('Client not found.'); return \Symfony\Component\Console\Command\Command::FAILURE; } $user = $this->askForUser($client, $output, $input); if (!$user) { $output->error('User not found for the specified client.'); return \Symfony\Component\Console\Command\Command::FAILURE; } if ($input->getOption('send-email')) { /** @var Message $message */ $message = CommandBus::handle(new SendPasswordReset($user, $client)); $output->info('Password reset email sent to the user.'); $output->info('Email Subject: ' . $message->getSubject()); $output->info('Email Body: ' . $message->getBody()); return \Symfony\Component\Console\Command\Command::SUCCESS; } /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new QuestionInput('Enter the new password: '); $question->setValidator(function ($input): string { if (empty($input) || strlen($input) < 8) { throw new \InvalidArgumentException('Password must be at least 8 characters long.'); } return $input; }); $question->setHidden(true); $question->setHiddenFallback(false); $newPassword = $helper->ask($input, $output, $question); $user->password = $newPassword; $user->save(); $output->info('Password has been reset successfully.'); return \Symfony\Component\Console\Command\Command::SUCCESS; } }