+ 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');
+ }
+
+ /**
+ * Deletes a tagging rule and redirect to the config homepage.
+ *
+ * @param TaggingRule $rule
+ *
+ * @Route("/tagging-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_tagging_rule")
+ *
+ * @return RedirectResponse
+ */
+ public function deleteTaggingRuleAction(TaggingRule $rule)
+ {
+ $this->validateRuleAction($rule);
+
+ $em = $this->getDoctrine()->getManager();
+ $em->remove($rule);
+ $em->flush();
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ 'flashes.config.notice.tagging_rules_deleted'
+ );
+
+ return $this->redirect($this->generateUrl('config').'#set5');
+ }
+
+ /**
+ * Edit a tagging rule.
+ *
+ * @param TaggingRule $rule
+ *
+ * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule")
+ *
+ * @return RedirectResponse
+ */
+ public function editTaggingRuleAction(TaggingRule $rule)
+ {
+ $this->validateRuleAction($rule);
+
+ return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5');
+ }
+
+ /**
+ * Validate that a rule can be edited/deleted by the current user.
+ *
+ * @param TaggingRule $rule
+ */
+ private function validateRuleAction(TaggingRule $rule)
+ {
+ if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) {
+ throw $this->createAccessDeniedException('You can not access this tagging rule.');
+ }