diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index b3236e3ce..aedbc9999 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(), )); } diff --git a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php index de0ad5378..e141789f1 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php @@ -23,7 +23,7 @@ class ChangePasswordType extends AbstractType 'constraints' => array( new Constraints\Length(array( 'min' => 8, - 'minMessage' => 'Password should by at least 6 chars long', + 'minMessage' => 'Password should by at least 8 chars long', )), new Constraints\NotBlank(), ), diff --git a/src/Wallabag/CoreBundle/Form/Type/NewUserType.php b/src/Wallabag/CoreBundle/Form/Type/NewUserType.php new file mode 100644 index 000000000..313a9aae8 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/NewUserType.php @@ -0,0 +1,40 @@ +add('username', 'text') + ->add('password', 'password', array( + 'constraints' => array( + new Constraints\Length(array( + 'min' => 8, + 'minMessage' => 'Password should by at least 8 chars long', + )), + new Constraints\NotBlank(), + ), + )) + ->add('email', 'text') + ->add('save', 'submit') + ; + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Wallabag\CoreBundle\Entity\User', + )); + } + + public function getName() + { + return 'new_user'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig index 7a45ec1f1..051dafd6b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig @@ -102,4 +102,36 @@ {{ form_rest(pwdForm) }} + +