Auth会话不能销毁

Auth会话不能销毁

本文介绍了Cakephp 3 - Auth会话不能销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Cakephp 3.2.11 on Cloud 9 IDE server.


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

>

我输入用户名&密码在数据库中的我的用户表。这是登录。

I type username & password in my Users table in database. It was LOGGED IN.


  1. 我的应用程序仍然记录了我上面登录的会话。我使用debug来检查:

  1. Now when I tried log out, destroy all session; my app still recorded the session what I logged in as above. I use debug to check:

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

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

这里我的注销()

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

我的AppController.php与Auth组件配置

My AppController.php with Auth component config

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

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

Now I cannot delete that session using code, I just can delete it by clear the browser cache. So my questions are:

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

How can I solve this problem using code or config my app settings?

strong> UPDATE

UPDATE

基于@Kamlesh Gupta回答,它编辑了我的代码,可以。

Based on @Kamlesh Gupta answered, it edited my code and it's ok.

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

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

This code is work for me. i am using in my app.

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

you can also try just changing model name and fieldname, action

这篇关于Cakephp 3 - Auth会话不能销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 14:43