Configure FOSUserBundle Registration

What I'm trying to do is not complicated. This is my first symfony project and it is really confusing.

I am using FOSUSerbundle. I do not want to have registration and registration below /login and /registration

So, I made a bunch, which is a child of the FOSUSerbundle ... and it overrides its branches.

I have :: base.html.twig where I include header.html.twig, and there I have: {% render 'FOSUserBundle:Security:login' %} that displays my tag (overridden by FOS), gr8 works . Even errors after sending are displayed on the :: base template below "/".

 #Security.yml form_login: check_path: /login_check login_path: / provider: fos_userbundle 

It works great.

And I need to do the same for my registration.

So, in ::base I include welcome_page.html.twig , where I code {% render 'FOSUserBundle:Registration:register' %} , and I have under my rewritten template: WelcomePageBundle:Registration:register.html.twig this:

 {% block fos_user_content %} {% include "FOSUserBundle:Registration:register_content.html.twig" %} {% endblock fos_user_content %}[/code] 

which also include MY rewritten package: WelcomePageBundle:Registration:register_content.html.twig this:

 {% for key, message in app.session.getFlashes() %} <div class="{{ key }}"> {{ message|trans({}, 'FOSUserBundle') }} </div> {% endfor %} <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" id="register_form"> {{ form_widget(form) }} {{ form_rest(form) }} <input type="submit" class="registration_submit" value="{{ 'welcome_page.registration_box.register_submit'|trans }}"/> </form> <div class="v_pripade"> {{ 'welcome_page.registration_box.with_reg_problems'|trans }} <span style='color: #fff568'>{{ 'welcome_page.registration_box.with_reg_problems_part2'|trans }}</span> </div> 

Everything works like a charm ... all files are included and displayed greate. But the problem is now.

When I go to the /register route

(which is the main route from the FOS package)

 <route id="fos_user_registration_register" pattern="/register"> <default key="_controller">FOSUserBundle:Registration:register</default> </route> 

... fill in the data and click "Submit ...". Errors are displayed or successful registration occurs.

But when I submit the form from my route / , where the registration handler is displayed (displayed normally), it accepts my route :/register , which is normal behavior, because this path:

 <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" id="register_form"> 

... this site is not expanding anything, so its just a clean form on a white page with errors ... OK

But how can I do the work with this form with the display of errors and successes on the MY :: base template, for example, at login? and don’t go to the /register route? I tried replacing /register with / , which led me to my ::base pattern (e.g. when logging in).

 #security.yml form_login: check_path: /login_check login_path: / provider: fos_userbundle 

But none of the errors or results are displayed ...

Does anyone know a solution?

+7
source share
1 answer

You will find the official documentation on how to override the standard FOSUserBundle controllers at http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html

Create a controller for your home page and forward requests ( http://symfony.com/doc/master/book/controller.html#forwarding ) to the FOSUserBundle registration controller or add logic to your own controller after execution FOSUserBundle does during registration:

 <?php namespace Acme\UserBundle\Controller; // Imports @route annotation use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class CustomRegistrationController extends BaseController { /** * @Route("/") */ public function register() { $response = $this->forward('FOSUserBundle:Registration:register'); return $response; } } 

or

 <?php namespace Acme\UserBundle\Controller; use Symfony\Component\HttpFoundation\RedirectResponse; use FOS\UserBundle\Controller\RegistrationController as BaseController; class RegistrationController extends BaseController { public function registerAction() { $form = $this->container->get('fos_user.registration.form'); $formHandler = $this->container->get('fos_user.registration.form.handler'); $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled'); $process = $formHandler->process($confirmationEnabled); if ($process) { $user = $form->getData(); /***************************************************** * Add new functionality (eg log the registration) * *****************************************************/ $this->container->get('logger')->info( sprintf('New user registration: %s', $user) ); if ($confirmationEnabled) { $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail()); $route = 'fos_user_registration_check_email'; } else { $this->authenticateUser($user); $route = 'fos_user_registration_confirmed'; } $this->setFlash('fos_user_success', 'registration.flash.user_created'); $url = $this->container->get('router')->generate($route); return new RedirectResponse($url); } return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array( 'form' => $form->createView(), )); } } 
+4
source

All Articles