Integrating FosUserBundle with FosRestBundle

Does anyone have an example or any idea how to implement a FOSRestBundle with a FOSUserBundle. I have a web application already developed with Symfony 2 and FOSUserBundle, but I would like to add a FOSRestBundle for the api layer. I want to be able to pass him a username and password and get some type of token from FOSUserBundle, which represents a registered user, which I can then transfer and transfer between other api calls. Does anyone know a good way to do this?

+5
source share
1 answer

FOSUserBundle should be initially “calm”, which means that it can follow the recommendations of REST.

FOSRestBundle, - UserController Bundle .

, RESTFul, :

    public function postUsersAction()
    {
        $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();
            $authUser = false;

            if ($confirmationEnabled) {
            } else {
                $authUser = true;
            }

            $response = new Response();

            if ($authUser) {
                /* @todo Implement authentication */
                //$this->authenticateUser($user, $response);
            }

            $response->setStatusCode(Codes::HTTP_CREATED);
            $response->headers->set(
                'Location',
                $this->generateUrl(
                    'api_users_get_user',
                    array('user' => $user->getId()),
                    true
                )
            );

            return $response;
        }

        return RestView::create($form, Codes::HTTP_BAD_REQUEST);
    }
+3

All Articles