gpt4 book ai didi

authentication - CakePHP 3.2 : Prevent authError showing when user is not logged in

转载 作者:行者123 更新时间:2023-12-01 22:23:53 25 4
gpt4 key购买 nike

即使用户未登录并尝试打开主页,在被重定向到登录页面后,也会显示 authError。是否有一种优雅的方法来防止这种情况,而无需修改 Auth 组件?这是我加载 Auth 组件的方式(我使用 TinyAuth 作为授权适配器):

$this->loadComponent('Auth', [
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'loginRedirect' => [
'controller' => 'Home',
'action' => 'index'
],
'authError' => 'You dont have permissions for that action',
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
],
'scope' => ['Users.active' => true],
'contain' => ['Roles']
]
],
'authorize' => [
'TinyAuth.Tiny' => [
'roleColumn' => 'role_id',
'rolesTable' => 'Roles',
'multiRole' => true,
'pivotTable' => 'roles_users',
'superAdminRole' => null,
'authorizeByPrefix' => false,
'prefixes' => [],
'allowUser' => false,
'adminPrefix' => null,
'autoClearCache' => true
]
]
]
);

最佳答案

根据 CakePHP's documentation您可以通过将 authError 设置为 false 来防止显示错误消息。

Sometimes, you want to display the authorization error only after the user has already logged-in. You can suppress this message by setting its value to boolean false.

这应该禁用错误消息:

if (!$this->Auth->user()) {
$this->Auth->config('authError', false);
}

关于authentication - CakePHP 3.2 : Prevent authError showing when user is not logged in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38037777/

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