From c844dc0c50bb4f1044154401310af25eb21b0f11 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 28 Mar 2015 00:10:39 +0100 Subject: Remove ability to change username Since password are linked to username it was hard to change username while checking that the password is the good one. Instead of doing crazy things to achieve that, I act that user won't be able to update username. Also, username (and email) must be unique, since people logged in using username and can request a new password using email. This should fix #1149 --- .../CoreBundle/Controller/ConfigController.php | 4 +-- src/Wallabag/CoreBundle/Entity/User.php | 4 +++ .../CoreBundle/Form/Type/UserInformationType.php | 30 ++++++++++++++++++ src/Wallabag/CoreBundle/Form/Type/UserType.php | 31 ------------------ .../Resources/views/Config/index.html.twig | 8 ----- .../Tests/Controller/ConfigControllerTest.php | 37 ++++++++++------------ 6 files changed, 53 insertions(+), 61 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Form/Type/UserInformationType.php delete mode 100644 src/Wallabag/CoreBundle/Form/Type/UserType.php diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index dbae3ea7..898c291f 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\User; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; -use Wallabag\CoreBundle\Form\Type\UserType; +use Wallabag\CoreBundle\Form\Type\UserInformationType; use Wallabag\CoreBundle\Form\Type\NewUserType; use Wallabag\CoreBundle\Form\Type\RssType; use Wallabag\CoreBundle\Tools\Utils; @@ -65,7 +65,7 @@ class ConfigController extends Controller } // handle changing user information - $userForm = $this->createForm(new UserType(), $user); + $userForm = $this->createForm(new UserInformationType(), $user); $userForm->handleRequest($request); if ($userForm->isValid()) { diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index e75e3a83..63ec072c 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\AdvancedUserInterface; use Symfony\Component\Validator\Constraints as Assert; @@ -17,6 +18,9 @@ use JMS\Serializer\Annotation\Expose; * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository") * @ORM\HasLifecycleCallbacks() * @ExclusionPolicy("all") + * + * @UniqueEntity("email") + * @UniqueEntity("username") */ class User implements AdvancedUserInterface, \Serializable { diff --git a/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php new file mode 100644 index 00000000..617722db --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php @@ -0,0 +1,30 @@ +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 'update_user'; + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/UserType.php b/src/Wallabag/CoreBundle/Form/Type/UserType.php deleted file mode 100644 index b479a0b5..00000000 --- a/src/Wallabag/CoreBundle/Form/Type/UserType.php +++ /dev/null @@ -1,31 +0,0 @@ -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 f2a98dfb..c90bb2e3 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig @@ -84,14 +84,6 @@
{{ form_errors(form.user) }} -
-
- {{ form_label(form.user.username) }} - {{ form_errors(form.user.username) }} - {{ form_widget(form.user.username) }} -
-
-
{{ form_label(form.user.name) }} diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 11c86423..5030bcbd 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -27,7 +27,7 @@ class ConfigControllerTest extends WallabagTestCase $this->assertCount(1, $crawler->filter('button[id=config_save]')); $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); - $this->assertCount(1, $crawler->filter('button[id=user_save]')); + $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); $this->assertCount(1, $crawler->filter('button[id=new_user_save]')); $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); } @@ -189,25 +189,15 @@ class ConfigControllerTest extends WallabagTestCase return array( array( array( - 'user[username]' => '', - 'user[name]' => '', - 'user[email]' => '', + 'update_user[name]' => '', + 'update_user[email]' => '', ), 'This value should not be blank.', ), array( array( - 'user[username]' => 'ad', - 'user[name]' => '', - 'user[email]' => '', - ), - 'This value is too short.', - ), - array( - array( - 'user[username]' => 'admin', - 'user[name]' => '', - 'user[email]' => 'test', + 'update_user[name]' => '', + 'update_user[email]' => 'test', ), 'This value is not a valid email address.', ), @@ -226,7 +216,7 @@ class ConfigControllerTest extends WallabagTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $form = $crawler->filter('button[id=user_save]')->form(); + $form = $crawler->filter('button[id=update_user_save]')->form(); $crawler = $client->submit($form, $data); @@ -245,12 +235,11 @@ class ConfigControllerTest extends WallabagTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $form = $crawler->filter('button[id=user_save]')->form(); + $form = $crawler->filter('button[id=update_user_save]')->form(); $data = array( - 'user[username]' => 'admin', - 'user[name]' => 'new name', - 'user[email]' => 'admin@wallabag.io', + 'update_user[name]' => 'new name', + 'update_user[email]' => 'admin@wallabag.io', ); $client->submit($form, $data); @@ -298,6 +287,14 @@ class ConfigControllerTest extends WallabagTestCase ), 'Password should by at least', ), + array( + array( + 'new_user[username]' => 'admin', + 'new_user[password]' => 'wallacewallace', + 'new_user[email]' => 'wallace@wallace.me', + ), + 'This value is already used', + ), ); } -- cgit v1.2.3