title: Checking user role on login using CakePHP?
body: <p>I want to create an admin panel for my site, for this I've created <code>admin.ctp</code>. In DB table name user contain column <code>role</code>, where role=admin/regular(user).</p>
  
  <p>There is only one login form, and the question is, Is it possible to place a 'check' that if <code>user.role=admin</code> then redirect to the <code>admin/user/dashboard</code> and if <code>user.role=regular</code> then <code>layout=default</code>? my AppController.php contains:</p>
  
  <pre><code>function beforeFilter(){
      $this-&gt;Auth-&gt;allow('index','view','login','home');
      $this-&gt;set('admin',$this-&gt;_isAdmin());
  
      $this-&gt;set('logged_in',$this-&gt;Auth-&gt;loggedIn());
      $this-&gt;set('current_user',$this-&gt;Auth-&gt;User());
      if ((isset($this-&gt;params['prefix']) &amp;&amp; ($this-&gt;params['prefix'] == 'admin'))) {
          $this-&gt;layout = 'admin';
      }
  </code></pre>
  
  <p>And usersController.php</p>
  
  <pre><code>function beforeFilter(){
      parent::beforeFilter();
      $this-&gt;Auth-&gt;allow('*');
      if($this-&gt;action=='add' || $this-&gt;action=='edit'){
          $this-&gt;Auth-&gt;authenticate=$this-&gt;User;
      }
  }
  
  function login(){
      if(!($this-&gt;Auth-&gt;loggedIn())){
          if ($this-&gt;request-&gt;is('post')) {
              if ($this-&gt;Auth-&gt;login()) {
                  if($user['role'] === 'admin'){
                      $this-&gt;redirect($this-&gt;Auth-&gt;redirect('admin',array('controller' =&gt; 'user','action' =&gt; 'admin_dashboard')));
                  }
                  $this-&gt;redirect($this-&gt;Auth-&gt;redirect(array('controller' =&gt; 'posts','action' =&gt; 'index')));
              } else {
                  $this-&gt;Session-&gt;setFlash('Your username/password combination was incorrect.',
                      'alert',array(
                          'plugin' =&gt; 'TwitterBootstrap',
                          'class' =&gt; 'alert-error'
                      ));
                  $this-&gt;set('forget', 'Forgot Your Password');
  
              }
          }
      }else
      {
          $this-&gt;redirect($this-&gt;Auth-&gt;redirect(array('controller' =&gt; 'posts','action' =&gt; 'index')));
      }
  }
  </code></pre>
  
  <p>using cakephp 2.2.3.
  thanks in advance!</p>