Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.16 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class AppController extends Controller {
  2.        
  3.     public $components = array(
  4.         'Session',
  5.         'Auth' => array(
  6.             'loginRedirect' => array('controller' => '/', 'action' => '/'),
  7.             'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
  8.                 'authError' => "You can't access that page",
  9.                 'authorize' => array('Controller')
  10.         )
  11.     );
  12.    
  13.     public function isAuthorized($user) {  
  14.  
  15.         // let everyone onto the pages
  16.         if ($this->request['controller'] == "pages") return true;
  17.  
  18.         // if the user is an admin, they can do all.           
  19.         if($this->Auth->user('group') == 'admin') return true;
  20.  
  21.         if(!empty($this->permissions[$this->action])){
  22.             if($this->permissions[$this->action] == '*') return true;
  23.             if(in_array($this->Auth->user('group'), $this->permissions[$this->action])) return true;
  24.         }
  25.         return false;
  26.     }
  27.  
  28.     public function beforeFilter() {
  29.                        
  30.         $this->Auth->allow('index', 'view', 'denied', 'archive');                      
  31.                 $this->set('logged_in', $this->Auth->loggedIn());
  32.                 $this->set('current_user', $this->Auth->user());
  33.     }
  34. }