فهرست منبع

Fix impl in #895

Jordi Boggiano 5 سال پیش
والد
کامیت
e1a7e235a2

+ 19 - 6
src/Packagist/WebBundle/Form/Type/ProfileFormType.php

@@ -18,6 +18,8 @@ use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\FormEvent;
 use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
+use Symfony\Component\Validator\Constraints\NotBlank;
+use Symfony\Component\Form\Extension\Core\Type\PasswordType;
 
 /**
  * @author Jordi Boggiano <j.boggiano@seld.be>
@@ -28,16 +30,27 @@ class ProfileFormType extends BaseType
     {
         $this->buildUserForm($builder, $options);
 
-        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event)
-        {
-            if ( ! ($user = $event->getData())) { return; }
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
+            if (!($user = $event->getData())) {
+                return;
+            }
+
+            if (!$user->getGithubId()) {
+                $constraintsOptions = array(
+                    'message' => 'fos_user.current_password.invalid',
+                );
 
-            if ( ! $user->getGithubId()) {
-                $event->getForm()->add('current_password', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'), array(
+                $event->getForm()->add('current_password', PasswordType::class, array(
                     'label' => 'form.current_password',
                     'translation_domain' => 'FOSUserBundle',
                     'mapped' => false,
-                    'constraints' => new UserPassword(),
+                    'constraints' => array(
+                        new NotBlank(),
+                        new UserPassword($constraintsOptions),
+                    ),
+                    'attr' => array(
+                        'autocomplete' => 'current-password',
+                    ),
                 ));
             }
         });

+ 1 - 1
src/Packagist/WebBundle/Resources/config/services.yml

@@ -166,7 +166,7 @@ services:
     packagist.profile.form.type:
         public: true
         class: Packagist\WebBundle\Form\Type\ProfileFormType
-        arguments: ['%fos_user.model.user.class%', '@security.context']
+        arguments: ['%fos_user.model.user.class%']
         tags:
             - { name: form.type, alias: packagist_user_profile }
 

+ 4 - 0
src/Packagist/WebBundle/Resources/public/css/main.css

@@ -537,6 +537,10 @@ button {
     font-family: 'Open Sans', sans-serif;
 }
 
+.form-group {
+    clear: left;
+}
+
 .form-control {
     min-height: 20px;
     padding: 7px 11px 6px 9px;