0

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

  1. 当我通过 Auth 组件注销我的应用程序时。我没有再次登录,但我尝试访问一些页面。出现 Auth session login request 像:(我没有设计它)

在此处输入图像描述

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

  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',
                            ]
                        ]
4

1 回答 1

2
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();
}

这段代码对我有用。我在我的应用程序中使用。

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

于 2016-08-22T10:57:59.890 回答