CakeDc/users how to work with permissions?

孤人 提交于 2019-12-11 07:07:55

问题


I installed CakeDC/users run migration, created the super user, copied the users.php to config/ directory.

And now in my website all pages are redirecting to login page. And i can't change this thing, cause i not well understand how permissions work.

My needs are to allow all pages on site, and block access only for one page with personal data for the user loggedin.

Any help, suggest readings, examples are welcome, BIG thanks!


回答1:


You will need to allow all actions in the beforeFilter of your AppController.

public function beforeFilter(Event $event)
{
    $this->Auth->allow();
}

See AuthComponent::allow

You will then need to deny the action that requires authentication in the beforeFilter of the controller that has that action.

public function beforeFilter(Event $event)
{
    // Where `loggedInAction` is the name of the
    // action that requires authentication 
    $this->Auth->deny('loggedInAction');
}

See AuthComponent::deny




回答2:


Maybe you have to use this method for cakephp3.x , in your controllers:

 public function initialize()
 {
    $this->Auth->allow('youraction'); // this action will plublic. Not under auth control.
 }

Hope this link can help you: https://book.cakephp.org/3.0/en/controllers.html#the-app-controller



来源:https://stackoverflow.com/questions/47183492/cakedc-users-how-to-work-with-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!