2016-06-25 7 views
0

私のアプリケーションの認証に間違いがあります。 adminロールを持つユーザーがページを追加できるようにしたいだけです。しかし、問題なく、私はadd関数にアクセスできます。ここに私がしたことがあります。CakePhp 3で認証が機能しない

のAppController

public function initialize() 
    { 
     parent::initialize(); 

    $this->loadComponent('RequestHandler'); 
    $this->loadComponent('Flash'); 
    $this->loadComponent('Auth', [ 
     'loginRedirect' => [ 
      'controller' => 'Moves', 
      'action' => 'view' 
     ], 
     'logoutRedirect' => [ 
      'controller' => 'Pages', 
      'action' => 'display', 
      'home' 
     ] 
    ]); 

public function beforeFilter(Event $event) 
{ 

    $this->Auth->allow(['index', 'view', 'display', 'english', 'italian', 'german']); 
    $this->Auth->loginAction = array('controller'=>'pages', 'action'=>'home'); 
    $this->loadModel('Menus'); 


    $main_de = $this->Menus->find('all', array(
     'conditions' => array('Menus.action' => 'main_de') 
    )); 
    $this->set('main_de', $main_de); 

    $main_us = $this->Menus->find('all', array(
     'conditions' => array('Menus.action' => 'main_us') 
    )); 
    $this->set('main_us', $main_us); 

} 

public function isAuthorized($user) 
{ 
    // Admin can access every action 
    if (isset($user['role']) && $user['role'] === 'admin') { 
     return true; 
    } 

    // Default deny 
    return false; 
} 

ページ

public function isAuthorized($user) 
    { 
     // All registered users can add articles 
     if ($this->request->action === 'add') { 
      return false; 
     } 

     // The owner of an article can edit and delete it 
     if (in_array($this->request->action, ['edit', 'delete'])) { 
      $articleId = (int)$this->request->params['pass'][0]; 
      if ($this->Articles->isOwnedBy($articleId, $user['id'])) { 
       return false; 
      } 
     } 

     return false; 
    } 

EDIT:解決策を見つけ、私は( '認証...

私loadComponentに '認可'=> 'コントローラ' を忘れてしまいました

答えて

0

'authorize' => 'Controller'、認証アレイ

public function initialize() 
    { 
     parent::initialize(); 

    $this->loadComponent('RequestHandler'); 
    $this->loadComponent('Flash'); 
    $this->loadComponent('Auth', [ 
     'loginRedirect' => [ 
      'controller' => 'Moves', 
      'action' => 'view' 
     ], 
     'logoutRedirect' => [ 
      'controller' => 'Pages', 
      'action' => 'display', 
      'home' 
     ], 
     // **'authorize' => 'Controller',** 

]); 
+0

さて、あなた自身の質問に答えるために行われますが、ただ捨てていない質問を_answer_してくださいに(ひどくフォーマットされた、との質問と同じ)コード。 – AD7six

関連する問題