我无法让 Auth 组件在 CakePHP 1.2.6 应用程序中执行我想要的重定向。
我有一个出现在所有页面上的登录表单,我想让用户保留在他登录的页面上。例如,如果他正在查看另一个用户的个人资料,我想让他在登录后保留在那里,而不是将他重定向到$this->Auth->loginRedirect
行动。另外,关于我的应用程序的另一件事是,我没有“仅经过身份验证的访问”页面,每个页面都可供每个人访问,但如果您登录,您将获得其他功能。
我从阅读中了解到的文档是我需要设置autoRedirect
设置为 false 以获取要执行的 login() 函数中的代码:
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form','Text');
function beforeFilter() {
$this->Auth->autoRedirect = false;
}
function login() {
$this->redirect($this->referer());
}
function logout() {
$this->redirect($this->Auth->logout());
}
/* [...] */
}
目前这破坏了我的身份验证。我注意到(从日志中),如果我将重定向保留在登录函数中并设置autoRedirect
为 false,密码字段$this->data
in the login()
函数显示为空。
下面,我发布了 AppController 中与 Auth 组件相关的内容:
public function beforeFilter() {
$this->Auth->fields = array(
'username' => 'email',
'password' => 'password'
);
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'usercars', 'action' => 'homepage');
$this->allowAccess();
// build wishlist if the user is logged in
if ($currentUser = $this->Auth->user()) {
$wishlists = $this->buildWishlist($currentUser);
$this->set('wishlists', $wishlists);
}
}
private function allowAccess() {
if(in_array($this->name, /* all my controller names */)) {
$this->Auth->allow('*');
}
}
我似乎无法理解我做错了什么。