Added autocomplete attributes on password change form in user settings.

This commit is contained in:
Jan Böhmer 2019-12-23 19:00:27 +01:00
parent 10ca895309
commit eb3c34b75f

View file

@ -34,9 +34,11 @@ use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator; use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator;
use Symfony\Component\Asset\Packages; use Symfony\Component\Asset\Packages;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType; use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -193,9 +195,17 @@ class UserController extends AdminPages\BaseAdminController
$demo_mode = $this->getParameter('demo_mode'); $demo_mode = $this->getParameter('demo_mode');
$pw_form = $this->createFormBuilder() $pw_form = $this->createFormBuilder()
//Username field for autocomplete
->add('username', TextType::class, [
'data' => $user->getName(),
'attr' => ['autocomplete' => 'username'],
'disabled' => true,
'row_attr' => ['class' => 'd-none']
])
->add('old_password', PasswordType::class, [ ->add('old_password', PasswordType::class, [
'label' => 'user.settings.pw_old.label', 'label' => 'user.settings.pw_old.label',
'disabled' => $demo_mode, 'disabled' => $demo_mode,
'attr' => ['autocomplete' => 'current-password'],
'constraints' => [new UserPassword()], ]) //This constraint checks, if the current user pw was inputted. 'constraints' => [new UserPassword()], ]) //This constraint checks, if the current user pw was inputted.
->add('new_password', RepeatedType::class, [ ->add('new_password', RepeatedType::class, [
'disabled' => $demo_mode, 'disabled' => $demo_mode,
@ -203,10 +213,13 @@ class UserController extends AdminPages\BaseAdminController
'first_options' => ['label' => 'user.settings.pw_new.label'], 'first_options' => ['label' => 'user.settings.pw_new.label'],
'second_options' => ['label' => 'user.settings.pw_confirm.label'], 'second_options' => ['label' => 'user.settings.pw_confirm.label'],
'invalid_message' => 'password_must_match', 'invalid_message' => 'password_must_match',
'options' => [
'attr' => ['autocomplete' => 'new-password']
],
'constraints' => [new Length([ 'constraints' => [new Length([
'min' => 6, 'min' => 6,
'max' => 128, 'max' => 128,
])], ])],
]) ])
->add('submit', SubmitType::class, ['label' => 'save']) ->add('submit', SubmitType::class, ['label' => 'save'])
->getForm(); ->getForm();