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\Entity\User
;
10 use Wallabag\CoreBundle\Form\Type\ConfigType
;
11 use Wallabag\CoreBundle\Form\Type\ChangePasswordType
;
12 use Wallabag\CoreBundle\Form\Type\UserType
;
13 use Wallabag\CoreBundle\Form\Type\NewUserType
;
15 class ConfigController
extends Controller
18 * @param Request $request
20 * @Route("/config", name="config")
22 public function indexAction(Request
$request)
24 $em = $this->getDoctrine()->getManager();
25 $config = $this->getConfig();
26 $user = $this->getUser();
28 // handle basic config detail
29 $configForm = $this->createForm(new ConfigType(), $config);
30 $configForm->handleRequest($request);
32 if ($configForm->isValid()) {
33 $em->persist($config);
36 $this->get('session')->getFlashBag()->add(
41 return $this->redirect($this->generateUrl('config'));
44 // handle changing password
45 $pwdForm = $this->createForm(new ChangePasswordType());
46 $pwdForm->handleRequest($request);
48 if ($pwdForm->isValid()) {
49 $user->setPassword($pwdForm->get('new_password')->getData());
53 $this->get('session')->getFlashBag()->add(
58 return $this->redirect($this->generateUrl('config'));
61 // handle changing user information
62 $userForm = $this->createForm(new UserType(), $user);
63 $userForm->handleRequest($request);
65 if ($userForm->isValid()) {
69 $this->get('session')->getFlashBag()->add(
74 return $this->redirect($this->generateUrl('config'));
77 // handle adding new user
78 $newUser = new User();
79 $newUserForm = $this->createForm(new NewUserType(), $newUser);
80 $newUserForm->handleRequest($request);
82 if ($newUserForm->isValid()) {
83 $em->persist($newUser);
85 $config = new Config($newUser);
86 $config->setTheme($this->container
->getParameter('theme'));
87 $config->setItemsPerPage($this->container
->getParameter('items_on_page'));
88 $config->setLanguage($this->container
->getParameter('language'));
90 $em->persist($config);
94 $this->get('session')->getFlashBag()->add(
96 sprintf('User "%s" added', $newUser->getUsername())
99 return $this->redirect($this->generateUrl('config'));
102 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
103 'configForm' => $configForm->createView(),
104 'pwdForm' => $pwdForm->createView(),
105 'userForm' => $userForm->createView(),
106 'newUserForm' => $newUserForm->createView(),
111 * Retrieve config for the current user.
112 * If no config were found, create a new one.
114 * @return Wallabag\CoreBundle\Entity\Config
116 private function getConfig()
118 $config = $this->getDoctrine()
119 ->getRepository('WallabagCoreBundle:Config')
120 ->findOneByUser($this->getUser());
123 $config = new Config($this->getUser());