In a Symfony2 application that uses FOSUserBundle to manage users, a user table is populated by importing a script from a csv file and a password generated from a combination of data.
I would like to force the user to change the password at the first login.
When an event occurs FOSUserEvents::SECURITY_IMPLICIT_LOGIN, redirect to the route fos_user_change_passwordif the field last_loginis NULL.
My idea was rewriting a onImplicitLogin(UserEvent $event)class method AGI\UserBundle\EventListener\LastLoginListenerlike this, but the class was not rewriting:
public function onImplicitLogin(UserEvent $event) {
$user = $event->getUser ();
if ($user->getLastLogin () === null) {
$user->setLastLogin ( new \DateTime () );
$this->userManager->updateUser ( $user );
$response = new RedirectResponse ( $this->router->generate ( 'fos_user_change_password' ) );
$this->session->getFlashBag ()->add ( 'notice', 'Please change your password' );
$event->setResponse ( $response );
}
}
I already have a rewritable FOSUserBundle package, and it works for controllers, forms, etc. But it looks like this is not a way to do this with eventListeners.
How can I get the user to change the password after the first login?