'admin' will only allow users with the role admin to access action_adminpanel * 'moderatorpanel' => array('login', 'moderator') will only allow users with the roles login and moderator to access action_moderatorpanel * * @var array actions that require a valid user */ protected $secure_actions = array(); /** * Check and see if this controller needs authentication * * if $this->auth_required is TRUE, then the user must be logged in only. * if $this->auth_required is FALSE, AND $this->secure_actions has an array of * methods set to TRUE, then the user must be logged in AND a member of the * role. * * @return boolean */ protected function _auth_required() { // If our global configurable is disabled, then continue if (! Kohana::$config->load('config')->method_security) return FALSE; return (($this->auth_required !== FALSE && Auth::instance()->logged_in() === FALSE) || (is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) && Auth::instance()->logged_in($this->secure_actions[$this->request->action()]) === FALSE)); } public function before() { parent::before(); // Check user auth and role if ($this->_auth_required()) { // For AJAX/JSON requests, authorisation is controlled in the method. if (Request::current()->is_ajax() && $this->request->action() === 'json') { // Nothing required. // For no AJAX/JSON requests, display an access page } elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) { HTTP::redirect('login/noaccess'); } else { Session::instance()->set('afterlogin',Request::detect_uri()); HTTP::redirect($this->noauth_redirect); } } } public function after() { parent::after(); // Generate and check the ETag for this file $this->check_cache(sha1($this->response->body())); } } ?>