From e4977b8a866f84f65f08c55c050a62f40170fdbf Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 22 Feb 2015 09:30:25 +0100 Subject: Adding new user --- .../CoreBundle/Controller/ConfigController.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index b3236e3c..aedbc999 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -6,9 +6,11 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\User; use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; use Wallabag\CoreBundle\Form\Type\UserType; +use Wallabag\CoreBundle\Form\Type\NewUserType; class ConfigController extends Controller { @@ -72,10 +74,28 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config')); } + // handle adding new user + $newUser = new User(); + $newUserForm = $this->createForm(new NewUserType(), $newUser); + $newUserForm->handleRequest($request); + + if ($newUserForm->isValid()) { + $em->persist($newUser); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + sprintf('User "%s" added', $newUser->getUsername()) + ); + + return $this->redirect($this->generateUrl('config')); + } + return $this->render('WallabagCoreBundle:Config:index.html.twig', array( 'configForm' => $configForm->createView(), 'pwdForm' => $pwdForm->createView(), 'userForm' => $userForm->createView(), + 'newUserForm' => $newUserForm->createView(), )); } -- cgit v1.2.3