title: Simple login form in Symfony2
body: <p>I've been looking for solution but couldn't find any answer which would fix my problem. I have the simpliest form login ( still learning symfony2 ) and I have no idea why it's not working.</p>
  
  <p>My <strong>security.yml</strong></p>
  
  <pre><code>security:
  encoders:
      Symfony\Component\Security\Core\User\User: plaintext
  
  role_hierarchy:
      ROLE_ADMIN:       ROLE_USER
      ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  
  providers:
      in_memory:
          memory:
              users:
                  user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                  admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
  
  firewalls:
      secured_area:
          pattern:    ^/profile
          provider: in_memory
          form_login:
              check_path: _security_check
              login_path: _portal_login
  
              username_parameter: _username
              password_parameter: _password
  
  access_control:
      - { path: ^/profile, roles: ROLE_ADMIN }
  </code></pre>
  
  <p>My <strong>DefaultController</strong> :</p>
  
  <pre><code>class DefaultController extends Controller
  { 
  
   /**
   * @Route("/login", name="_portal_login")
   * @Template()
   */
  public function indexAction(Request $request)
  {  
      $request = $this-&gt;getRequest();
      $session = $request-&gt;getSession();
  
      // get the login error if there is one
      if ($request-&gt;attributes-&gt;has(SecurityContext::AUTHENTICATION_ERROR)) {
          $error = $request-&gt;attributes-&gt;get(
              SecurityContext::AUTHENTICATION_ERROR
          );
      } else {
          $error = $session-&gt;get(SecurityContext::AUTHENTICATION_ERROR);
          $session-&gt;remove(SecurityContext::AUTHENTICATION_ERROR);
      }
  
  
      return array(
          'last_username' =&gt; $request-&gt;getSession()-&gt;get(SecurityContext::LAST_USERNAME),
          'error'         =&gt; $error
      );
  
  }
  
   /**
   * @Route("/login_check", name="security_check")
   */
  public function securityCheckAction()
  {
  }
  
  /**
   * @Route("/profile", name="profile_main")
   * @Template()
   */
  public function profileAction()
  {  
      return array();
  }
  }
  </code></pre>
  
  <p>and view of my <strong>login form</strong></p>
  
  <pre><code>{% if error %}
  &lt;div&gt;{{ error.message }}&lt;/div&gt;
  {% endif %}
  
  &lt;form action="{{ path("security_check") }}" method="post" id="login"&gt;
  &lt;label for="username"&gt;Username:&lt;/label&gt;
  &lt;input type="text" id="username" name="_username" value="{{ last_username }}" /&gt;
  
  &lt;label for="password"&gt;Password:&lt;/label&gt;
  &lt;input type="password" id="password" name="_password" /&gt;
  
  &lt;button type="submit"&gt;login&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>As I said - as simple as it can be, and after clicking "login" I get <strong>exception</strong>:</p>
  
  <pre><code>The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
  </code></pre>
  
  <p><strong>EDIT !!!!</strong></p>
  
  <p>JUST FOUND A SOLUTION:
  You need to edit security.yml so provider is in form_login section ^^</p>