password reset

This commit is contained in:
2026-01-29 22:34:15 -05:00
parent 8dbf3c22b6
commit 96409973bf
4 changed files with 22 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ use Symfony\Component\Console\Question\Question as QuestionInput;
#[AsCommand('user:add', 'Add a new user associated with an OAuth client')] #[AsCommand('user:add', 'Add a new user associated with an OAuth client')]
class Add extends Command 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); $client = $this->askForClient($output, $input);
if (!$client) { if (!$client) {

View File

@@ -7,6 +7,7 @@ namespace Siteworxpro\App\Cli\Commands\User;
use Siteworxpro\App\Cli\ClimateOutput; use Siteworxpro\App\Cli\ClimateOutput;
use Siteworxpro\App\Cli\Commands\Command; use Siteworxpro\App\Cli\Commands\Command;
use Siteworxpro\App\CommandBus\Commands\SendPasswordReset; use Siteworxpro\App\CommandBus\Commands\SendPasswordReset;
use Siteworxpro\App\Mailer\Message;
use Siteworxpro\App\Services\Facades\CommandBus; use Siteworxpro\App\Services\Facades\CommandBus;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\QuestionHelper;
@@ -41,9 +42,13 @@ class ResetPassword extends Command
} }
if ($input->getOption('send-email')) { 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('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; return \Symfony\Component\Console\Command\Command::SUCCESS;
} }

View File

@@ -23,7 +23,7 @@ class SendPasswordResetHandler extends CommandHandler
/** /**
* @throws RandomException * @throws RandomException
*/ */
public function __invoke(Command|SendPasswordReset $command): User public function __invoke(Command|SendPasswordReset $command): Message
{ {
if (!$command instanceof SendPasswordReset) { if (!$command instanceof SendPasswordReset) {
throw new CommandHandlerException('Invalid command type provided to handler.'); throw new CommandHandlerException('Invalid command type provided to handler.');
@@ -33,13 +33,23 @@ class SendPasswordResetHandler extends CommandHandler
$content = Twig::render('password-reset.twig', [ $content = Twig::render('password-reset.twig', [
'user' => $command->getUser(), '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() '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( $message = new Message(
$command->getUser()->email, $command->getUser()->email,
$command->getClient()->capabilities->toArray()['support_email'] ?? Config::get('app.default_support_email'), $from,
'Password Reset Request', 'Password Reset Request',
$content $content
); );
@@ -50,6 +60,6 @@ class SendPasswordResetHandler extends CommandHandler
Redis::set('password_reset:' . $command->getUser()->id, $token, 'EX', Redis::MINUTE * 15); Redis::set('password_reset:' . $command->getUser()->id, $token, 'EX', Redis::MINUTE * 15);
return $command->getUser(); return $message;
} }
} }

View File

@@ -5,7 +5,7 @@
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<p>Dear {{ user.firstName }},</p> <p>{{ user.first_name }},</p>
<p>We received a request to reset your password. Click the link below to set a new password:</p> <p>We received a request to reset your password. Click the link below to set a new password:</p>