diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 7540f756c..b3236e3ce 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Request; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; +use Wallabag\CoreBundle\Form\Type\UserType; class ConfigController extends Controller { @@ -20,13 +21,13 @@ class ConfigController extends Controller { $em = $this->getDoctrine()->getManager(); $config = $this->getConfig(); + $user = $this->getUser(); // handle basic config detail $configForm = $this->createForm(new ConfigType(), $config); $configForm->handleRequest($request); if ($configForm->isValid()) { - $em->persist($config); $em->flush(); @@ -43,7 +44,6 @@ class ConfigController extends Controller $pwdForm->handleRequest($request); if ($pwdForm->isValid()) { - $user = $this->getUser(); $user->setPassword($pwdForm->get('new_password')->getData()); $em->persist($user); $em->flush(); @@ -56,9 +56,26 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config')); } + // handle changing user information + $userForm = $this->createForm(new UserType(), $user); + $userForm->handleRequest($request); + + if ($userForm->isValid()) { + $em->persist($user); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Information updated' + ); + + return $this->redirect($this->generateUrl('config')); + } + return $this->render('WallabagCoreBundle:Config:index.html.twig', array( 'configForm' => $configForm->createView(), 'pwdForm' => $pwdForm->createView(), + 'userForm' => $userForm->createView(), )); } diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index c83250c37..193dfebc2 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\AdvancedUserInterface; +use Symfony\Component\Validator\Constraints as Assert; /** * User @@ -29,6 +30,11 @@ class User implements AdvancedUserInterface, \Serializable * @var string * * @ORM\Column(name="username", type="text") + * @Assert\NotBlank() + * @Assert\Length( + * min = "3", + * max = "255" + * ) */ private $username; @@ -56,14 +62,16 @@ class User implements AdvancedUserInterface, \Serializable /** * @var string * - * @ORM\Column(name="email", type="text", nullable=true) + * @ORM\Column(name="email", type="text", nullable=false) + * @Assert\Email() + * @Assert\NotBlank() */ private $email; /** - * @ORM\Column(name="is_active", type="boolean") + * @ORM\Column(name="is_active", type="boolean", nullable=false) */ - private $isActive; + private $isActive = true; /** * @var date @@ -86,9 +94,8 @@ class User implements AdvancedUserInterface, \Serializable public function __construct() { - $this->isActive = true; - $this->salt = md5(uniqid(null, true)); - $this->entries = new ArrayCollection(); + $this->salt = md5(uniqid(null, true)); + $this->entries = new ArrayCollection(); } /** diff --git a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php index 8bf4ca1ef..de0ad5378 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php @@ -3,7 +3,6 @@ namespace Wallabag\CoreBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; use Symfony\Component\Validator\Constraints; @@ -23,11 +22,11 @@ class ChangePasswordType extends AbstractType 'second_options' => array('label' => 'Repeat new password'), 'constraints' => array( new Constraints\Length(array( - 'min' => 6, - 'minMessage' => 'Password should by at least 6 chars long' + 'min' => 8, + 'minMessage' => 'Password should by at least 6 chars long', )), - new Constraints\NotBlank() - ) + new Constraints\NotBlank(), + ), )) ->add('save', 'submit') ; diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php index 74e2a6f14..a1e0ce47d 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php @@ -21,7 +21,7 @@ class ConfigType extends AbstractType 'solarized_dark' => 'Solarized Dark', ), )) - ->add('items_per_page') + ->add('items_per_page', 'text') ->add('language') ->add('save', 'submit') ; diff --git a/src/Wallabag/CoreBundle/Form/Type/UserType.php b/src/Wallabag/CoreBundle/Form/Type/UserType.php new file mode 100644 index 000000000..b479a0b58 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/UserType.php @@ -0,0 +1,31 @@ +add('username', 'text') + ->add('name', 'text') + ->add('email', 'text') + ->add('save', 'submit') + ; + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Wallabag\CoreBundle\Entity\User', + )); + } + + public function getName() + { + return 'user'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig index 941451778..7a45ec1f1 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig @@ -7,7 +7,7 @@ {% endblock %} {% block content %} -