3 namespace Wallabag\CoreBundle\Controller
;
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Wallabag\CoreBundle\Entity\Config
;
9 use Wallabag\CoreBundle\Form\Type\ConfigType
;
10 use Wallabag\CoreBundle\Form\Type\ChangePasswordType
;
11 use Wallabag\CoreBundle\Form\Type\UserType
;
13 class ConfigController
extends Controller
16 * @param Request $request
18 * @Route("/config", name="config")
20 public function indexAction(Request
$request)
22 $em = $this->getDoctrine()->getManager();
23 $config = $this->getConfig();
24 $user = $this->getUser();
26 // handle basic config detail
27 $configForm = $this->createForm(new ConfigType(), $config);
28 $configForm->handleRequest($request);
30 if ($configForm->isValid()) {
31 $em->persist($config);
34 $this->get('session')->getFlashBag()->add(
39 return $this->redirect($this->generateUrl('config'));
42 // handle changing password
43 $pwdForm = $this->createForm(new ChangePasswordType());
44 $pwdForm->handleRequest($request);
46 if ($pwdForm->isValid()) {
47 $user->setPassword($pwdForm->get('new_password')->getData());
51 $this->get('session')->getFlashBag()->add(
56 return $this->redirect($this->generateUrl('config'));
59 // handle changing user information
60 $userForm = $this->createForm(new UserType(), $user);
61 $userForm->handleRequest($request);
63 if ($userForm->isValid()) {
67 $this->get('session')->getFlashBag()->add(
72 return $this->redirect($this->generateUrl('config'));
75 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
76 'configForm' => $configForm->createView(),
77 'pwdForm' => $pwdForm->createView(),
78 'userForm' => $userForm->createView(),
83 * Retrieve config for the current user.
84 * If no config were found, create a new one.
86 * @return Wallabag\CoreBundle\Entity\Config
88 private function getConfig()
90 $config = $this->getDoctrine()
91 ->getRepository('WallabagCoreBundle:Config')
92 ->findOneByUser($this->getUser());
95 $config = new Config($this->getUser());