title: How can you test whether a user is active in Cakephp 2.0 auth component?
body: <p>I'm having trouble hashing out how to test whether a user is active using the new Auth component. I have 3 states a user can be in: 0 unactivated (default), 1 activated, 2 deactivated. I'm trying to implement this in the login function so I can return whether they haven't registered or have been banned. </p>
  
  <p><strong>Login</strong>:</p>
  
  <pre><code>        public function login() {
          if ($this-&gt;request-&gt;is('post')) {
              if($this-&gt;Auth-&gt;login()) {                   
                  $results = $this-&gt;User-&gt;find('all', array(
                      'conditions' =&gt; array('User.email' =&gt; $this-&gt;Auth-&gt;user('email')),
                      'fields' =&gt; array('User.is_active')
                  ));
                  if ($results['User']['is_active'] == 0) {
                      // User has not confirmed account
                      $this-&gt;Session-&gt;setFlash('Your account has not been activated. Please check your email.');
                      $this-&gt;Auth-&gt;logout();
                      $this-&gt;redirect(array('action'=&gt;'login'));
                  }
                 // not working atm
                  else if ($results['User']['is_active'] == 2) {
                      // User has been deactivated
                      $this-&gt;Session-&gt;setFlash('Your account has been deactivated. Contact site admin if you believe this is in error.');
                      $this-&gt;Auth-&gt;logout();
                      $this-&gt;redirect(array('action'=&gt;'login'));
                  }
                  else if ($results['User']['is_active'] == 1) {
                      // User is active
                        $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
                      }
              } else {
                  $this-&gt;Session-&gt;setFlash(__('Your email/password combination was incorrect'));
              }
          }
      }
  </code></pre>
  
  <p>Can't see where I've gone wrong. Users with admin privileges and activated users are still getting the unactivated account error. </p>
  
  <p><strong>Update</strong></p>
  
  <p>Decided to drop the User.is_active field and handle it all in roles. I'm handling it in the AppController and it is almost working now. In the isAuthorized function, it now throws errors if the user is banned or unactivated, but I need it to log them out as well.</p>
  
  <pre><code>    public function isAuthorized($user) {
      // This isAuthorized determines what logged in users are able to see on ALL controllers. Use controller
      // by controller isAuthorized to limit what they can view on each one. Basically, you do not want to allow
      // actions on all controllers for users. Only admins can access every controller.
      if (isset($user['role']) &amp;&amp; $user['role'] === 'admin') {
          return true; //Admin can access every action
      }
      elseif (isset($user['role']) &amp;&amp; $user['role'] === 'unactivated') { // Account has not been activated
          $this-&gt;Session-&gt;setFlash("You haven't activated your account yet. Please check your email.");
          return false; 
      }
      elseif (isset($user['role']) &amp;&amp; $user['role'] === 'banned') { // Your account has been banned
          $this-&gt;Session-&gt;setFlash("You're account has been banned. If you feel this was an error, please contact the site administrator.");
          return false;
      }
      return false; // The rest don't
  }
  </code></pre>