Skip to content

Instantly share code, notes, and snippets.

@ceeram
Created January 3, 2012 21:12
Show Gist options
  • Save ceeram/1556959 to your computer and use it in GitHub Desktop.
Save ceeram/1556959 to your computer and use it in GitHub Desktop.
example for loggin in guests in CakePHP 2.x
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Auth' => array(
'authorize' => 'Controller',
),
'Session'
);
public function beforeFilter() {
if ($this->action != 'login' && !$this->Auth->user()) {
$this->Auth->login('guest');
}
}
public function isAuthorized() {
$role = $this->Auth->user('role');
if ($role == 'admin') {
return true;
} elseif ($role == 'user') {
if (in_array($this->action, array('edit', 'delete'))) {
return false;
}
return true;
}
if (in_array($this->action, array('index', 'view'))) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment