router = $router; $this->em = $entityManager; $this->demo_mode = $demo_mode; $this->flashBag = $flashBag; } /** @return string[] **/ public static function getSubscribedEvents(): array { return array( 'r_u2f_two_factor.register' => 'onRegister', ); } public function onRegister(RegisterEvent $event): void { //Skip adding of U2F key on demo mode if (!$this->demo_mode) { $user = $event->getUser(); $registration = $event->getRegistration(); $newKey = new U2FKey(); $newKey->fromRegistrationData($registration); $newKey->setUser($user); $newKey->setName($event->getKeyName()); // persist the new key $this->em->persist($newKey); $this->em->flush(); $this->flashBag->add('success', 'tfa_u2f.key_added_successful'); } // generate new response, here we redirect the user to the fos user // profile $response = new RedirectResponse($this->router->generate('user_settings')); $event->setResponse($response); } }