aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/ConfigController.php
diff options
context:
space:
mode:
authorJeremy <jeremy.benoist@gmail.com>2015-02-17 21:03:23 +0100
committerJeremy <jeremy.benoist@gmail.com>2015-02-17 21:03:23 +0100
commitd9085c63e35bb708f560722fff5f4f5ad322c27b (patch)
tree73e2183afe218442ce44faffe469e31f630d89d9 /src/Wallabag/CoreBundle/Controller/ConfigController.php
parent7781faa0b0749b0d9842fddec3e337db04d44a10 (diff)
downloadwallabag-d9085c63e35bb708f560722fff5f4f5ad322c27b.tar.gz
wallabag-d9085c63e35bb708f560722fff5f4f5ad322c27b.tar.zst
wallabag-d9085c63e35bb708f560722fff5f4f5ad322c27b.zip
Handle password change
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index f48a9cb1..7540f756 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Config; 8use Wallabag\CoreBundle\Entity\Config;
9use Wallabag\CoreBundle\Form\Type\ConfigType; 9use Wallabag\CoreBundle\Form\Type\ConfigType;
10use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
10 11
11class ConfigController extends Controller 12class ConfigController extends Controller
12{ 13{
@@ -14,19 +15,18 @@ class ConfigController extends Controller
14 * @param Request $request 15 * @param Request $request
15 * 16 *
16 * @Route("/config", name="config") 17 * @Route("/config", name="config")
17 *
18 * @return \Symfony\Component\HttpFoundation\Response
19 */ 18 */
20 public function indexAction(Request $request) 19 public function indexAction(Request $request)
21 { 20 {
21 $em = $this->getDoctrine()->getManager();
22 $config = $this->getConfig(); 22 $config = $this->getConfig();
23 23
24 $form = $this->createForm(new ConfigType(), $config); 24 // handle basic config detail
25 $configForm = $this->createForm(new ConfigType(), $config);
26 $configForm->handleRequest($request);
25 27
26 $form->handleRequest($request); 28 if ($configForm->isValid()) {
27 29
28 if ($form->isValid()) {
29 $em = $this->getDoctrine()->getManager();
30 $em->persist($config); 30 $em->persist($config);
31 $em->flush(); 31 $em->flush();
32 32
@@ -38,11 +38,36 @@ class ConfigController extends Controller
38 return $this->redirect($this->generateUrl('config')); 38 return $this->redirect($this->generateUrl('config'));
39 } 39 }
40 40
41 // handle changing password
42 $pwdForm = $this->createForm(new ChangePasswordType());
43 $pwdForm->handleRequest($request);
44
45 if ($pwdForm->isValid()) {
46 $user = $this->getUser();
47 $user->setPassword($pwdForm->get('new_password')->getData());
48 $em->persist($user);
49 $em->flush();
50
51 $this->get('session')->getFlashBag()->add(
52 'notice',
53 'Password updated'
54 );
55
56 return $this->redirect($this->generateUrl('config'));
57 }
58
41 return $this->render('WallabagCoreBundle:Config:index.html.twig', array( 59 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
42 'form' => $form->createView(), 60 'configForm' => $configForm->createView(),
61 'pwdForm' => $pwdForm->createView(),
43 )); 62 ));
44 } 63 }
45 64
65 /**
66 * Retrieve config for the current user.
67 * If no config were found, create a new one.
68 *
69 * @return Wallabag\CoreBundle\Entity\Config
70 */
46 private function getConfig() 71 private function getConfig()
47 { 72 {
48 $config = $this->getDoctrine() 73 $config = $this->getDoctrine()