]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/ConfigController.php
Merge pull request #1915 from wallabag/doc-links
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ConfigController.php
index de1536c91d92cbdccece2b5a3d065d069e032243..779be2689897a3344a279f4b667acbc03b0cffbe 100644 (file)
@@ -4,16 +4,17 @@ namespace Wallabag\CoreBundle\Controller;
 
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Request;
 use Wallabag\CoreBundle\Entity\Config;
 use Wallabag\CoreBundle\Entity\TaggingRule;
-use Wallabag\UserBundle\Entity\User;
+use Wallabag\CoreBundle\Form\Type\ConfigType;
 use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
-use Wallabag\CoreBundle\Form\Type\UserInformationType;
-use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
 use Wallabag\CoreBundle\Form\Type\NewUserType;
 use Wallabag\CoreBundle\Form\Type\RssType;
+use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
+use Wallabag\CoreBundle\Form\Type\UserInformationType;
 use Wallabag\CoreBundle\Tools\Utils;
 
 class ConfigController extends Controller
@@ -31,7 +32,7 @@ class ConfigController extends Controller
         $user = $this->getUser();
 
         // handle basic config detail (this form is defined as a service)
-        $configForm = $this->createForm('config', $config, array('action' => $this->generateUrl('config')));
+        $configForm = $this->createForm(ConfigType::class, $config, array('action' => $this->generateUrl('config')));
         $configForm->handleRequest($request);
 
         if ($configForm->isValid()) {
@@ -44,30 +45,33 @@ class ConfigController extends Controller
 
             $this->get('session')->getFlashBag()->add(
                 'notice',
-                'Config saved. Some parameters will be considered after disconnection.'
+                'flashes.config.notice.config_saved'
             );
 
             return $this->redirect($this->generateUrl('config'));
         }
 
         // handle changing password
-        $pwdForm = $this->createForm(new ChangePasswordType(), null, array('action' => $this->generateUrl('config').'#set4'));
+        $pwdForm = $this->createForm(ChangePasswordType::class, null, array('action' => $this->generateUrl('config').'#set4'));
         $pwdForm->handleRequest($request);
 
         if ($pwdForm->isValid()) {
-            $user->setPlainPassword($pwdForm->get('new_password')->getData());
-            $userManager->updateUser($user, true);
+            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';
 
-            $this->get('session')->getFlashBag()->add(
-                'notice',
-                'Password updated'
-            );
+                $user->setPlainPassword($pwdForm->get('new_password')->getData());
+                $userManager->updateUser($user, true);
+            }
 
-            return $this->redirect($this->generateUrl('config'));
+            $this->get('session')->getFlashBag()->add('notice', $message);
+
+            return $this->redirect($this->generateUrl('config').'#set4');
         }
 
         // handle changing user information
-        $userForm = $this->createForm(new UserInformationType(), $user, array(
+        $userForm = $this->createForm(UserInformationType::class, $user, array(
             'validation_groups' => array('Profile'),
             'action' => $this->generateUrl('config').'#set3',
         ));
@@ -78,14 +82,14 @@ class ConfigController extends Controller
 
             $this->get('session')->getFlashBag()->add(
                 'notice',
-                'Information updated'
+                'flashes.config.notice.user_updated'
             );
 
-            return $this->redirect($this->generateUrl('config'));
+            return $this->redirect($this->generateUrl('config').'#set3');
         }
 
         // handle rss information
-        $rssForm = $this->createForm(new RssType(), $config, array('action' => $this->generateUrl('config').'#set2'));
+        $rssForm = $this->createForm(RssType::class, $config, array('action' => $this->generateUrl('config').'#set2'));
         $rssForm->handleRequest($request);
 
         if ($rssForm->isValid()) {
@@ -94,15 +98,15 @@ class ConfigController extends Controller
 
             $this->get('session')->getFlashBag()->add(
                 'notice',
-                'RSS information updated'
+                'flashes.config.notice.rss_updated'
             );
 
-            return $this->redirect($this->generateUrl('config'));
+            return $this->redirect($this->generateUrl('config').'#set2');
         }
 
         // handle tagging rule
         $taggingRule = new TaggingRule();
-        $newTaggingRule = $this->createForm(new TaggingRuleType(), $taggingRule);
+        $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, array('action' => $this->generateUrl('config').'#set5'));
         $newTaggingRule->handleRequest($request);
 
         if ($newTaggingRule->isValid()) {
@@ -112,19 +116,19 @@ class ConfigController extends Controller
 
             $this->get('session')->getFlashBag()->add(
                 'notice',
-                'Tagging rules updated'
+                'flashes.config.notice.tagging_rules_updated'
             );
 
-            return $this->redirect($this->generateUrl('config'));
+            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(new NewUserType(), $newUser, array(
+        $newUserForm = $this->createForm(NewUserType::class, $newUser, array(
             'validation_groups' => array('Profile'),
-            'action' => $this->generateUrl('config').'#set5',
+            'action' => $this->generateUrl('config').'#set6',
         ));
         $newUserForm->handleRequest($request);
 
@@ -132,10 +136,10 @@ class ConfigController extends Controller
             $userManager->updateUser($newUser, true);
 
             $config = new Config($newUser);
-            $config->setTheme($this->container->getParameter('theme'));
-            $config->setItemsPerPage($this->container->getParameter('items_on_page'));
-            $config->setRssLimit($this->container->getParameter('rss_limit'));
-            $config->setLanguage($this->container->getParameter('language'));
+            $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'));
 
             $em->persist($config);
 
@@ -143,10 +147,10 @@ class ConfigController extends Controller
 
             $this->get('session')->getFlashBag()->add(
                 'notice',
-                sprintf('User "%s" added', $newUser->getUsername())
+                $this->get('translator')->trans('flashes.config.notice.user_added', array('%username%' => $newUser->getUsername()))
             );
 
-            return $this->redirect($this->generateUrl('config'));
+            return $this->redirect($this->generateUrl('config').'#set6');
         }
 
         return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
@@ -162,6 +166,7 @@ class ConfigController extends Controller
                 'username' => $user->getUsername(),
                 'token' => $config->getRssToken(),
             ),
+            'twofactor_auth' => $this->getParameter('twofactor_auth'),
         ));
     }
 
@@ -170,7 +175,7 @@ class ConfigController extends Controller
      *
      * @Route("/generate-token", name="generate_token")
      *
-     * @return JsonResponse
+     * @return RedirectResponse|JsonResponse
      */
     public function generateTokenAction(Request $request)
     {
@@ -185,7 +190,12 @@ class ConfigController extends Controller
             return new JsonResponse(array('token' => $config->getRssToken()));
         }
 
-        return $request->headers->get('referer') ? $this->redirect($request->headers->get('referer')) : $this->redirectToRoute('config');
+        $this->get('session')->getFlashBag()->add(
+            'notice',
+            'flashes.config.notice.rss_token_updated'
+        );
+
+        return $this->redirect($this->generateUrl('config').'#set2');
     }
 
     /**
@@ -195,12 +205,12 @@ class ConfigController extends Controller
      *
      * @Route("/tagging-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_tagging_rule")
      *
-     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     * @return RedirectResponse
      */
-    public function deleteTaggingRule(TaggingRule $rule)
+    public function deleteTaggingRuleAction(TaggingRule $rule)
     {
         if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) {
-            throw $this->createAccessDeniedException('You can not access this tagging ryle.');
+            throw $this->createAccessDeniedException('You can not access this tagging rule.');
         }
 
         $em = $this->getDoctrine()->getManager();
@@ -209,10 +219,10 @@ class ConfigController extends Controller
 
         $this->get('session')->getFlashBag()->add(
             'notice',
-            'Tagging rule deleted'
+            'flashes.config.notice.tagging_rules_deleted'
         );
 
-        return $this->redirect($this->generateUrl('config'));
+        return $this->redirect($this->generateUrl('config').'#set5');
     }
 
     /**