gpt4 book ai didi

CakePHP 2.5.2 URL 在身份验证后包含两次应用程序路径

转载 作者:行者123 更新时间:2023-12-01 06:28:41 25 4
gpt4 key购买 nike

我建立了一个简单的网站,并使用 ACL 指南添加了身份验证 here .我想我已经做到了。

我的问题是这样的:
登录后,如果我尝试访问有效的 url,则会再次添加路由文件夹。
例如访问:

 projectpath/controllerpath/action

重定向到
 projectpath/projectpath/controllerpath/action

我注意到的事情:
  • 只有当用户登录时才会发生。如果他们没有登录,它会正确重定向到登录页面。
  • 只有在作为 Controller 的页面上才会发生这种情况。如果我输入了不正确的页面,它会抛出缺少 Controller 异常。
  • 我允许公众访问的任何页面都可以正常工作。只有那些不公开的。

  • 编辑:

    今天早上我安装了一个新版本的 CakePHP 2.5.3。然后我手动复制了我的所有文件,不包括路由文件。仍然得到同样的错误。

    任何想法可能导致这种情况?

    编辑:
    我在这方面取得了进一步的进展。我删除了 ACL 组件并使用了 Auth 组件。

    该问题似乎仅在登录用户尝试访问未经授权的 url 时发生。从蛋糕

    property AuthComponent::$unauthorizedRedirect Controls handling of unauthorized access. By default unauthorized user is redirected to the referrer URL or AuthComponent::$loginAction or ‘/’. If set to false a ForbiddenException exception is thrown instead of redirecting.



    在我的应用程序 Controller 中
        public $components = array(
    'DebugKit.Toolbar',
    'Auth' => array(
    'redirectUrl' => array(
    'controller' => 'pages',
    'action' => 'index'
    ),
    'logoutRedirect' => array(
    'controller' => 'user',
    'action' => 'login',
    'home'
    ),
    'authenticate' => array(
    'Form' => array(
    'passwordHasher' => 'Blowfish'
    )
    ),
    'unauthorizedRedirect'=> false,// I have added this line
    'Session',
    'authorize' => array('Controller')
    )
    );

    这是有效的(因为它根本不重定向)。谁能解释如何根据文档将未经授权的重定向到正确的路线?

    编辑
    这是我在 App Controller 中的 beforeFilter
    public function beforeFilter() {

    $this->Auth->allow('display');
    /*if($this->Auth->user('role') == 'apa'){

    $this->Auth->redirectUrl = "/apa";
    }else{
    $this->Auth->redirectUrl = "/test";
    }*/ //Moved logic to UserController
    parent::beforeFilter();
    }

    编辑 用户 Controller
    public function login() {
    if ($this->request->is('post')) {
    if ($this->Auth->login()) {
    if($this->Auth->user('role') == 'apa'){

    $this->Auth->redirectUrl = "/apa";
    }else{
    $this->Auth->redirectUrl = "/test";
    }

    return $this->redirect($this->Auth->redirectUrl);
    }

    $this->Session->setFlash(__('Invalid username or password, try again'));
    }
    }

    最佳答案

    尝试在 AuthComponent 初始化中添加 loginAction 和 loginRedirect 属性,如下所示:

    'Auth' => array(
    'loginAction' => array('admin' => false, 'controller' => 'users', 'action' => 'login'),
    'loginRedirect' => array('admin' => false, 'controller' => 'pages', 'action' => 'index'), // redirected here after login success
    'logoutRedirect' => array(
    'controller' => 'user',
    'action' => 'login',
    'home'
    ),
    'authenticate' => array(
    'Form' => array(
    'passwordHasher' => 'Blowfish'
    )
    ), ...

    此外, AuthComponent::redirectUrl 是一个方法,而不是一个属性,它从 v2.3 开始被弃用。

    引用这里: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

    关于CakePHP 2.5.2 URL 在身份验证后包含两次应用程序路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25278735/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com