]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/ConfigController.php
Added check if there is only one user
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ConfigController.php
index 3cafd1bc69708ce11b777bb40d9465aed66f0f6f..70a641f7a2c62be68a013699ca45406325e88d7b 100644 (file)
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 use Wallabag\CoreBundle\Entity\Config;
 use Wallabag\CoreBundle\Entity\TaggingRule;
 use Wallabag\CoreBundle\Form\Type\ConfigType;
@@ -148,6 +149,9 @@ class ConfigController extends Controller
                 'token' => $config->getRssToken(),
             ],
             'twofactor_auth' => $this->getParameter('twofactor_auth'),
+            'enabled_users' => $this->getDoctrine()
+                ->getRepository('WallabagUserBundle:User')
+                ->getSumEnabledUsers(),
         ]);
     }
 
@@ -257,10 +261,20 @@ class ConfigController extends Controller
       *
       * @Route("/account/delete", name="delete_account")
       *
+      * @throws AccessDeniedHttpException
+      *
       * @return \Symfony\Component\HttpFoundation\RedirectResponse
       */
      public function deleteAccountAction()
      {
+         $enabledUsers = $this->getDoctrine()
+             ->getRepository('WallabagUserBundle:User')
+             ->getSumEnabledUsers();
+
+         if ($enabledUsers <= 1) {
+             throw new AccessDeniedHttpException();
+         }
+
          $em = $this->get('fos_user.user_manager');
          $em->deleteUser($this->getUser());