Reputation: 974
I made the cakephp acl controlled application tutorial
my problem is at this step:
Our controllers and models are now prepped for adding some initial data, and our Group and User models are bound to the Acl table. So add some groups and users using the baked forms by browsing to http://example.com/groups/add and http://example.com/users/add. I made the following groups:
when I try to open */groups/add or */users/add i get the error "You are not authorized to access that location."
how I can solve the problem?
here my GroupModel and UserModel.
Group:
<?php
App::uses('AppModel', 'Model');
/**
* Group Model
*
*/
class Group extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'name';
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
return null;
}
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}
}
User:
<?php
App::uses('AppModel', 'Model');
/**
* User Model
*
*/
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
public $belongsTo = array('Group');
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
if (!$this->id && empty($this->data)) {
return null;
}
if (isset($this->data['User']['group_id'])) {
$groupId = $this->data['User']['group_id'];
} else {
$groupId = $this->field('group_id');
}
if (!$groupId) {
return null;
} else {
return array('Group' => array('id' => $groupId));
}
}
public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}
}
Upvotes: 0
Views: 1500
Reputation: 9398
did you read the whole chapter you linked? About half page you find this rows, I guess it's what you need
Before we set up the ACL at all we will need to add some users and groups. With AuthComponent in use we will not be able to access any of our actions, as we are not logged in. We will now add some exceptions so AuthComponent will allow us to create some groups and users. In both your GroupsController and your UsersController Add the following:
public function beforeFilter() {
parent::beforeFilter();
// For CakePHP 2.0
$this->Auth->allow('*');
// For CakePHP 2.1 and up
$this->Auth->allow();
}
Upvotes: 1