+ // 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();
+ $action = $this->generateUrl('config').'#set5';
+
+ if ($request->query->has('tagging-rule')) {
+ $taggingRule = $this->getDoctrine()
+ ->getRepository('WallabagCoreBundle:TaggingRule')
+ ->find($request->query->get('tagging-rule'));
+
+ if ($this->getUser()->getId() !== $taggingRule->getConfig()->getUser()->getId()) {
+ return $this->redirect($action);
+ }
+
+ $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5';
+ }
+
+ $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]);
+ $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');
+ }
+
+ return $this->render('WallabagCoreBundle:Config:index.html.twig', [
+ 'form' => [
+ 'config' => $configForm->createView(),
+ 'rss' => $rssForm->createView(),
+ 'pwd' => $pwdForm->createView(),
+ 'user' => $userForm->createView(),
+ 'new_tagging_rule' => $newTaggingRule->createView(),
+ ],
+ 'rss' => [
+ 'username' => $user->getUsername(),
+ 'token' => $config->getRssToken(),
+ ],
+ 'twofactor_auth' => $this->getParameter('twofactor_auth'),
+ ]);
+ }
+
+ /**
+ * @param Request $request
+ *
+ * @Route("/generate-token", name="generate_token")
+ *
+ * @return RedirectResponse|JsonResponse
+ */
+ public function generateTokenAction(Request $request)
+ {
+ $config = $this->getConfig();
+ $config->setRssToken(Utils::generateToken());
+
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($config);
+ $em->flush();
+
+ if ($request->isXmlHttpRequest()) {
+ return new JsonResponse(['token' => $config->getRssToken()]);
+ }
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ 'flashes.config.notice.rss_token_updated'
+ );
+
+ return $this->redirect($this->generateUrl('config').'#set2');