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);
86 $this->get('session')->getFlashBag()->add(
88 sprintf('User "%s" added', $newUser->getUsername())
91 return $this->redirect($this->generateUrl('config'));
94 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
95 'configForm' => $configForm->createView(),
96 'pwdForm' => $pwdForm->createView(),
97 'userForm' => $userForm->createView(),
98 'newUserForm' => $newUserForm->createView(),
103 * Retrieve config for the current user.
104 * If no config were found, create a new one.
106 * @return Wallabag\CoreBundle\Entity\Config
108 private function getConfig()
110 $config = $this->getDoctrine()
111 ->getRepository('WallabagCoreBundle:Config')
112 ->findOneByUser($this->getUser());
115 $config = new Config($this->getUser());