Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
Expand Down Expand Up @@ -214,16 +213,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'Form\\'
);

/*
* @legacy Conditional can be removed when MakerBundle no longer
* supports Symfony < 5.2
*/
$passwordHasher = UserPasswordEncoderInterface::class;

if (interface_exists(UserPasswordHasherInterface::class)) {
$passwordHasher = UserPasswordHasherInterface::class;
}

$useStatements = new UseStatementGenerator([
AbstractController::class,
$userClassNameDetails->getFullName(),
Expand All @@ -239,7 +228,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
ResetPasswordControllerTrait::class,
ResetPasswordExceptionInterface::class,
ResetPasswordHelperInterface::class,
$passwordHasher,
UserPasswordHasherInterface::class,
EntityManagerInterface::class,
]);

Expand Down Expand Up @@ -269,9 +258,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'from_email_name' => $this->fromEmailName,
'email_getter' => $this->emailGetterMethodName,
'email_field' => $this->emailPropertyName,
'password_hasher_class_details' => ($passwordClassDetails = $generator->createClassNameDetails($passwordHasher, '\\')),
'password_hasher_variable_name' => str_replace('Interface', '', sprintf('$%s', lcfirst($passwordClassDetails->getShortName()))), // @legacy see passwordHasher conditional above
'use_password_hasher' => UserPasswordHasherInterface::class === $passwordHasher, // @legacy see passwordHasher conditional above
'problem_validate_message_or_constant' => $problemValidateMessageOrConstant,
'problem_handle_message_or_constant' => $problemHandleMessageOrConstant,
'translator_available' => $isTranslatorAvailable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function checkEmail(): Response
* Validates and process the reset URL that the user clicked in their email.
*/
#[Route('/reset/{token}', name: 'app_reset_password')]
public function reset(Request $request, <?= $password_hasher_class_details->getShortName() ?> <?= $password_hasher_variable_name ?><?php if ($translator_available): ?>, TranslatorInterface $translator<?php endif ?>, string $token = null): Response
public function reset(Request $request, UserPasswordHasherInterface $passwordHasher<?php if ($translator_available): ?>, TranslatorInterface $translator<?php endif ?>, string $token = null): Response
{
if ($token) {
// We store the token in session and remove it from the URL, to avoid the URL being
Expand Down Expand Up @@ -94,7 +94,7 @@ public function reset(Request $request, <?= $password_hasher_class_details->getS
$this->resetPasswordHelper->removeResetRequest($token);

// Encode(hash) the plain password, and set it.
$encodedPassword = <?= $password_hasher_variable_name ?>-><?= $use_password_hasher ? 'hashPassword' : 'encodePassword' ?>(
$encodedPassword = $passwordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
);
Expand Down
32 changes: 14 additions & 18 deletions tests/Maker/MakeResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ public function getTestDetails(): \Generator

$this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']);

$this->runResetPasswordTest($runner, 'it_generates_with_normal_setup.php');
$runner->writeFile(
'config/packages/mailer.yaml',
Yaml::dump(['framework' => [
'mailer' => ['dsn' => 'null://null'],
]])
);

$runner->copy(
'make-reset-password/tests/it_generates_with_normal_setup.php',
'tests/ResetPasswordFunctionalTest.php'
);

$runner->runTests();
}),
];

Expand Down Expand Up @@ -105,6 +117,7 @@ public function getTestDetails(): \Generator

$this->assertStringContainsString('Success', $output);

// @legacy - conditional can be removed when PHPUnit 9.x is no longer supported.
if (method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist($runner->getPath('config/packages/reset_password.yaml'));
} else {
Expand Down Expand Up @@ -184,23 +197,6 @@ public function getTestDetails(): \Generator
];
}

private function runResetPasswordTest(MakerTestRunner $runner, string $filename): void
{
$runner->writeFile(
'config/packages/mailer.yaml',
Yaml::dump(['framework' => [
'mailer' => ['dsn' => 'null://null'],
]])
);

$runner->copy(
'make-reset-password/tests/'.$filename,
'tests/ResetPasswordFunctionalTest.php'
);

$runner->runTests();
}

private function makeUser(MakerTestRunner $runner, string $identifier = 'email', string $userClass = 'User', bool $checkPassword = true): void
{
$runner->runConsole('make:user', [
Expand Down