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
;
12 class ConfigController
extends Controller
15 * @param Request $request
17 * @Route("/config", name="config")
19 public function indexAction(Request
$request)
21 $em = $this->getDoctrine()->getManager();
22 $config = $this->getConfig();
24 // handle basic config detail
25 $configForm = $this->createForm(new ConfigType(), $config);
26 $configForm->handleRequest($request);
28 if ($configForm->isValid()) {
30 $em->persist($config);
33 $this->get('session')->getFlashBag()->add(
38 return $this->redirect($this->generateUrl('config'));
41 // handle changing password
42 $pwdForm = $this->createForm(new ChangePasswordType());
43 $pwdForm->handleRequest($request);
45 if ($pwdForm->isValid()) {
46 $user = $this->getUser();
47 $user->setPassword($pwdForm->get('new_password')->getData());
51 $this->get('session')->getFlashBag()->add(
56 return $this->redirect($this->generateUrl('config'));
59 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
60 'configForm' => $configForm->createView(),
61 'pwdForm' => $pwdForm->createView(),
66 * Retrieve config for the current user.
67 * If no config were found, create a new one.
69 * @return Wallabag\CoreBundle\Entity\Config
71 private function getConfig()
73 $config = $this->getDoctrine()
74 ->getRepository('WallabagCoreBundle:Config')
75 ->findOneByUser($this->getUser());
78 $config = new Config($this->getUser());