Skip to content

Commit 062542a

Browse files
committed
adjustments from review
1 parent b1581ca commit 062542a

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
];

0 commit comments

Comments
 (0)