title: Why is my CakePHP login script not working?
body: <p>I am working on my first CakePHP project. I have only ever worked in procedural PHP before and I haven't dealt with anything like the Cake framework, so am having a few teething problems. I'd greatly appreciate help with my login script, which is not working.</p>
  
  <p>My app will be a system for rugby clubs. As such, the login page requires the user to select their club from a drop-down and then enter a password. </p>
  
  <p><strong>Edited:</strong></p>
  
  <p>Working as follows:</p>
  
  <p><strong>/App/Webroot/View/Clubs/login.ctp</strong></p>
  
  <pre><code>  &lt;div class="clubs form"&gt;
  &lt;?php echo $this-&gt;Session-&gt;flash('auth'); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;create('Club'); ?&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;&lt;?php echo __('Please select your club and enter your password'); ?&gt;&lt;/legend&gt;
  
          &lt;table&gt;
  
             &lt;tr&gt; 
  
                  &lt;?php 
                  echo $this-&gt;Form-&gt;input('id', array('label' =&gt; 'Club name', 'before' =&gt; '&lt;td&gt;', 'after' =&gt; '&lt;/td&gt;', 'between' =&gt; '&lt;/td&gt;&lt;td&gt;', 'type'=&gt;'select','options'=&gt;$clubs)); 
             ?&gt;
             &lt;tr&gt;
                 &lt;?php echo $this-&gt;Form-&gt;input('password', array( 'before' =&gt; '&lt;td&gt;', 'after' =&gt; '&lt;/td&gt;', 'between' =&gt; '&lt;/td&gt;&lt;td&gt;')); 
             ?&gt;
             &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/fieldset&gt;
  &lt;?php echo $this-&gt;Form-&gt;end(__('Login')); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>/App/Controller/AppController.php</strong></p>
  
  <pre><code>    public $components = array(
       'Session',
          'Auth' =&gt; array(
              'authenticate' =&gt; array(
                  'Form' =&gt; array(
                      'userModel' =&gt; 'Club',
                      'fields' =&gt; array(
                          'username' =&gt; 'id',
                          'password' =&gt; 'password'
                      )
                  )
              ),
              'loginRedirect' =&gt; array('controller' =&gt; 'clubs', 'action' =&gt; 'index'),
              'logoutRedirect' =&gt; array('controller' =&gt; 'pages', 'action' =&gt; 'display', 'home'),
              'loginAction' =&gt; array('admin' =&gt; false, 'controller' =&gt; 'clubs', 'action' =&gt; 'login')
          ),
         'DebugKit.Toolbar'
     );
  
      public function beforeFilter() {
          parent::beforeFilter();
          $this-&gt;Auth-&gt;allow('logout', 'display');
      }
  </code></pre>
  
  <p><strong>/App/Controller/ClubsController.php</strong></p>
  
  <pre><code>    public function login() {
  
      if ($this-&gt;request-&gt;is('post')) {
  
          if ($this-&gt;Auth-&gt;login()) {
              return $this-&gt;redirect($this-&gt;Auth-&gt;redirectUrl());         
          } 
          else {
              $this-&gt;Session-&gt;setFlash(__('Invalid club or password, try again.', 'default', array(), 'auth'));
              $this-&gt;set('clubs', $this-&gt;Club-&gt;find(
                  'list', array(
                      'fields' =&gt; array('club_name'),
                      'conditions' =&gt; array('status' =&gt; '2')
                      )
                    )
              );
          }
      }
      else {
          $this-&gt;set('clubs', $this-&gt;Club-&gt;find(
              'list', array(
                  'fields' =&gt; array('club_name'),
                  'conditions' =&gt; array('status' =&gt; '2')
                  )
              )
          );
      }
  
  }
  
  public function logout() {
      $this-&gt;Session-&gt;setFlash(__('You have been logged out.'));
      $this-&gt;redirect($this-&gt;Auth-&gt;logout());
  }
  
  public function beforeFilter() {
      parent::beforeFilter();
      $this-&gt;Auth-&gt;allow('add', 'login', 'index', 'logout', 'view');
  }
  </code></pre>