Redirect cakephp验证组件允许重定向问题

Redirect cakephp验证组件允许重定向问题,redirect,components,cakephp-1.3,authentication,Redirect,Components,Cakephp 1.3,Authentication,当我使用$this->Auth->allow('index','view')时,我对Auth组件有问题 当我使用$this->Auth->allow('*')时,/users/login导致了太多重定向。我使用的是CakePHP1.3.12,这里是app_controller.php class AppController extends Controller { var $components = array('Auth','Session'); function before

当我使用
$this->Auth->allow('index','view')时,我对Auth组件有问题
当我使用
$this->Auth->allow('*')
时,/users/login导致了太多重定向。我使用的是CakePHP1.3.12,这里是app_controller.php

class AppController extends Controller {
    var $components = array('Auth','Session');
    function beforeFilter(){    
         $this->Auth->allow('index','view');
    } 
}
class AppController extends Controller {
    var $components = array('Auth','Session');
    function beforeFilter(){    
        $this->Auth->allow(array('index','view','display'));
    }
}
class UsersController extends AppController {

var $name = 'Users';

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

function login() {
    if ($this->Session->read('Auth.User')) {
        $this->redirect('/', null, false);
    }
}
我更改了app_controller.php

class AppController extends Controller {
    var $components = array('Auth','Session');
    function beforeFilter(){    
         $this->Auth->allow('index','view');
    } 
}
class AppController extends Controller {
    var $components = array('Auth','Session');
    function beforeFilter(){    
        $this->Auth->allow(array('index','view','display'));
    }
}
class UsersController extends AppController {

var $name = 'Users';

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

function login() {
    if ($this->Session->read('Auth.User')) {
        $this->redirect('/', null, false);
    }
}
users\u controller.php

class AppController extends Controller {
    var $components = array('Auth','Session');
    function beforeFilter(){    
         $this->Auth->allow('index','view');
    } 
}
class AppController extends Controller {
    var $components = array('Auth','Session');
    function beforeFilter(){    
        $this->Auth->allow(array('index','view','display'));
    }
}
class UsersController extends AppController {

var $name = 'Users';

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

function login() {
    if ($this->Session->read('Auth.User')) {
        $this->redirect('/', null, false);
    }
}
routes.php

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
有什么建议吗? 谢谢

这是一个数组=)

由于无法访问/user/login操作,因此您收到的
重定向次数过多。因此,服务器尝试显示登录页面,但无法显示,因为普通的非连接用户没有/user/login的访问权限。当用户无法访问某个页面时,服务器会将其重定向到登录页面。。。你看,这是一个无限循环

应向所有人授权/user/login操作。您的
用户
控制器应如下所示:

class UsersController extends AppController {

var $name = 'Users';
function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow(array('login','logout'));
}

function login(){
    if ($this->Session->read('Auth.User')) {
        $this->redirect('/', null, false);
    }
}

    //if you're using prefix routes. 
function admin_login(){
    $this->redirect('/users/login');
}
如果这不是问题所在,那么可能是在routes.php中重定向页面

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

希望这有帮助

我不知道,但您可能希望检查是否有任何请求操作

“如果在布局或元素中使用requestAction,则应允许这些操作,以便能够正确打开登录页面。”

这让我难堪了很长时间

假设您在模板中的某个位置呈现一个元素:

echo $this->element('comments');
在views/elements/comments.ctp中,您有一些要求执行以下操作的内容

$comments = $this->requestAction('comments/index');
foreach($comments as $comment) {
 // print stuff
}
在您的评论控制器中,您必须:

function beforeFilter() {
    $this->Auth->allow('index');
}
请注意,您正在从元素中的注释控制器请求索引操作。这就是为什么您必须允许该特定控制器使用“索引”


我还没有看到这个问题在任何地方得到妥善解决。希望这就是导致您出错的原因。

您做错了。应用程序如何知道您试图控制的控制器操作。请从控制器上执行

从应用程序中删除此项

$this->Auth->allow(数组('index','view','display')

在应用程序控制器中尝试此操作,并进行必要的更改

        $this->Auth->loginError = "Wrong credentials. Please provide a valid username and password.";

        $this->Auth->authError = "You don't have sufficient privilege to access this resource.";

        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');

        $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');

        $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'dashboard');
从用户控制器执行此操作

$this->Auth->userModel = 'User';
$this->Auth->allow('*');
在你的登录中,不要做任何事情,所有重定向都将由app controller完成

如果你对此有任何疑问,请给我发邮件

jafarkv9@gmail.com


谢谢你的快速回复,我也试过了,但是运气不好。即使它不允许索引和查看操作谢谢你的评论我试过了,但没有成功。我清除了缓存和浏览器上的所有内容,但它显示了太多重定向。非常感谢,但它对我不起作用。我还添加了routes.php,我看不到任何问题,这真的很奇怪,我发现了问题,但我忘记了在允许解决该问题时使用了requestAction。感谢您,我正在使用Apache/2.2.17 PHP/5.3.5