PUGX / PUGXMultiUserBundle

An extension for FOSUserBundle to handle users of different types. Compatible with Doctrine ORM.
163 stars 96 forks source link

Loading wrong template #83

Open radoslawkoziol opened 9 years ago

radoslawkoziol commented 9 years ago

Hi I found a problem,

Every register route loads wrong (default) tempate. I found that is caused by those lines in

RegistrationManager.php

    $result = $this->controller->registerAction($this->container->get('request'));
    if ($result instanceof RedirectResponse) {
        return $result;
    }

$this->controller->registerAction($this->container->get('request'));

This renders default register form and prevents to run this:

    $template = $this->userDiscriminator->getTemplate('registration');
    if (is_null($template)) {
        $engine = $this->container->getParameter('fos_user.template.engine');
        $template = 'FOSUserBundle:Registration:register.html.'.$engine;
    }

    $form = $this->formFactory->createForm();      
    return $this->container->get('templating')->renderResponse($template, array(
        'form' => $form->createView(),
    ));

That's because this in RegistrationController in FOSUserBundle if (null !== $event->getResponse()) { return $event->getResponse(); }

doesn't return null

When I delete wrong lines from RegistrationManager.php - everything works well.

Am I doing something wrong, or there is a bug?

Here is my config.yml

config.yml

pugx_multi_user:
  users:

    chiro:
        entity:
          class: Bos\UserBundle\Entity\Chiro
        registration:
          form:
            type: Bos\UserBundle\Form\RegistrationFormType
            name: bos_user_registration
            validation_groups:  [Registration, Default]
          template: BosUserBundle:Registration:register.html.twig

    patient:
        entity:
          class: Bos\UserBundle\Entity\Patient
        registration:
          template: BosUserBundle:Registration:register_patient.html.twig
          form:
            type: Bos\UserBundle\Form\RegistrationPatientFormType
            name: bos_user_registration_patient
greg-man commented 9 years ago

Same problem here, except when I remove the lines from RegistrationManager.php as you suggested, the form is not performed after submit. Instead it shows the empty registration form again.

Any ideas how to fix this?

greg-man commented 9 years ago

Well, found a solution by myself => need to check the request object for POST method, like so:

RegistrationManager.php (starting line 65)

$request = $this->container->get('request');
    if ($request->getMethod() == 'POST') {
        $result = $this->controller->registerAction($request);
        if ($result instanceof RedirectResponse) {
            return $result;
        }
    }

Maybe some official could check this issue (wether this is really a bug or OP and I are doing something wrong) and commit the suggested change?

leopro commented 9 years ago

@greg-man could you open a PR with the fix and a test to cover it?

greg-man commented 9 years ago

Too bad, as I dug further I found that the fix won't cover the problem fully. It still exists, when a form is submitted, but rejected for some constraints, e.g. duplicate email. Any ideas?

greg-man commented 9 years ago

Weird, don't know why, but custom templates are working now as expected. Must have done something wrong, doesn't seem to be a bug at all.