Browse Source

Merge remote-tracking branch 'GregoireHebert/remove-password-with-github-auth'

Jordi Boggiano 5 years ago
parent
commit
0990c92d75

+ 2 - 0
app/Resources/FOSUserBundle/views/Profile/edit_content.html.twig

@@ -19,6 +19,7 @@
         </div>
     </div>
 
+    {% if not app.user.githubId %}
     <div class="form-group clearfix">
         {{ form_label(form.current_password) }}
         <div class="input-group">
@@ -27,6 +28,7 @@
             <span class="input-group-addon"><span class="icon-lock"></span></span>
         </div>
     </div>
+    {% endif %}
 
     <div class="notifications form-group">
         {{ form_errors(form.failureNotifications) }}

+ 20 - 4
src/Packagist/WebBundle/Form/Type/ProfileFormType.php

@@ -13,7 +13,11 @@
 namespace Packagist\WebBundle\Form\Type;
 
 use FOS\UserBundle\Form\Type\ProfileFormType as BaseType;
+use FOS\UserBundle\Util\LegacyFormHelper;
 use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\Form\FormEvents;
+use Symfony\Component\Form\FormEvent;
+use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
 
 /**
  * @author Jordi Boggiano <j.boggiano@seld.be>
@@ -22,11 +26,23 @@ class ProfileFormType extends BaseType
 {
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
-        parent::buildForm($builder, $options);
+        $this->buildUserForm($builder, $options);
 
-        $builder->add('failureNotifications', null, array(
-            'required' => false,
-        ));
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event)
+        {
+            if ( ! ($user = $event->getData())) { return; }
+
+            if ( ! $user->getGithubId()) {
+                $event->getForm()->add('current_password', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'), array(
+                    'label' => 'form.current_password',
+                    'translation_domain' => 'FOSUserBundle',
+                    'mapped' => false,
+                    'constraints' => new UserPassword(),
+                ));
+            }
+        });
+
+        $builder->add('failureNotifications', null, array('required' => false, 'label' => 'Notify me of package update failures'));
     }
 
     /**

+ 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%']
+        arguments: ['%fos_user.model.user.class%', '@security.context']
         tags:
             - { name: form.type, alias: packagist_user_profile }