CakeDC / users

Users Plugin for CakePHP
https://www.cakedc.com
Other
522 stars 296 forks source link

remember_me cookie not added after login #694

Open benoitkopp opened 6 years ago

benoitkopp commented 6 years ago

Hello all !

I just upgraded CakeDC/Users at the 7.0.0 version with CakeDC/Auth 2.0.3.

Before, with the default configuration, the remember_me cookie was automatically added on the login.

Since the update, the cookie is not added on the login and i'm disconnected from the session after the default CakePHP Session time.

Did i miss something ?

Thanks in advance !

benoitkopp commented 6 years ago

CakeDC 7.0.0 / Auth 2.0.3 / CakePHP 3.6.4

In vendor/cakedc/users/src/Controller/Component/RememberMeComponent:

public function setLoginCookie(Event $event)
    {
        $user['id'] = $this->Auth->user('id');
        if (empty($user)) {
            return;
        }
        $user['user_agent'] = $this->getController()->getRequest()->getHeaderLine('User-Agent');
        // $this->Cookie->write($this->_cookieName, $user);
        if (!(bool)$this->getController()->getRequest()->getData(Configure::read('Users.Key.Data.rememberMe'))) {
             return;
        }
        $this->Cookie->write($this->_cookieName, $user);
    }

Why the if condition on Users.Key.Data.rememberMe ? Even if the key is set, the condition is True and the cookie is never written !

I will certainly remove this condition in my case, other ideas ?

benoitkopp commented 6 years ago

Alright, i figured out that in the Component login.ctp it had the following code:

<?php if(Configure::read('Users.RememberMe.active')): ?>
    <?= $this->Form->control(Configure::read('Users.Key.Data.rememberMe'), [
    'type' => 'checkbox',
     'label' => __d('CakeDC/Users', 'Remember me'),
  'checked' => Configure::read('Users.RememberMe.checked'),
]) ?>
<?php endif; ?>

So I added it to my Template/Plugin/Users/Users/login.ctp but I put the checkbox display to none because i want to write automatically the Cookie. I don't want the user to choose !

ajibarra commented 4 months ago

@benoitkopp I think you can add the field as hidden. Can you confirm is this still an issue in latest version?