Skip to content

Commit 3ebc8fd

Browse files
committed
adjustments from review
1 parent 01e09c5 commit 3ebc8fd

File tree

17 files changed

+38
-126
lines changed

17 files changed

+38
-126
lines changed

src/Resources/scaffolds/6.0/bootstrapcss.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
return $data;
3030
});
3131

32-
// add bootstrap to app.css
33-
$files->dumpFile('assets/styles/app.css', "@import \"~bootstrap/dist/css/bootstrap.css\";\n");
34-
3532
// add bootstrap to app.js
3633
$appJs = $files->getFileContents('assets/app.js');
3734

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "~bootstrap/dist/css/bootstrap.css";

src/Resources/scaffolds/6.0/change-password.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
],
1717
'packages' => [
1818
'symfony/form' => 'all',
19-
'symfony/validator' => 'all',
2019
],
2120
];

src/Resources/scaffolds/6.0/change-password/src/Controller/ChangePasswordController.php.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ChangePasswordController extends AbstractController
2727
throw new \LogicException('Invalid user type.');
2828
}
2929

30-
$form = $this->createForm(ChangePasswordFormType::class, $user);
30+
$form = $this->createForm(ChangePasswordFormType::class);
3131
$form->handleRequest($request);
3232

3333
if ($form->isSubmitted() && $form->isValid()) {

src/Resources/scaffolds/6.0/change-password/src/Form/ChangePasswordFormType.php.tpl

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace App\Form;
44

55
use Symfony\Component\Form\AbstractType;
66
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
7-
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
87
use Symfony\Component\Form\FormBuilderInterface;
98
use Symfony\Component\OptionsResolver\OptionsResolver;
109
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
@@ -20,31 +19,20 @@ class ChangePasswordFormType extends AbstractType
2019
'constraints' => [
2120
new UserPassword(['message' => 'This is not your current password.']),
2221
],
23-
'mapped' => false,
2422
])
25-
->add('plainPassword', RepeatedType::class, [
26-
'type' => PasswordType::class,
27-
'first_options' => [
28-
'attr' => ['autocomplete' => 'new-password'],
29-
'constraints' => [
30-
new NotBlank([
31-
'message' => 'Please enter a password.',
32-
]),
33-
new Length([
34-
'min' => 6,
35-
'minMessage' => 'Your password should be at least {{ limit }} characters',
36-
// max length allowed by Symfony for security reasons
37-
'max' => 4096,
38-
]),
39-
],
40-
],
41-
'second_options' => [
42-
'attr' => ['autocomplete' => 'new-password'],
23+
->add('plainPassword', PasswordType::class, [
24+
'attr' => ['autocomplete' => 'new-password'],
25+
'constraints' => [
26+
new NotBlank([
27+
'message' => 'Please enter a password.',
28+
]),
29+
new Length([
30+
'min' => 6,
31+
'minMessage' => 'Your password should be at least {{ limit }} characters',
32+
// max length allowed by Symfony for security reasons
33+
'max' => 4096,
34+
]),
4335
],
44-
'invalid_message' => 'The password fields must match.',
45-
// Instead of being set onto the object directly,
46-
// this is read and encoded in the controller
47-
'mapped' => false,
4836
])
4937
;
5038
}

src/Resources/scaffolds/6.0/change-password/templates/user/change_password.html.twig.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
{{ form_start(changePasswordForm) }}
1111
{{ form_row(changePasswordForm.currentPassword, {label: 'Current Password'}) }}
12-
{{ form_row(changePasswordForm.plainPassword.first, {label: 'New Password'}) }}
13-
{{ form_row(changePasswordForm.plainPassword.second, {label: 'Repeat New Password'}) }}
12+
{{ form_row(changePasswordForm.plainPassword, {label: 'New Password'}) }}
1413

1514
<button type="submit" class="btn btn-primary">Change Password</button>
1615
{{ form_end(changePasswordForm) }}

src/Resources/scaffolds/6.0/change-password/tests/Functional/ChangePasswordTest.php.tpl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ final class ChangePasswordTest extends KernelTestCase
2727
->visit('/user/change-password')
2828
->fillField('Current Password', '1234')
2929
->fillField('New Password', 'new-password')
30-
->fillField('Repeat New Password', 'new-password')
3130
->click('Change Password')
3231
->assertSuccessful()
3332
->assertOn('/')
@@ -56,7 +55,6 @@ final class ChangePasswordTest extends KernelTestCase
5655
->visit('/user/change-password')
5756
->fillField('Current Password', 'invalid')
5857
->fillField('New Password', 'new-password')
59-
->fillField('Repeat New Password', 'new-password')
6058
->click('Change Password')
6159
->assertStatus(422)
6260
->assertOn('/user/change-password')
@@ -76,7 +74,6 @@ final class ChangePasswordTest extends KernelTestCase
7674
->actingAs($user->object())
7775
->visit('/user/change-password')
7876
->fillField('New Password', 'new-password')
79-
->fillField('Repeat New Password', 'new-password')
8077
->click('Change Password')
8178
->assertStatus(422)
8279
->assertOn('/user/change-password')
@@ -106,27 +103,6 @@ final class ChangePasswordTest extends KernelTestCase
106103
$this->assertSame($currentPassword, $user->getPassword());
107104
}
108105

109-
public function testNewPasswordsMustMatch(): void
110-
{
111-
$user = UserFactory::createOne(['email' => '[email protected]', 'password' => '1234']);
112-
$currentPassword = $user->getPassword();
113-
114-
$this->browser()
115-
->actingAs($user->object())
116-
->visit('/user/change-password')
117-
->fillField('Current Password', '1234')
118-
->fillField('New Password', 'new-password')
119-
->fillField('Repeat New Password', 'different-new-password')
120-
->click('Change Password')
121-
->assertStatus(422)
122-
->assertOn('/user/change-password')
123-
->assertSee('The password fields must match.')
124-
->assertAuthenticated('[email protected]')
125-
;
126-
127-
$this->assertSame($currentPassword, $user->getPassword());
128-
}
129-
130106
public function testCannotAccessChangePasswordPageIfNotLoggedIn(): void
131107
{
132108
$this->browser()

src/Resources/scaffolds/6.0/profile.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
],
1717
'packages' => [
1818
'symfony/form' => 'all',
19-
'symfony/validator' => 'all',
2019
],
2120
];

src/Resources/scaffolds/6.0/profile/src/Form/ProfileFormType.php.tpl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ use App\Entity\User;
66
use Symfony\Component\Form\AbstractType;
77
use Symfony\Component\Form\FormBuilderInterface;
88
use Symfony\Component\OptionsResolver\OptionsResolver;
9-
use Symfony\Component\Validator\Constraints\NotBlank;
109

1110
class ProfileFormType extends AbstractType
1211
{
1312
public function buildForm(FormBuilderInterface $builder, array $options): void
1413
{
1514
$builder
16-
->add('name', null, [
17-
'constraints' => [
18-
new NotBlank(['message' => 'Name is required']),
19-
],
20-
])
15+
->add('name')
2116
;
2217
}
2318

src/Resources/scaffolds/6.0/register.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,12 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\Bundle\MakerBundle\FileManager;
13-
1412
return [
1513
'description' => 'Create registration form and tests.',
1614
'dependents' => [
1715
'auth',
1816
],
1917
'packages' => [
2018
'symfony/form' => 'all',
21-
'symfony/validator' => 'all',
2219
],
23-
'configure' => function (FileManager $files) {
24-
$userEntity = $files->getFileContents('src/Entity/User.php');
25-
26-
if (str_contains($userEntity, $attribute = "#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]")) {
27-
// unique constraint already there
28-
return;
29-
}
30-
31-
$userEntity = str_replace(
32-
[
33-
'#[ORM\Entity(repositoryClass: UserRepository::class)]',
34-
'use Doctrine\ORM\Mapping as ORM;',
35-
],
36-
[
37-
"#[ORM\Entity(repositoryClass: UserRepository::class)]\n{$attribute}",
38-
"use Doctrine\ORM\Mapping as ORM;\nuse Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;",
39-
],
40-
$userEntity
41-
);
42-
$files->dumpFile('src/Entity/User.php', $userEntity);
43-
},
4420
];

src/Resources/scaffolds/6.0/register/src/Form/RegistrationFormType.php.tpl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use Symfony\Component\Form\Extension\Core\Type\EmailType;
88
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
99
use Symfony\Component\Form\FormBuilderInterface;
1010
use Symfony\Component\OptionsResolver\OptionsResolver;
11-
use Symfony\Component\Validator\Constraints\Email;
1211
use Symfony\Component\Validator\Constraints\Length;
1312
use Symfony\Component\Validator\Constraints\NotBlank;
1413

@@ -17,17 +16,8 @@ class RegistrationFormType extends AbstractType
1716
public function buildForm(FormBuilderInterface $builder, array $options): void
1817
{
1918
$builder
20-
->add('name', null, [
21-
'constraints' => [
22-
new NotBlank(['message' => 'Name is required']),
23-
],
24-
])
25-
->add('email', EmailType::class, [
26-
'constraints' => [
27-
new NotBlank(['message' => 'Email is required']),
28-
new Email(['message' => 'This is not a valid email address']),
29-
],
30-
])
19+
->add('name')
20+
->add('email', EmailType::class)
3121
->add('plainPassword', PasswordType::class, [
3222
// instead of being set onto the object directly,
3323
// this is read and encoded in the controller

src/Resources/scaffolds/6.0/reset-password.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
],
1919
'packages' => [
2020
'symfony/form' => 'all',
21-
'symfony/validator' => 'all',
2221
'symfony/mailer' => 'all',
2322
'symfonycasts/reset-password-bundle' => 'all',
2423
'zenstruck/mailer-test' => 'dev',

src/Resources/scaffolds/6.0/reset-password/src/Form/ResetPasswordFormType.php.tpl

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace App\Form;
44

55
use Symfony\Component\Form\AbstractType;
66
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
7-
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
87
use Symfony\Component\Form\FormBuilderInterface;
98
use Symfony\Component\OptionsResolver\OptionsResolver;
109
use Symfony\Component\Validator\Constraints\Length;
@@ -15,35 +14,24 @@ class ResetPasswordFormType extends AbstractType
1514
public function buildForm(FormBuilderInterface $builder, array $options): void
1615
{
1716
$builder
18-
->add('plainPassword', RepeatedType::class, [
19-
'type' => PasswordType::class,
20-
'first_options' => [
21-
'attr' => ['autocomplete' => 'new-password'],
22-
'constraints' => [
23-
new NotBlank([
24-
'message' => 'Please enter a password',
25-
]),
26-
new Length([
27-
'min' => 6,
28-
'minMessage' => 'Your password should be at least {{ limit }} characters',
29-
// max length allowed by Symfony for security reasons
30-
'max' => 4096,
31-
]),
32-
],
17+
->add('plainPassword', PasswordType::class, [
18+
'attr' => ['autocomplete' => 'new-password'],
19+
'constraints' => [
20+
new NotBlank([
21+
'message' => 'Please enter a password',
22+
]),
23+
new Length([
24+
'min' => 6,
25+
'minMessage' => 'Your password should be at least {{ limit }} characters',
26+
// max length allowed by Symfony for security reasons
27+
'max' => 4096,
28+
]),
3329
],
34-
'second_options' => [
35-
'attr' => ['autocomplete' => 'new-password'],
36-
],
37-
'invalid_message' => 'The password fields must match.',
38-
// Instead of being set onto the object directly,
39-
// this is read and encoded in the controller
40-
'mapped' => false,
4130
])
4231
;
4332
}
4433

4534
public function configureOptions(OptionsResolver $resolver): void
4635
{
47-
$resolver->setDefaults([]);
4836
}
4937
}

src/Resources/scaffolds/6.0/reset-password/templates/reset_password/reset.html.twig.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
<h1>Reset your password</h1>
99

1010
{{ form_start(resetForm) }}
11-
{{ form_row(resetForm.plainPassword.first, {label: 'New Password'}) }}
12-
{{ form_row(resetForm.plainPassword.second, {label: 'Repeat New Password'}) }}
11+
{{ form_row(resetForm.plainPassword, {label: 'New Password'}) }}
1312
<button class="btn btn-primary">Reset password</button>
1413
{{ form_end(resetForm) }}
1514
</div>

src/Resources/scaffolds/6.0/reset-password/tests/Functional/ResetPasswordTest.php.tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ final class ResetPasswordTest extends KernelTestCase
5252
$this->browser()
5353
->visit($resetUrl)
5454
->fillField('New Password', 'new-password')
55-
->fillField('Repeat New Password', 'new-password')
5655
->click('Reset password')
5756
->assertOn('/')
5857
->assertSeeIn('.alert', 'Your password was successfully reset, you are now logged in.')

src/Resources/scaffolds/6.0/user.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'doctrine/orm' => 'all',
1616
'doctrine/doctrine-bundle' => 'all',
1717
'symfony/security-bundle' => 'all',
18+
'symfony/validator' => 'all',
1819
'phpunit/phpunit' => 'dev',
1920
'symfony/phpunit-bridge' => 'dev',
2021
'zenstruck/foundry' => 'dev',

src/Resources/scaffolds/6.0/user/src/Entity/User.php.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ namespace App\Entity;
44

55
use App\Repository\UserRepository;
66
use Doctrine\ORM\Mapping as ORM;
7+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
78
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
89
use Symfony\Component\Security\Core\User\UserInterface;
10+
use Symfony\Component\Validator\Constraints as Assert;
911

1012
#[ORM\Entity(repositoryClass: UserRepository::class)]
13+
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
1114
class User implements UserInterface, PasswordAuthenticatedUserInterface
1215
{
1316
#[ORM\Id]
@@ -16,9 +19,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
1619
private ?int $id = null;
1720
1821
#[ORM\Column(unique: true)]
22+
#[Assert\NotBlank(message: 'Email is required')]
23+
#[Assert\Email(message: 'This is not a valid email address')]
1924
private ?string $email = null;
2025
2126
#[ORM\Column]
27+
#[Assert\NotBlank(message: 'Name is required')]
2228
private ?string $name = null;
2329
2430
#[ORM\Column(type: 'json')]

0 commit comments

Comments
 (0)