Skip to content

Commit

Permalink
[make:reset-password] handle multiple entities
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow committed Apr 28, 2024
1 parent 1f02b59 commit 5ee5b7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
'What is the User entity that should be used with the "forgotten password" feature? (e.g. <fg=yellow>App\\Entity\\User</>)'
);

// @TODO - if more than 1 $providerData - ask if we should handle more than $this->userClass

$this->emailPropertyName = $interactiveSecurityHelper->guessEmailField($io, $this->userClass);
$this->emailGetterMethodName = $interactiveSecurityHelper->guessEmailGetter($io, $this->userClass, $this->emailPropertyName);
$this->passwordSetterMethodName = $interactiveSecurityHelper->guessPasswordSetter($io, $this->userClass);
Expand Down Expand Up @@ -284,6 +286,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'problem_validate_message_or_constant' => $problemValidateMessageOrConstant,
'problem_handle_message_or_constant' => $problemHandleMessageOrConstant,
'translator_available' => $isTranslatorAvailable,
'multiple_entities' => false,
]
);

Expand Down Expand Up @@ -482,6 +485,14 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r

$manipulator->addUseStatementIfNecessary($userClassDetails->getFullName());

/**
* @TODO - If Multiple Entities
* 1) $user -> `nullable: true`
* 2) add "other" user ManyToOne
* 3) __construct(User|OTHER_USER $user) { $user instanceOf User ? $this->user = $user : $this->OTHER_USER = $user }
* 4) getUser(): User|OTHER_USER
*/

$manipulator->addConstructor([
(new Param('user'))->setType($userClassDetails->getShortName())->getNode(),
(new Param('expiresAt'))->setType('\DateTimeInterface')->getNode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI
$user = $this->entityManager->getRepository(<?= $user_class_name ?>::class)->findOneBy([
'<?= $email_field ?>' => $emailFormData,
]);
<?php if ($multiple_entities:) ?>

if (null === $user) {
$user = $this->entityManager->getRepository(ANOTHER_USER::class)->findOneBy([
'email' => $emailFormData,
]);
}
<?php endif ?>

// Do not reveal whether a user account was found or not.
if (!$user) {
Expand Down

0 comments on commit 5ee5b7f

Please sign in to comment.