FriendsOfSymfony / FOSUserBundle

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
MIT License
3.25k stars 1.57k forks source link

While registering an already existing username/email i got an error 500 (solved temporarely) #1870

Open pirasterize opened 9 years ago

pirasterize commented 9 years ago

The error I got is : An exception has been thrown during the rendering of a template ("You cannot change the data of a submitted form.") in SonataUserBundle:Security:base_login.html.twig at line 86.

capture d ecran 2015-06-23 a 12 51 51

basically is something about validation. I tried to find something similar in others issues but didn't find nothing. I m writing this post for people having same problem and for developers to offer further informations.

I run a "composer update" yesterday and now i m running with 2.7.1 of symfony here is my require section of composer.json :

"require": {
    "php": ">=5.3.3",

    "twig/twig": "~1.12",
    "twig/extensions": "~1.0",

    "symfony/symfony": "~2.5",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.3",

    "sensio/distribution-bundle": "~2.3",
    "sensio/framework-extra-bundle": "~2.3",
    "sensio/generator-bundle": "~2.4",

    "jms/security-extra-bundle": "~1.5",
    "jms/di-extra-bundle": "~1.4",
    "jms/serializer-bundle": "~0.11",

    "doctrine/orm": "~2.4",
    "doctrine/doctrine-bundle": "1.3.*@dev",
    "doctrine/doctrine-migrations-bundle": "~2.0@dev",
    "doctrine/migrations": "~1.0@dev",
    "doctrine/doctrine-fixtures-bundle": "~2.2",
    "doctrine/data-fixtures": "~1.0@dev",

    "symfony-cmf/routing-bundle": "~1.1",

    "knplabs/gaufrette": "~0.1.6",
    "knplabs/knp-menu-bundle": "~2.0",

    "sonata-project/easy-extends-bundle": "~2.1@dev",
    "sonata-project/seo-bundle": "~2.0@dev",
    "sonata-project/doctrine-extensions": "~1@dev",
    "sonata-project/intl-bundle": "~2.2@dev",
    "sonata-project/admin-bundle": "~2.4@dev",
    "sonata-project/doctrine-orm-admin-bundle": "~2.4@dev",
    "sonata-project/notification-bundle": "~2.2@dev",
    "sonata-project/block-bundle": "dev-master",
    "sonata-project/media-bundle": "~2.4@dev",
    "sonata-project/user-bundle": "^2.3@dev",
    "sonata-project/cache-bundle": "dev-master",
    "sonata-project/cache": "~1.0@dev",
    "sonata-project/page-bundle": "~2.4@dev",
    "sonata-project/core-bundle": "dev-master",
    "sonata-project/formatter-bundle": "~2.4@dev",
    "sonata-project/news-bundle": "2.4.*@dev",
    "sonata-project/datagrid-bundle": "~2.2@dev",
    "sonata-project/exporter": "~1.3@dev",
    "sonata-project/timeline-bundle": "~2.3@dev",
    "sonata-project/classification-bundle": "~2.3@dev",
    "sonata-project/ecommerce": "dev-develop",
    "sonata-project/comment-bundle": "~2.2@dev",

    "friendsofsymfony/comment-bundle": "~2.0@dev",

    "michelf/php-markdown": "1.4.1",
    "simplethings/entity-audit-bundle": "~0.5",
    "willdurand/faker-bundle": "~1.0",

    "mopa/bootstrap-bundle": "dev-master",
    "twbs/bootstrap": "master",

    "stof/doctrine-extensions-bundle": "~1.1",

    "incenteev/composer-parameter-handler": "~2.0",
    "sonata-project/google-authenticator": "~1.0",
    "friendsofsymfony/jsrouting-bundle": "~1.5",
    "egeloen/google-map": "~1.4",
    "widop/http-adapter": "~1.1",
    "willdurand/geocoder": "~2.8",
    "egeloen/google-map-bundle": "~2.2",
    "hwi/oauth-bundle": "0.4.*@dev",
    "lipis/bootstrap-social": "~4.8",
    "widop/google-analytics-bundle": "*"

},

I found a temporarely solution editing/overwriting the FOSUserBundle RegistrationFormHandler the process function :

public function process($confirmation = false)
{
    $user = $this->createUser();

    if(!$this->form->isSubmitted()) // <------ here is the line added
        $this->form->setData($user);

    if ('POST' === $this->request->getMethod()) {
        $this->form->bind($this->request);

        if ($this->form->isValid()) {
            $this->onSuccess($user, $confirmation);

            return true;
        }
    }

    return false;
}

That's all

stof commented 9 years ago

$this->form->isSubmitted() will always be false before the ->bind() call, so it is weird if it changes something here. something weird must be going on.

and the weird thing is that there is no call to form->setData on line 46 of the RegistrationFormHandler in 1.3.x. Which version of FOSUserBundle are you using ?

could you please give the full stack trace of exceptions instead of just an extract of the beginning ? this would help debugging. Recent versions of Symfony are providing a plain-text rendering of the stack trace at the bottom of the exception page btw.

pirasterize commented 9 years ago

Thanx for answer I'll try to give all possible info The version from composer.lock is :

        "name": "friendsofsymfony/user-bundle",
        "version": "v1.3.6",
        "target-dir": "FOS/UserBundle",
        "source": {
            "type": "git",
            "url": "https://github.com/FriendsOfSymfony/FOSUserBundle.git",
            "reference": "2022ac8463a8c50dd631f93a17064bd41795fff2"
        },

The line is 44th (was 46 because of my test) here is the stack :

     [1/2] AlreadySubmittedException: You cannot change the data of a submitted form.   -

in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 314 - // changed. In such cases (i.e. when the form is not initialized yet) don't // abort this method. if ($this->submitted && $this->defaultDataSet) { throw new AlreadySubmittedException('You cannot change the data of a submitted form.'); } // If the form inherits its parent's data, disallow data setting to at Form ->setData (object(User)) in vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Form/Handler/RegistrationFormHandler.php at line 44 - public function process($confirmation = false) { $user = $this->createUser(); $this->form->setData($user); if ('POST' === $this->request->getMethod()) { $this->form->bind($this->request); at RegistrationFormHandler ->process (false) in vendor/sonata-project/user-bundle/Controller/RegistrationFOSUser1Controller.php at line 48 + at RegistrationFOSUser1Controller ->registerAction () at call_user_func_array (array(object(RegistrationFOSUser1Controller), 'registerAction'), array()) in app/bootstrap.php.cache at line 3094 + at HttpKernel ->handleRaw (object(SiteRequest), '2') in app/bootstrap.php.cache at line 3056 + at HttpKernel ->handle (object(SiteRequest), '2', false) in app/bootstrap.php.cache at line 3207 + at ContainerAwareHttpKernel ->handle (object(SiteRequest), '2', false) in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php at line 85 + at InlineFragmentRenderer ->render (object(ControllerReference), object(SiteRequest), array('ignore_errors' => false)) in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php at line 118 + at FragmentHandler ->render (object(ControllerReference), 'inline', array()) in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/LazyLoadingFragmentHandler.php at line 56 + at LazyLoadingFragmentHandler ->render (object(ControllerReference), 'inline', array()) in vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php at line 64 + at ActionsExtension ->renderUri (object(ControllerReference), array()) in app/cache/dev/twig/4/1/410827eec24cd06b80fc0f0d925afe8584d4b954d1ec23ee8688c03134f0acac.php at line 213 +

a more clear stack with image (I couldn't paste correctly) :

capture d ecran 2015-06-23 a 15 33 31