Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - [make:reset-password] handle multiple entities #1527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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