0
votes

I want to create some permission to my site in cakephp but not works permission check. I want only for example allow only the page add the other page like index or register doesn't have access.

This is my AppController component

public $components = array(
        'Session',
        'Auth' => array(
            'loginAction' => array('controller'=>'users','action'=>'login', 'admin'=>false),
            'logoutRedirect' => array('controller'=>'users','action'=>'logout'),
            'loginRedirect' => array('controller'=>'shows', 'action'=>'index'),
            'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
            'autoRedirect' => false,
            'authorize' => array(
                'Controller',
                'Actions' => array(
                    'actionPath' => 'controllers'
                )
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        )
    );

And this is the beforeFilter inside UserController:

public function beforeFilter () {
   parent::beforeFilter();  
   $this->Auth->deny('*'); //I have also tried $this->Auth->deny();
   $this->Auth->allow('register');
}

Why I can access to the other pages? Thanks

2

2 Answers

0
votes

From Cakephp book: By default all actions require authorization. However, after making actions public, you want to revoke the public access. You can do so using AuthComponent::deny(): What you are doing with deny is probably only because of lack of knowledge how Auth works. Please check this http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html $this->Auth->deny(); // Will remove all the actions.

0
votes

You should use Acl Component of cakephp which gives you a perfect scenario in which you can decide for which page you should give permission and which not

Read this:- http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html

and then invoke component in AppController

class AppController extends Controller {

public $components = array(
    'Acl'

}