aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/ConfigController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php140
1 files changed, 69 insertions, 71 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index d4170d39..7e39992d 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -10,8 +10,8 @@ use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; 10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
11use Wallabag\CoreBundle\Entity\Config; 11use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\CoreBundle\Entity\TaggingRule; 12use Wallabag\CoreBundle\Entity\TaggingRule;
13use Wallabag\CoreBundle\Form\Type\ConfigType;
14use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 13use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
14use Wallabag\CoreBundle\Form\Type\ConfigType;
15use Wallabag\CoreBundle\Form\Type\RssType; 15use Wallabag\CoreBundle\Form\Type\RssType;
16use Wallabag\CoreBundle\Form\Type\TaggingRuleType; 16use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
17use Wallabag\CoreBundle\Form\Type\UserInformationType; 17use Wallabag\CoreBundle\Form\Type\UserInformationType;
@@ -54,7 +54,7 @@ class ConfigController extends Controller
54 } 54 }
55 55
56 // handle changing password 56 // handle changing password
57 $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config').'#set4']); 57 $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config') . '#set4']);
58 $pwdForm->handleRequest($request); 58 $pwdForm->handleRequest($request);
59 59
60 if ($pwdForm->isSubmitted() && $pwdForm->isValid()) { 60 if ($pwdForm->isSubmitted() && $pwdForm->isValid()) {
@@ -69,13 +69,13 @@ class ConfigController extends Controller
69 69
70 $this->get('session')->getFlashBag()->add('notice', $message); 70 $this->get('session')->getFlashBag()->add('notice', $message);
71 71
72 return $this->redirect($this->generateUrl('config').'#set4'); 72 return $this->redirect($this->generateUrl('config') . '#set4');
73 } 73 }
74 74
75 // handle changing user information 75 // handle changing user information
76 $userForm = $this->createForm(UserInformationType::class, $user, [ 76 $userForm = $this->createForm(UserInformationType::class, $user, [
77 'validation_groups' => ['Profile'], 77 'validation_groups' => ['Profile'],
78 'action' => $this->generateUrl('config').'#set3', 78 'action' => $this->generateUrl('config') . '#set3',
79 ]); 79 ]);
80 $userForm->handleRequest($request); 80 $userForm->handleRequest($request);
81 81
@@ -87,11 +87,11 @@ class ConfigController extends Controller
87 'flashes.config.notice.user_updated' 87 'flashes.config.notice.user_updated'
88 ); 88 );
89 89
90 return $this->redirect($this->generateUrl('config').'#set3'); 90 return $this->redirect($this->generateUrl('config') . '#set3');
91 } 91 }
92 92
93 // handle rss information 93 // handle rss information
94 $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config').'#set2']); 94 $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config') . '#set2']);
95 $rssForm->handleRequest($request); 95 $rssForm->handleRequest($request);
96 96
97 if ($rssForm->isSubmitted() && $rssForm->isValid()) { 97 if ($rssForm->isSubmitted() && $rssForm->isValid()) {
@@ -103,12 +103,12 @@ class ConfigController extends Controller
103 'flashes.config.notice.rss_updated' 103 'flashes.config.notice.rss_updated'
104 ); 104 );
105 105
106 return $this->redirect($this->generateUrl('config').'#set2'); 106 return $this->redirect($this->generateUrl('config') . '#set2');
107 } 107 }
108 108
109 // handle tagging rule 109 // handle tagging rule
110 $taggingRule = new TaggingRule(); 110 $taggingRule = new TaggingRule();
111 $action = $this->generateUrl('config').'#set5'; 111 $action = $this->generateUrl('config') . '#set5';
112 112
113 if ($request->query->has('tagging-rule')) { 113 if ($request->query->has('tagging-rule')) {
114 $taggingRule = $this->getDoctrine() 114 $taggingRule = $this->getDoctrine()
@@ -119,7 +119,7 @@ class ConfigController extends Controller
119 return $this->redirect($action); 119 return $this->redirect($action);
120 } 120 }
121 121
122 $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; 122 $action = $this->generateUrl('config') . '?tagging-rule=' . $taggingRule->getId() . '#set5';
123 } 123 }
124 124
125 $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); 125 $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]);
@@ -135,7 +135,7 @@ class ConfigController extends Controller
135 'flashes.config.notice.tagging_rules_updated' 135 'flashes.config.notice.tagging_rules_updated'
136 ); 136 );
137 137
138 return $this->redirect($this->generateUrl('config').'#set5'); 138 return $this->redirect($this->generateUrl('config') . '#set5');
139 } 139 }
140 140
141 return $this->render('WallabagCoreBundle:Config:index.html.twig', [ 141 return $this->render('WallabagCoreBundle:Config:index.html.twig', [
@@ -182,7 +182,7 @@ class ConfigController extends Controller
182 'flashes.config.notice.rss_token_updated' 182 'flashes.config.notice.rss_token_updated'
183 ); 183 );
184 184
185 return $this->redirect($this->generateUrl('config').'#set2'); 185 return $this->redirect($this->generateUrl('config') . '#set2');
186 } 186 }
187 187
188 /** 188 /**
@@ -207,7 +207,7 @@ class ConfigController extends Controller
207 'flashes.config.notice.tagging_rules_deleted' 207 'flashes.config.notice.tagging_rules_deleted'
208 ); 208 );
209 209
210 return $this->redirect($this->generateUrl('config').'#set5'); 210 return $this->redirect($this->generateUrl('config') . '#set5');
211 } 211 }
212 212
213 /** 213 /**
@@ -223,7 +223,7 @@ class ConfigController extends Controller
223 { 223 {
224 $this->validateRuleAction($rule); 224 $this->validateRuleAction($rule);
225 225
226 return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); 226 return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5');
227 } 227 }
228 228
229 /** 229 /**
@@ -241,11 +241,9 @@ class ConfigController extends Controller
241 ->getRepository('WallabagAnnotationBundle:Annotation') 241 ->getRepository('WallabagAnnotationBundle:Annotation')
242 ->removeAllByUserId($this->getUser()->getId()); 242 ->removeAllByUserId($this->getUser()->getId());
243 break; 243 break;
244
245 case 'tags': 244 case 'tags':
246 $this->removeAllTagsByUserId($this->getUser()->getId()); 245 $this->removeAllTagsByUserId($this->getUser()->getId());
247 break; 246 break;
248
249 case 'entries': 247 case 'entries':
250 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff 248 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff
251 // otherwise they won't be removed ... 249 // otherwise they won't be removed ...
@@ -272,10 +270,63 @@ class ConfigController extends Controller
272 270
273 $this->get('session')->getFlashBag()->add( 271 $this->get('session')->getFlashBag()->add(
274 'notice', 272 'notice',
275 'flashes.config.notice.'.$type.'_reset' 273 'flashes.config.notice.' . $type . '_reset'
276 ); 274 );
277 275
278 return $this->redirect($this->generateUrl('config').'#set3'); 276 return $this->redirect($this->generateUrl('config') . '#set3');
277 }
278
279 /**
280 * Delete account for current user.
281 *
282 * @Route("/account/delete", name="delete_account")
283 *
284 * @param Request $request
285 *
286 * @throws AccessDeniedHttpException
287 *
288 * @return \Symfony\Component\HttpFoundation\RedirectResponse
289 */
290 public function deleteAccountAction(Request $request)
291 {
292 $enabledUsers = $this->get('wallabag_user.user_repository')
293 ->getSumEnabledUsers();
294
295 if ($enabledUsers <= 1) {
296 throw new AccessDeniedHttpException();
297 }
298
299 $user = $this->getUser();
300
301 // logout current user
302 $this->get('security.token_storage')->setToken(null);
303 $request->getSession()->invalidate();
304
305 $em = $this->get('fos_user.user_manager');
306 $em->deleteUser($user);
307
308 return $this->redirect($this->generateUrl('fos_user_security_login'));
309 }
310
311 /**
312 * Switch view mode for current user.
313 *
314 * @Route("/config/view-mode", name="switch_view_mode")
315 *
316 * @param Request $request
317 *
318 * @return \Symfony\Component\HttpFoundation\RedirectResponse
319 */
320 public function changeViewModeAction(Request $request)
321 {
322 $user = $this->getUser();
323 $user->getConfig()->setListMode(!$user->getConfig()->getListMode());
324
325 $em = $this->getDoctrine()->getManager();
326 $em->persist($user);
327 $em->flush();
328
329 return $this->redirect($request->headers->get('referer'));
279 } 330 }
280 331
281 /** 332 /**
@@ -349,7 +400,7 @@ class ConfigController extends Controller
349 */ 400 */
350 private function validateRuleAction(TaggingRule $rule) 401 private function validateRuleAction(TaggingRule $rule)
351 { 402 {
352 if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { 403 if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) {
353 throw $this->createAccessDeniedException('You can not access this tagging rule.'); 404 throw $this->createAccessDeniedException('You can not access this tagging rule.');
354 } 405 }
355 } 406 }
@@ -373,57 +424,4 @@ class ConfigController extends Controller
373 424
374 return $config; 425 return $config;
375 } 426 }
376
377 /**
378 * Delete account for current user.
379 *
380 * @Route("/account/delete", name="delete_account")
381 *
382 * @param Request $request
383 *
384 * @throws AccessDeniedHttpException
385 *
386 * @return \Symfony\Component\HttpFoundation\RedirectResponse
387 */
388 public function deleteAccountAction(Request $request)
389 {
390 $enabledUsers = $this->get('wallabag_user.user_repository')
391 ->getSumEnabledUsers();
392
393 if ($enabledUsers <= 1) {
394 throw new AccessDeniedHttpException();
395 }
396
397 $user = $this->getUser();
398
399 // logout current user
400 $this->get('security.token_storage')->setToken(null);
401 $request->getSession()->invalidate();
402
403 $em = $this->get('fos_user.user_manager');
404 $em->deleteUser($user);
405
406 return $this->redirect($this->generateUrl('fos_user_security_login'));
407 }
408
409 /**
410 * Switch view mode for current user.
411 *
412 * @Route("/config/view-mode", name="switch_view_mode")
413 *
414 * @param Request $request
415 *
416 * @return \Symfony\Component\HttpFoundation\RedirectResponse
417 */
418 public function changeViewModeAction(Request $request)
419 {
420 $user = $this->getUser();
421 $user->getConfig()->setListMode(!$user->getConfig()->getListMode());
422
423 $em = $this->getDoctrine()->getManager();
424 $em->persist($user);
425 $em->flush();
426
427 return $this->redirect($request->headers->get('referer'));
428 }
429} 427}