diff --git a/src/Cli/Commands/User/Add.php b/src/Cli/Commands/User/Add.php index 133aee2..af052f4 100644 --- a/src/Cli/Commands/User/Add.php +++ b/src/Cli/Commands/User/Add.php @@ -20,7 +20,7 @@ use Symfony\Component\Console\Question\Question as QuestionInput; #[AsCommand('user:add', 'Add a new user associated with an OAuth client')] class Add extends Command { - public function __invoke(ClimateOutput|ArgvInput|InputInterface $input, ClimateOutput $output): int + public function __invoke(ClimateOutput|ArgvInput|InputInterface $input, $output): int { $client = $this->askForClient($output, $input); if (!$client) { diff --git a/src/Cli/Commands/User/ResetPassword.php b/src/Cli/Commands/User/ResetPassword.php index 7385388..2d87f06 100644 --- a/src/Cli/Commands/User/ResetPassword.php +++ b/src/Cli/Commands/User/ResetPassword.php @@ -7,6 +7,7 @@ namespace Siteworxpro\App\Cli\Commands\User; use Siteworxpro\App\Cli\ClimateOutput; use Siteworxpro\App\Cli\Commands\Command; use Siteworxpro\App\CommandBus\Commands\SendPasswordReset; +use Siteworxpro\App\Mailer\Message; use Siteworxpro\App\Services\Facades\CommandBus; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\QuestionHelper; @@ -41,9 +42,13 @@ class ResetPassword extends Command } if ($input->getOption('send-email')) { - CommandBus::handle(new SendPasswordReset($user, $client)); + /** @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; } diff --git a/src/CommandBus/Handlers/SendPasswordResetHandler.php b/src/CommandBus/Handlers/SendPasswordResetHandler.php index 37c360b..28ae898 100644 --- a/src/CommandBus/Handlers/SendPasswordResetHandler.php +++ b/src/CommandBus/Handlers/SendPasswordResetHandler.php @@ -23,7 +23,7 @@ class SendPasswordResetHandler extends CommandHandler /** * @throws RandomException */ - public function __invoke(Command|SendPasswordReset $command): User + public function __invoke(Command|SendPasswordReset $command): Message { if (!$command instanceof SendPasswordReset) { throw new CommandHandlerException('Invalid command type provided to handler.'); @@ -33,13 +33,23 @@ class SendPasswordResetHandler extends CommandHandler $content = Twig::render('password-reset.twig', [ 'user' => $command->getUser(), - 'resetLink' => Config::get('app.url') . '/reset-password?token=' . $token, + 'resetLink' => sprintf( + '%s/authorize?token=%s&client_id=%s&response_type=code&redirect_uri=%s#/password-reset', + Config::get('app.url'), + $token, + $command->getClient()->client_id, + urlencode($command->getClient()->clientRedirectUris->first()->redirect_uri) + ), 'client' => $command->getClient() ]); + $from = $command->getClient()->capabilities->toArray()['support_email'] != '' + ? $command->getClient()->capabilities->toArray()['support_email'] + : Config::get('app.default_support_email'); + $message = new Message( $command->getUser()->email, - $command->getClient()->capabilities->toArray()['support_email'] ?? Config::get('app.default_support_email'), + $from, 'Password Reset Request', $content ); @@ -50,6 +60,6 @@ class SendPasswordResetHandler extends CommandHandler Redis::set('password_reset:' . $command->getUser()->id, $token, 'EX', Redis::MINUTE * 15); - return $command->getUser(); + return $message; } } diff --git a/src/Mailer/Templates/password-reset.twig b/src/Mailer/Templates/password-reset.twig index 14dd0fe..960e090 100644 --- a/src/Mailer/Templates/password-reset.twig +++ b/src/Mailer/Templates/password-reset.twig @@ -5,7 +5,7 @@ {% endblock %} {% block body %} -

Dear {{ user.firstName }},

+

{{ user.first_name }},

We received a request to reset your password. Click the link below to set a new password: