如何删除cakephp身份验证中的“重定向”参数?

问题描述 投票:0回答:2

我希望用户在未登录的情况下被重定向到登录页面,但URL中没有“redirect”参数。 这是我的代码:

<code>
    $this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'fields' => [
                    'username' => 'email',
                    'password' => 'password'
                ]
            ],
        ],
        'loginAction' => [
            'controller' => 'Auth',
            'action' => 'login'
        ],
    ]);
</code>

我希望输出为admin / auth / login,但实际输出是admin / auth / login?redirect =%2Fadmin%2F

我已经查看了文档但没有发现任何内容。

authentication cakephp-3.0
2个回答
0
投票

我通过重写AuthComponent类(Cake \ Controller \ Component \ AuthComponent)解决了这个问题。为此我通过为组件创建别名(https://book.cakephp.org/3.0/en/controllers/components.html#aliasing-components)来跟踪文档。

我重写了_loginActionRedirectUrl()函数,导致它返回$ this - > _ config ['loginAction'];


0
投票

你需要在你的代码中添加param 'unauthorizedRedirect' => false。所以你的代码看起来就像

$this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => [`enter code here`
                'username' => 'email',
                'password' => 'password'
            ]
        ],`enter code here`
    ],
    'loginAction' => [
        'controller' => 'Auth',
        'action' => 'login'
    ],
    'unauthorizedRedirect' => false
]);

希望它会对你有所帮助。 更多你可以检查Here

© www.soinside.com 2019 - 2024. All rights reserved.