我在使用 CakeDC 插件时遇到了同样的问题,其中很多插件很少/没有文档。
但是,它没有“零”文档,您可以在阅读我的 github 页面底部的大部分内容中查看如何设置它。您还需要将它放在 AppController::beforeFilter() 方法中。
$this->Auth->authorize = 'controller';
$this->Auth->fields = array('username' => 'email', 'password' => 'passwd');
$this->Auth->loginAction = array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = '/';
$this->Auth->logoutRedirect = '/';
$this->Auth->authError = __('Sorry, but you need to login to access this location.', true);
$this->Auth->loginError = __('Invalid e-mail / password
combination. Please try again', true);
$this->Auth->autoRedirect = true;
$this->Auth->userModel = 'User';
$this->Auth->userScope = array('User.active' => 1);
if ($this->Auth->user()) {
$this->set('userData', $this->Auth->user());
$this->set('isAuthorized', ($this->Auth->user('id') != ''));
}
此外,您需要一个isAuthorized()
函数,就像这样简单:
public function isAuthorized() {
return true;
}
此外,您需要允许“登录”操作(这将涉及编辑插件文件)。只需将“登录”添加到$this->Auth->allow()
in users_controller.php
。