Browse Source

TakeOver the work of dShoreman, fix according to fosUser last version

Grégoire Hébert 7 years ago
parent
commit
4cfa42b99e

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

@@ -19,7 +19,7 @@
         </div>
     </div>
 
-    {% if not user.githubId %}
+    {% if not app.user.githubId %}
     <div class="form-group clearfix">
         {{ form_label(form.current_password) }}
         <div class="input-group">

+ 0 - 4
app/config/routing.yml

@@ -11,10 +11,6 @@ fos_user_profile_show:
     defaults: { _controller: PackagistWebBundle:User:myProfile }
     methods: [GET]
 
-fos_user_profile_edit:
-    pattern: /profile/edit/
-    defaults: { _controller: PackagistWebBundle:Profile:edit }
-
 fos_user_register:
     resource: '@FOSUserBundle/Resources/config/routing/registration.xml'
     prefix: /register

+ 0 - 34
src/Packagist/WebBundle/Controller/ProfileController.php

@@ -1,34 +0,0 @@
-<?php
-
-namespace Packagist\WebBundle\Controller;
-
-use FOS\UserBundle\Controller\ProfileController as BaseController;
-use FOS\UserBundle\Model\UserInterface;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-use Symfony\Component\Security\Core\Exception\AccessDeniedException;
-
-class ProfileController extends BaseController
-{
-    public function editAction()
-    {
-        $user = $this->container->get('security.context')->getToken()->getUser();
-        if (!is_object($user) || !$user instanceof UserInterface) {
-            throw new AccessDeniedException('This user does not have access to this section.');
-        }
-
-        $form = $this->container->get('fos_user.profile.form');
-        $formHandler = $this->container->get('fos_user.profile.form.handler');
-
-        $process = $formHandler->process($user);
-        if ($process) {
-            $this->setFlash('fos_user_success', 'profile.flash.updated');
-
-            return new RedirectResponse($this->getRedirectionUrl($user));
-        }
-
-        return $this->container->get('templating')->renderResponse(
-            'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'),
-            array('form' => $form->createView(), 'user' => $user)
-        );
-    }
-}

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

@@ -13,6 +13,7 @@
 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;
@@ -25,15 +26,14 @@ class ProfileFormType extends BaseType
 {
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
-        $builder->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
-                ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'));
+        $this->buildUserForm($builder, $options);
 
         $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event)
         {
-            if ( ! ($user = $event->getData())) return;
+            if ( ! ($user = $event->getData())) { return; }
 
             if ( ! $user->getGithubId()) {
-                $event->getForm()->add('current_password', 'password', array(
+                $event->getForm()->add('current_password', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'), array(
                     'label' => 'form.current_password',
                     'translation_domain' => 'FOSUserBundle',
                     'mapped' => false,