Cakephp 3 - 身份验证会话无法破坏

Cakephp 3 - Auth session cannot destroy

我在 Cloud 9 IDE 服务器上使用 Cakephp 3.2.11。

  1. 当我通过 Auth 组件注销到我的应用程序时。我没有再次登录,但我尝试访问一些页面。出现这样的 Auth 会话登录请求:(我没有设计它)

我在数据库中的用户 table 中输入用户名和密码。它已登录。

  1. 现在当我尝试注销时,销毁所有会话;我的应用程序仍然记录了我如上所述登录的会话。我使用调试来检查:

    调试($this->request->session()->read('Auth'));

这是我的注销()

public function logout()
    {
        $this->request->session()->destroy();
        return $this->redirect($this->Auth->logout());
    }

我的 AppController.php 具有 Auth 组件配置

$this->loadComponent('Auth', [
            'authenticate' => array(
                'Form' => array(
                    // 'fields' => array('username' => 'email'),
                    'scope' => array('is_delete' => '0')
                )
            ),
            'loginAction' => [
                'controller' => 'MUsers',
                'action' => 'login'            
            ],
            'authorize' => ['Controller'],
            'loginRedirect' => [
                'controller' => 'Pages',
                'action' => 'dashboard'
            ],
            'logoutRedirect' => [
                'controller' => 'MUsers',
                'action' => 'login'
            ],
            'storage' => 'Session',
            'authError' => 'Woopsie, you are not authorized to access this area.',
            'flash' => [
                'params' => [
                    'class' => 'alert alert-danger alert-dismissible text-c',
                            ]
                        ]

现在我无法使用代码删除该会话,我只能通过清除浏览器缓存来删除它。所以我的问题是:

如何使用代码解决此问题或配置我的应用程序设置?

更新

根据@Kamlesh Gupta 的回答,它编辑了我的代码,没问题。

$this->loadComponent('Auth', [
            'authenticate' => array(
                'Form' => array(
                'userModel' => 'MUsers', //Add this line
                'fields' => array('username' => 'username',
                                   'password' => 'password'), //Edited this line
                    'scope' => array('is_delete' => '0')
                )
            ),
            'loginAction' => [
                'controller' => 'MUsers',
                'action' => 'login'            
            ],
            'authorize' => ['Controller'],
            'loginRedirect' => [
                'controller' => 'Pages',
                'action' => 'dashboard'
            ],
            'logoutRedirect' => [
                'controller' => 'MUsers',
                'action' => 'login'
            ],
            'storage' => 'Session',
            'authError' => 'Woopsie, you are not authorized to access this area.',
            'flash' => [
                'params' => [
                    'class' => 'alert alert-danger alert-dismissible text-c',
                            ]
                        ]
For login authentication,

Use below code in appController.php

$this->loadComponent('Auth', [
             'authenticate' => [
                 'Form' => [
                     'userModel' => 'Users',
                     'fields' => array(
                         'username' => 'email',
                         'password' => 'password'
                     ),
                 ],
             ],
            'logoutRedirect' => [
                    'controller' => 'users',
                    'action' => 'login'
                ],
             'loginAction' => [
                 'controller' => 'Users',
                 'action' => 'login'
             ],
             'unauthorizedRedirect' => false,
             'storage' => 'Session'
         ]);

**for destroying session** 
public function logout()
{
  $this->Auth->logout();
}

这段代码适合我。我正在我的应用程序中使用。

您也可以尝试只更改模型名称和字段名称,操作