Cakephp group permissions

I would like to have group-based restrictions that allow users to access only certain parts of the network. I am new to all ACL stuff, and I didn't quite understand this from the manual: / so I would like to ask a few questions.

But before any questions, my routes look like this:

Router::connect('/', array('controller' => 'users', 'action' => 'login'));
Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin', 'admin' => true));
Router::connect('/registered/:controller/:action/*', array('prefix' => 'registered', 'registered' => true));

1.) How to restrict users from any other group than Administratorto get ONLY part of the /registered/web page

2.) How can I prevent anyone from using default addresses, such as www.example.com/users/addglobally (I only want the address type www.example.com/admin/users/addor www.example.com/registered/users/add)? Such addresses are not events set in routes.php, but they still work.

Any answers appreciated

+3
2

, . (/app/app_controller.php)

function beforeFilter() {               
        if ((isset($this->params['admin']))) {
            $admin_grp = $this->UserGroup->find('first', array(
                'conditions' => array(
                    'UserGroup.name' => 'Administrator')));
            if ($this->Auth->user('user_group_id') != $admin_grp['UserGroup']['id']) {
                $this->Session->setFlash(__('Access denied.', true));
                $this->redirect("/registered");
            } else {
                $this->layout = 'admin';
            }
        } else if (isset($this->params['registered'])) {
            if (!$this->Auth->user()) {
                $this->Session->setFlash(__('Access denied. You need to login first.', true));
                $this->redirect("/users/login");
            }
            $this->layout = 'registered';
        } else {
            $this->layout = 'default';
        }
}
+1

-, 1.3 1.2? 1.3 . , , , admin/controller/action, ... , /users/controller/action.

, core.php:

Configure::write('Routing.prefixes', array('admin', 'registered'));

: http://book.cakephp.org/view/950/Prefix-Routing

Auth , ACL , , , .

, , Andrew Perkins youtube, , . youtube.com/watch?v=FjXAnizmR94

3 , .

!

+3

Source: https://habr.com/ru/post/1784688/


All Articles