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\ChangePasswordType
;
11 use Wallabag\CoreBundle\Form\Type\UserType
;
12 use Wallabag\CoreBundle\Form\Type\NewUserType
;
14 class ConfigController
extends Controller
17 * @param Request $request
19 * @Route("/config", name="config")
21 public function indexAction(Request
$request)
23 $em = $this->getDoctrine()->getManager();
24 $config = $this->getConfig();
25 $user = $this->getUser();
27 // handle basic config detail (this form is defined as a service)
28 $configForm = $this->createForm('config', $config);
29 $configForm->handleRequest($request);
31 if ($configForm->isValid()) {
32 $em->persist($config);
35 // switch active theme
36 $activeTheme = $this->get('liip_theme.active_theme');
37 $activeTheme->setName($config->getTheme());
39 $this->get('session')->getFlashBag()->add(
44 return $this->redirect($this->generateUrl('config'));
47 // handle changing password
48 $pwdForm = $this->createForm(new ChangePasswordType());
49 $pwdForm->handleRequest($request);
51 if ($pwdForm->isValid()) {
52 $user->setPassword($pwdForm->get('new_password')->getData());
56 $this->get('session')->getFlashBag()->add(
61 return $this->redirect($this->generateUrl('config'));
64 // handle changing user information
65 $userForm = $this->createForm(new UserType(), $user);
66 $userForm->handleRequest($request);
68 if ($userForm->isValid()) {
72 $this->get('session')->getFlashBag()->add(
77 return $this->redirect($this->generateUrl('config'));
80 // handle adding new user
81 $newUser = new User();
82 $newUserForm = $this->createForm(new NewUserType(), $newUser);
83 $newUserForm->handleRequest($request);
85 if ($newUserForm->isValid()) {
86 $em->persist($newUser);
88 $config = new Config($newUser);
89 $config->setTheme($this->container
->getParameter('theme'));
90 $config->setItemsPerPage($this->container
->getParameter('items_on_page'));
91 $config->setLanguage($this->container
->getParameter('language'));
93 $em->persist($config);
97 $this->get('session')->getFlashBag()->add(
99 sprintf('User "%s" added', $newUser->getUsername())
102 return $this->redirect($this->generateUrl('config'));
105 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
106 'configForm' => $configForm->createView(),
107 'pwdForm' => $pwdForm->createView(),
108 'userForm' => $userForm->createView(),
109 'newUserForm' => $newUserForm->createView(),
114 * Retrieve config for the current user.
115 * If no config were found, create a new one.
117 * @return Wallabag\CoreBundle\Entity\Config
119 private function getConfig()
121 $config = $this->getDoctrine()
122 ->getRepository('WallabagCoreBundle:Config')
123 ->findOneByUser($this->getUser());
126 $config = new Config($this->getUser());