public function testWithLanguage() { $session = new Session(new MockArraySessionStorage()); $listener = new UserLocaleListener($session); $user = new User(); $user->setEnabled(true); $config = new Config($user); $config->setLanguage('fr'); $user->setConfig($config); $userToken = new UsernamePasswordToken($user, '', 'test'); $request = Request::create('/'); $event = new InteractiveLoginEvent($request, $userToken); $listener->onInteractiveLogin($event); $this->assertEquals('fr', $session->get('_locale')); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $adminConfig = new Config($this->getReference('admin-user')); $adminConfig->setTheme('material'); $adminConfig->setItemsPerPage(30); $adminConfig->setReadingSpeed(1); $adminConfig->setLanguage('en'); $adminConfig->setPocketConsumerKey('xxxxx'); $manager->persist($adminConfig); $this->addReference('admin-config', $adminConfig); $bobConfig = new Config($this->getReference('bob-user')); $bobConfig->setTheme('default'); $bobConfig->setItemsPerPage(10); $bobConfig->setReadingSpeed(1); $bobConfig->setLanguage('fr'); $bobConfig->setPocketConsumerKey(null); $manager->persist($bobConfig); $this->addReference('bob-config', $bobConfig); $emptyConfig = new Config($this->getReference('empty-user')); $emptyConfig->setTheme('material'); $emptyConfig->setItemsPerPage(10); $emptyConfig->setReadingSpeed(1); $emptyConfig->setLanguage('en'); $emptyConfig->setPocketConsumerKey(null); $manager->persist($emptyConfig); $this->addReference('empty-config', $emptyConfig); $manager->flush(); }
private function getPocketImport($consumerKey = 'ConsumerKey') { $this->user = new User(); $config = new Config($this->user); $config->setPocketConsumerKey('xxx'); $this->user->setConfig($config); $this->contentProxy = $this->getMockBuilder('Wallabag\\CoreBundle\\Helper\\ContentProxy')->disableOriginalConstructor()->getMock(); $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock(); $this->em->expects($this->any())->method('getUnitOfWork')->willReturn($this->uow); $this->uow->expects($this->any())->method('getScheduledEntityInsertions')->willReturn([]); $pocket = new PocketImport($this->em, $this->contentProxy); $pocket->setUser($this->user); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); $pocket->setLogger($logger); return $pocket; }
public function testWithValidUser() { $user = new User(); $user->setEnabled(true); $event = new FilterUserResponseEvent($user, $this->request, $this->response); $config = new Config($user); $config->setTheme('baggy'); $config->setItemsPerPage(20); $config->setRssLimit(50); $config->setLanguage('fr'); $config->setReadingSpeed(1); $this->em->expects($this->once())->method('persist')->will($this->returnValue($config)); $this->em->expects($this->once())->method('flush'); $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, $event); }
public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) { if (!$event->getUser()->isEnabled()) { return; } $config = new Config($event->getUser()); $config->setTheme($this->theme); $config->setItemsPerPage($this->itemsOnPage); $config->setRssLimit($this->rssLimit); $config->setLanguage($this->language); $this->em->persist($config); $this->em->flush(); }
protected function setupAdmin() { $this->defaultOutput->writeln('<info><comment>Step 3 of 5.</comment> Administration setup.</info>'); $questionHelper = $this->getHelperSet()->get('question'); $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true); if (!$questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { return $this; } $em = $this->getContainer()->get('doctrine.orm.entity_manager'); $userManager = $this->getContainer()->get('fos_user.user_manager'); $user = $userManager->createUser(); $question = new Question('Username (default: wallabag) :', 'wallabag'); $user->setUsername($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); $question = new Question('Password (default: wallabag) :', 'wallabag'); $user->setPlainPassword($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); $question = new Question('Email:', ''); $user->setEmail($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); $user->setEnabled(true); $user->addRole('ROLE_SUPER_ADMIN'); $em->persist($user); $config = new Config($user); $config->setTheme($this->getContainer()->getParameter('wallabag_core.theme')); $config->setItemsPerPage($this->getContainer()->getParameter('wallabag_core.items_on_page')); $config->setRssLimit($this->getContainer()->getParameter('wallabag_core.rss_limit')); $config->setReadingSpeed($this->getContainer()->getParameter('wallabag_core.reading_speed')); $config->setLanguage($this->getContainer()->getParameter('wallabag_core.language')); $em->persist($config); $this->defaultOutput->writeln(''); return $this; }
/** * @param Request $request * * @Route("/config", name="config") */ public function indexAction(Request $request) { $em = $this->getDoctrine()->getManager(); $config = $this->getConfig(); $userManager = $this->container->get('fos_user.user_manager'); $user = $this->getUser(); // handle basic config detail (this form is defined as a service) $configForm = $this->createForm(ConfigType::class, $config, ['action' => $this->generateUrl('config')]); $configForm->handleRequest($request); if ($configForm->isValid()) { $em->persist($config); $em->flush(); // switch active theme $activeTheme = $this->get('liip_theme.active_theme'); $activeTheme->setName($config->getTheme()); $this->get('session')->getFlashBag()->add('notice', 'flashes.config.notice.config_saved'); return $this->redirect($this->generateUrl('config')); } // handle changing password $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config') . '#set4']); $pwdForm->handleRequest($request); if ($pwdForm->isValid()) { if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) { $message = 'flashes.config.notice.password_not_updated_demo'; } else { $message = 'flashes.config.notice.password_updated'; $user->setPlainPassword($pwdForm->get('new_password')->getData()); $userManager->updateUser($user, true); } $this->get('session')->getFlashBag()->add('notice', $message); return $this->redirect($this->generateUrl('config') . '#set4'); } // handle changing user information $userForm = $this->createForm(UserInformationType::class, $user, ['validation_groups' => ['Profile'], 'action' => $this->generateUrl('config') . '#set3']); $userForm->handleRequest($request); if ($userForm->isValid()) { $userManager->updateUser($user, true); $this->get('session')->getFlashBag()->add('notice', 'flashes.config.notice.user_updated'); return $this->redirect($this->generateUrl('config') . '#set3'); } // handle rss information $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config') . '#set2']); $rssForm->handleRequest($request); if ($rssForm->isValid()) { $em->persist($config); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'flashes.config.notice.rss_updated'); return $this->redirect($this->generateUrl('config') . '#set2'); } // handle tagging rule $taggingRule = new TaggingRule(); $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $this->generateUrl('config') . '#set5']); $newTaggingRule->handleRequest($request); if ($newTaggingRule->isValid()) { $taggingRule->setConfig($config); $em->persist($taggingRule); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'flashes.config.notice.tagging_rules_updated'); return $this->redirect($this->generateUrl('config') . '#set5'); } // handle adding new user $newUser = $userManager->createUser(); // enable created user by default $newUser->setEnabled(true); $newUserForm = $this->createForm(NewUserType::class, $newUser, ['validation_groups' => ['Profile'], 'action' => $this->generateUrl('config') . '#set6']); $newUserForm->handleRequest($request); if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { $userManager->updateUser($newUser, true); $config = new Config($newUser); $config->setTheme($this->getParameter('wallabag_core.theme')); $config->setItemsPerPage($this->getParameter('wallabag_core.items_on_page')); $config->setRssLimit($this->getParameter('wallabag_core.rss_limit')); $config->setLanguage($this->getParameter('wallabag_core.language')); $config->setReadingSpeed($this->getParameter('wallabag_core.reading_speed')); $em->persist($config); $em->flush(); $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('flashes.config.notice.user_added', ['%username%' => $newUser->getUsername()])); return $this->redirect($this->generateUrl('config') . '#set6'); } return $this->render('WallabagCoreBundle:Config:index.html.twig', ['form' => ['config' => $configForm->createView(), 'rss' => $rssForm->createView(), 'pwd' => $pwdForm->createView(), 'user' => $userForm->createView(), 'new_user' => $newUserForm->createView(), 'new_tagging_rule' => $newTaggingRule->createView()], 'rss' => ['username' => $user->getUsername(), 'token' => $config->getRssToken()], 'twofactor_auth' => $this->getParameter('twofactor_auth')]); }