title: CakePHP login method read session if exists for redirect
body: <p>I have disabled <code>autoRedirect</code> so I can do some extra jazz in the login method of my users controller and use a Session to send them back to where they came from.</p>
  
  <pre><code>class UsersController extends AppController
  {
      var $name = 'Users';
  
      var $components = array('Session');
  
      function beforeFilter()
      {
          parent::beforeFilter();
  
          $this-&gt;Auth-&gt;allow(array('login','logout','admin_logout','admin_login')); 
  
          $this-&gt;Session-&gt;write('back_to', $this-&gt;referer());
      }
  
      /**
       * Log in
       */
  
      function admin_login ()
      {
          $this-&gt;set('title_for_layout', 'Log in &amp;ndash; Admin &amp;mdash;');
  
          if(!(empty($this-&gt;data)) &amp;&amp; $this-&gt;Auth-&gt;user())
          {   
  
              $back_to = $this-&gt;Session-&gt;read('back_to');
  
              if($back_to)
              {
                  $this-&gt;redirect($back_to, null, true);
              }
              else
              {
                  $this-&gt;redirect($this-&gt;Auth-&gt;redirect(), null, true);
              }
          }
  
          if($this-&gt;Auth-&gt;user())
          {
              $this-&gt;redirect($this-&gt;Auth-&gt;redirect(), null, true);
          }
  
      }
  </code></pre>
  
  <p>So the idea is that if a user has the session (99.% of the time) then on submit of form it will send the user TO the previous page, if not then send to the default loginRedirect.</p>
  
  <p><strong>NOTE: by setting <code>autoRedirect</code> to false, CakePHP no longer uses the <code>Auth.Redirect</code> session! So the value stored there is not used by the app anymore and is intentional!</strong></p>
  
  <p>The problem I am having is that my app is ALWAYS sending the user to the dashboard because of the function below 'This one' comment in the code above. If I remove that function then the user is just sent BACK to the login form all the time BUT they will be logged in!</p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks</p>
  
  <p>UPDATE: here is my appcontroller code:</p>
  
  <pre><code>class AppController extends Controller
  {
      var $components = array('Auth','Session');
  
          public function beforeFilter()
          {
  
              parent::beforeFilter();
  
              $this-&gt;Auth-&gt;authorize = 'controller';
  
              $this-&gt;Auth-&gt;autoRedirect = false;
  
              $this-&gt;Auth-&gt;loginAction = array('controller'=&gt;'users','action'=&gt;'login','admin'=&gt;true
              );
  
              $this-&gt;Auth-&gt;loginRedirect = array('admin'=&gt;true,'controller' =&gt; 'dashboard', 'action' =&gt; 'index');
  
              $this-&gt;Auth-&gt;logoutRedirect = array('admin'=&gt;false,'controller' =&gt; 'pages', 'action' =&gt; 'display','home');
          }
  
      function isAuthorized()
      {
          return true;
      }
  }
  </code></pre>