Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remember_me cookie not added after login #694

Open
benoitkopp opened this issue May 24, 2018 · 3 comments
Open

remember_me cookie not added after login #694

benoitkopp opened this issue May 24, 2018 · 3 comments

Comments

@benoitkopp
Copy link

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
Copy link
Author

benoitkopp commented May 25, 2018

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
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants