2014-10-11 65 views
0

我在Cakephp(版本= 2.5.3)中实现身份验证时遇到了问题。 登录功能工作正常,但每当我点击退出,在error.log中在CakePHP中使用AuthComponent注销时出现内部错误

0 /opt/lampp/htdocs/v1/lib/Cake/Controller/Component/Auth/BaseAuthorize.php(72): ControllerAuthorize->controller(Object(UsersController)) 
1 /opt/lampp/htdocs/v1/lib/Cake/Controller/Component/AuthComponent.php(500): BaseAuthorize->__construct(Object(ComponentCollection), Array) 
2 /opt/lampp/htdocs/v1/lib/Cake/Controller/Component/AuthComponent.php(462): AuthComponent->constructAuthorize() 
3 /opt/lampp/htdocs/v1/lib/Cake/Controller/Component/AuthComponent.php(309): AuthComponent->isAuthorized(Array) 
4 [internal function]: AuthComponent->startup(Object(UsersController)) 
5 /opt/lampp/htdocs/v1/lib/Cake/Utility/ObjectCollection.php(128): call_user_func_array(Array, Array) 
6 [internal function]: ObjectCollection->trigger(Object(CakeEvent)) 
7 /opt/lampp/htdocs/v1/lib/Cake/Event/CakeEventManager.php(242): call_user_func(Array, Object(CakeEvent)) 
8 /opt/lampp/htdocs/v1/lib/Cake/Controller/Controller.php(675): CakeEventManager->dispatch(Object(CakeEvent)) 
9 /opt/lampp/htdocs/v1/lib/Cake/Routing/Dispatcher.php(187): Controller->startupProcess() 
10 /opt/lampp/htdocs/v1/lib/Cake/Routing/Dispatcher.php(165): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest)) 
11 /opt/lampp/htdocs/v1/app/webroot/index.php(108): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse)) 
12 {main} 

以下是不同的文件,其中的登录和注销的功能进行编码

AppController.php生成以下异常

class AppController extends Controller { 

public $components = array(
    'Session', 
    'Auth' => array('authenticate' => array('Form' => array('passwordHasher' => 'Blowfish', 'userModel' => 'User','fields' => array('username' => 'user_name', 'password' => 'password'))), 
        'loginRedirect' => array('controller' => 'talks','action' => 'index'), 
        'logoutRedirect' => array('controller' => 'pages','action' => 'display','home'), 
        'loginAction' => array('controller' => 'users', 'action' => 'login'), 
        'authorize' => array('Controller') 
    ) 
); 

public function beforeFilter() { 
    $this->Auth->allow('index', 'view'); 
} 

} 

UsersController.php

App::uses('AppController', 'Controller'); 

class UsersController extends AppController { 

//put your code here 

public function beforeFilter() { 
    parent::beforeFilter(); 
    $this->Auth->allow('add', 'login'); 
} 

public function login() { 
    if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 
      return $this->redirect($this->Auth->redirectUrl()); 
     } 
     $this->Session->setFlash(__('Invalid username or password, try again')); 
    } 
} 

public function logout() { 
    return $this->redirect($this->Auth->logout()); 
} 

} 

下面的代码是登录和注销的显示链接

<?php if(!$this->Session->read('Auth.User')){ ?> 
LOGIN FORM GENERATION CODE 
      <?php }else{ 
      echo $this->Html->link(
         'LOGOUT', array(
             'controller' => 'users', 
             'action' => 'logout', 
             'full_base' => true) 
           ); 
     } ?> 

我也没有对如何调试CakePHP的应用有很多想法。所以如果有人能够至少将我指向正确的调试方向也会非常有帮助。

感谢提前:)

回答

0

给予多一点思考,并通过Caakephp API文档会后,我发现我并没有覆盖在我的UsersController的isAuthorized()方法。

添加以下到我的控制器:

public function isAuthorized() { 
    return true; 
} 

我返回true总是因为我没有任何团体。我只有一种类型的用户。

相关问题