简体   繁体   English

Cakephp前缀的不同会话

[英]Different Session for Cakephp Prefix

I'm strangling with a simple matter : How to tell Cake to use a different Session configuration for different prefix (routes). 我正在解决一个简单的问题:如何告诉Cake对不同的前缀(路由)使用不同的Session配置。

I have the main domain www.domain.tdl and I don't want the prefix couriers (www.domain.tdl/couriers) to use the same Session configuration to avoid Authentification problems : the main domain and prefix use different Authentification configurations. 我有主域www.domain.tdl,并且我不希望前缀couriers (www.domain.tdl / couriers)使用相同的会话配置来避免身份验证问题:主域名和前缀使用不同的身份验证配置。

So, in my App.php, the Session config is : 因此,在我的App.php中,会话配置为:

   'Session' => [
        'defaults' => 'cake',
        'timeout' => 24 * 60, //in minutes,
        'cookie' => 'app_bo',
//        "cookiePath" => "/mrbo", (tried with or without)
        'ini' => [
            "session.name" => "MR_BO",
        ]
    ],

And I thought I could change the config in the AppController of the prefix : src/Controller/Couriers/AppController.php 而且我以为我可以更改AppController中的前缀src / Controller / Couriers / AppController.php的配置

    Configure::write('Session', [
        'defaults' => 'cake',
        'timeout' => 24 * 60, //in minutes,
        'cookie' => 'app_courier',
        "cookiePath" => "/mrcourier",
        'ini' => [
            "session.name" => "MR_COURIER",
        ]
    ]);
    ini_set('session.cookie_name', 'app_courier');
    ini_set('session.cookie_path', '/mrcourier');
    ini_set('session.name', 'MR_COURIER');

Using only Configure::write did not work, that's why I added ini_set (seems like it update only internal CakePhp configuration). 仅使用Configure::write无效,这就是为什么我添加了ini_set(似乎只更新了内部CakePhp配置)。

By doing so, its works and not works. 这样做,它的工作而不是工作。 Indeed, I see that the domain and the prefix don't use the same, but when I tried to log in in the prefix page, nothing, it redirect to itself. 确实,我看到域和前缀没有使用相同的域,但是当我尝试登录前缀页面时,没有任何内容,它将重定向到自身。

I think it's because CakePHP use Session internally before my settings in the prefix AppController. 我认为这是因为CakePHP在前缀AppController中的设置之前先在内部使用Session。

EDIT Here is the Auth component loading : (the one for the prefix is quit the same, only the controller model/controller change) 编辑这是Auth组件的加载:(前缀的退出是一样的,只有控制器型号/控制器改变)

 $this->loadComponent('Auth', [
            'authorize' => ['Controller'],
            'authenticate' => [
                'Custom' => [
                    'passwordHasher' => [
                        'className' => 'Legacy',
                    ],
                    'userModel' => 'Establishments',
                    'fields' => array('username' => 'login', 'password' => 'password'),
                    "salt" => "salt" // Relative field for SALT
                ],
            ],
            'loginAction' => [
                'controller' => 'establishments',
                'action' => 'login'
            ],
            'loginRedirect' => [
                'controller' => 'pages',
                'action' => 'dashboard'
            ],
            'logoutRedirect' => [
                'controller' => 'establishments',
                'action' => 'login',
            ]
        ]);

In your auth configuration, use storage param to change Session settings. 在您的身份验证配置中,使用storage参数更改Session设置。 Use different key for each configuration 每种配置使用不同的密钥

$this->loadComponent('Auth', [
        'authorize' => ['Controller'],
        'storage' => ['className' => 'Session', 'key' => 'Auth.Admin'],
         /* ... */
    ]
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM