title: Automatically login in Symfony2 with FOSUserBundle
body: <p>I have created an individual sign up mechanism in my Symfony2 app (using FOSUserBundle) which exists in addition to the regular registration.</p>
  
  <p>Is there any way - after I have created and persisted the User to the database - to automatically login that current user. And after that the User shall be redirected to a page which requires a logged in user (and due to the automatical login, the User can access that page)?</p>
  
  <p>This is basically my method to create the user:</p>
  
  <pre><code>public function signupAction(Request $request) {
      $user = new User();
  
      $form = $this-&gt;createFormBuilder($user)
                  -&gt;...()
                  -&gt;getForm();
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid()) {
          // Enable User
          $user-&gt;setEnabled(true);
  
          // Persist to DB
          $em-&gt;persist($user);
          $em-&gt;flush();
  
          // Here I need the auto-login before redirecting to _root
  
          return $this-&gt;redirect($this-&gt;generateUrl('_root'));
      }
  
      return $this-&gt;render('MyBundle:MyController:signup.html.twig', array(
          'form' =&gt; $form-&gt;createView()
      ));
  }
  </code></pre>