diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 46fb9503..52a03070 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
7 | use Symfony\Component\HttpFoundation\JsonResponse; | 7 | use Symfony\Component\HttpFoundation\JsonResponse; |
8 | use Symfony\Component\HttpFoundation\RedirectResponse; | 8 | use Symfony\Component\HttpFoundation\RedirectResponse; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
10 | use Wallabag\CoreBundle\Entity\Config; | 11 | use Wallabag\CoreBundle\Entity\Config; |
11 | use Wallabag\CoreBundle\Entity\TaggingRule; | 12 | use Wallabag\CoreBundle\Entity\TaggingRule; |
12 | use Wallabag\CoreBundle\Form\Type\ConfigType; | 13 | use Wallabag\CoreBundle\Form\Type\ConfigType; |
@@ -150,6 +151,10 @@ class ConfigController extends Controller | |||
150 | 'token' => $config->getRssToken(), | 151 | 'token' => $config->getRssToken(), |
151 | ], | 152 | ], |
152 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), | 153 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), |
154 | 'wallabag_url' => $this->get('craue_config')->get('wallabag_url'), | ||
155 | 'enabled_users' => $this->getDoctrine() | ||
156 | ->getRepository('WallabagUserBundle:User') | ||
157 | ->getSumEnabledUsers(), | ||
153 | ]); | 158 | ]); |
154 | } | 159 | } |
155 | 160 | ||
@@ -223,6 +228,78 @@ class ConfigController extends Controller | |||
223 | } | 228 | } |
224 | 229 | ||
225 | /** | 230 | /** |
231 | * Remove all annotations OR tags OR entries for the current user. | ||
232 | * | ||
233 | * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries"}, name="config_reset") | ||
234 | * | ||
235 | * @return RedirectResponse | ||
236 | */ | ||
237 | public function resetAction($type) | ||
238 | { | ||
239 | switch ($type) { | ||
240 | case 'annotations': | ||
241 | $this->getDoctrine() | ||
242 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
243 | ->removeAllByUserId($this->getUser()->getId()); | ||
244 | break; | ||
245 | |||
246 | case 'tags': | ||
247 | $this->removeAllTagsByUserId($this->getUser()->getId()); | ||
248 | break; | ||
249 | |||
250 | case 'entries': | ||
251 | // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf | ||
252 | // otherwise they won't be removed ... | ||
253 | if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { | ||
254 | $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); | ||
255 | } | ||
256 | |||
257 | // manually remove tags to avoid orphan tag | ||
258 | $this->removeAllTagsByUserId($this->getUser()->getId()); | ||
259 | |||
260 | $this->getDoctrine() | ||
261 | ->getRepository('WallabagCoreBundle:Entry') | ||
262 | ->removeAllByUserId($this->getUser()->getId()); | ||
263 | } | ||
264 | |||
265 | $this->get('session')->getFlashBag()->add( | ||
266 | 'notice', | ||
267 | 'flashes.config.notice.'.$type.'_reset' | ||
268 | ); | ||
269 | |||
270 | return $this->redirect($this->generateUrl('config').'#set3'); | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * Remove all tags for a given user and cleanup orphan tags. | ||
275 | * | ||
276 | * @param int $userId | ||
277 | */ | ||
278 | private function removeAllTagsByUserId($userId) | ||
279 | { | ||
280 | $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); | ||
281 | |||
282 | if (empty($tags)) { | ||
283 | return; | ||
284 | } | ||
285 | |||
286 | $this->getDoctrine() | ||
287 | ->getRepository('WallabagCoreBundle:Entry') | ||
288 | ->removeTags($userId, $tags); | ||
289 | |||
290 | // cleanup orphan tags | ||
291 | $em = $this->getDoctrine()->getManager(); | ||
292 | |||
293 | foreach ($tags as $tag) { | ||
294 | if (count($tag->getEntries()) === 0) { | ||
295 | $em->remove($tag); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | $em->flush(); | ||
300 | } | ||
301 | |||
302 | /** | ||
226 | * Validate that a rule can be edited/deleted by the current user. | 303 | * Validate that a rule can be edited/deleted by the current user. |
227 | * | 304 | * |
228 | * @param TaggingRule $rule | 305 | * @param TaggingRule $rule |
@@ -253,4 +330,37 @@ class ConfigController extends Controller | |||
253 | 330 | ||
254 | return $config; | 331 | return $config; |
255 | } | 332 | } |
333 | |||
334 | /** | ||
335 | * Delete account for current user. | ||
336 | * | ||
337 | * @Route("/account/delete", name="delete_account") | ||
338 | * | ||
339 | * @param Request $request | ||
340 | * | ||
341 | * @throws AccessDeniedHttpException | ||
342 | * | ||
343 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
344 | */ | ||
345 | public function deleteAccountAction(Request $request) | ||
346 | { | ||
347 | $enabledUsers = $this->getDoctrine() | ||
348 | ->getRepository('WallabagUserBundle:User') | ||
349 | ->getSumEnabledUsers(); | ||
350 | |||
351 | if ($enabledUsers <= 1) { | ||
352 | throw new AccessDeniedHttpException(); | ||
353 | } | ||
354 | |||
355 | $user = $this->getUser(); | ||
356 | |||
357 | // logout current user | ||
358 | $this->get('security.token_storage')->setToken(null); | ||
359 | $request->getSession()->invalidate(); | ||
360 | |||
361 | $em = $this->get('fos_user.user_manager'); | ||
362 | $em->deleteUser($user); | ||
363 | |||
364 | return $this->redirect($this->generateUrl('fos_user_security_login')); | ||
365 | } | ||
256 | } | 366 | } |