I have implemented a login function programmatically.
This code is following:
$token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
$this->get('security.context')->setToken($token);
$event = new InteractiveLoginEvent($this->getRequest(),$token);
$this->get('event_dispatcher')->dispatch('security.interactive_login', $event);
After this, how do I implement remember me ?
(I know how to use form, but I want to implement remember me programmatically. )
please help...
Try to use RememberMeToken
$key = $this->getParameter('secret'); // your security key from parameters.yml
$token = new RememberMeToken($user, 'main', $key);
$this->get('security.context')->setToken($token);
I had the same problem.you should use RememberMeToken
instead of UsernamePasswordToken
.
The class parameters are very similar to UsernamePasswordToken so I don't go into details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With