aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy <jeremy.benoist@gmail.com>2015-03-28 00:10:39 +0100
committerJeremy <jeremy.benoist@gmail.com>2015-04-01 21:23:27 +0200
commitc844dc0c50bb4f1044154401310af25eb21b0f11 (patch)
treea4572193af600a8170b220c0c186bc46d6dd3d8e /src
parent1a93ee423b072ec3bcb0c437cbf9b488bdea245c (diff)
downloadwallabag-c844dc0c50bb4f1044154401310af25eb21b0f11.tar.gz
wallabag-c844dc0c50bb4f1044154401310af25eb21b0f11.tar.zst
wallabag-c844dc0c50bb4f1044154401310af25eb21b0f11.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php4
-rw-r--r--src/Wallabag/CoreBundle/Entity/User.php4
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/UserInformationType.php (renamed from src/Wallabag/CoreBundle/Form/Type/UserType.php)5
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig8
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php37
5 files changed, 25 insertions, 33 deletions
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;
9use Wallabag\CoreBundle\Entity\Config; 9use Wallabag\CoreBundle\Entity\Config;
10use Wallabag\CoreBundle\Entity\User; 10use Wallabag\CoreBundle\Entity\User;
11use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 11use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
12use Wallabag\CoreBundle\Form\Type\UserType; 12use Wallabag\CoreBundle\Form\Type\UserInformationType;
13use Wallabag\CoreBundle\Form\Type\NewUserType; 13use Wallabag\CoreBundle\Form\Type\NewUserType;
14use Wallabag\CoreBundle\Form\Type\RssType; 14use Wallabag\CoreBundle\Form\Type\RssType;
15use Wallabag\CoreBundle\Tools\Utils; 15use Wallabag\CoreBundle\Tools\Utils;
@@ -65,7 +65,7 @@ class ConfigController extends Controller
65 } 65 }
66 66
67 // handle changing user information 67 // handle changing user information
68 $userForm = $this->createForm(new UserType(), $user); 68 $userForm = $this->createForm(new UserInformationType(), $user);
69 $userForm->handleRequest($request); 69 $userForm->handleRequest($request);
70 70
71 if ($userForm->isValid()) { 71 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;
4 4
5use Doctrine\Common\Collections\ArrayCollection; 5use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
7use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
7use Symfony\Component\Security\Core\User\UserInterface; 8use Symfony\Component\Security\Core\User\UserInterface;
8use Symfony\Component\Security\Core\User\AdvancedUserInterface; 9use Symfony\Component\Security\Core\User\AdvancedUserInterface;
9use Symfony\Component\Validator\Constraints as Assert; 10use Symfony\Component\Validator\Constraints as Assert;
@@ -17,6 +18,9 @@ use JMS\Serializer\Annotation\Expose;
17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository") 18 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
18 * @ORM\HasLifecycleCallbacks() 19 * @ORM\HasLifecycleCallbacks()
19 * @ExclusionPolicy("all") 20 * @ExclusionPolicy("all")
21 *
22 * @UniqueEntity("email")
23 * @UniqueEntity("username")
20 */ 24 */
21class User implements AdvancedUserInterface, \Serializable 25class User implements AdvancedUserInterface, \Serializable
22{ 26{
diff --git a/src/Wallabag/CoreBundle/Form/Type/UserType.php b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php
index b479a0b5..617722db 100644
--- a/src/Wallabag/CoreBundle/Form/Type/UserType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php
@@ -5,12 +5,11 @@ use Symfony\Component\Form\AbstractType;
5use Symfony\Component\Form\FormBuilderInterface; 5use Symfony\Component\Form\FormBuilderInterface;
6use Symfony\Component\OptionsResolver\OptionsResolverInterface; 6use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7 7
8class UserType extends AbstractType 8class UserInformationType extends AbstractType
9{ 9{
10 public function buildForm(FormBuilderInterface $builder, array $options) 10 public function buildForm(FormBuilderInterface $builder, array $options)
11 { 11 {
12 $builder 12 $builder
13 ->add('username', 'text')
14 ->add('name', 'text') 13 ->add('name', 'text')
15 ->add('email', 'text') 14 ->add('email', 'text')
16 ->add('save', 'submit') 15 ->add('save', 'submit')
@@ -26,6 +25,6 @@ class UserType extends AbstractType
26 25
27 public function getName() 26 public function getName()
28 { 27 {
29 return 'user'; 28 return 'update_user';
30 } 29 }
31} 30}
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
@@ -86,14 +86,6 @@
86 86
87 <fieldset class="w500p inline"> 87 <fieldset class="w500p inline">
88 <div class="row"> 88 <div class="row">
89 {{ form_label(form.user.username) }}
90 {{ form_errors(form.user.username) }}
91 {{ form_widget(form.user.username) }}
92 </div>
93 </fieldset>
94
95 <fieldset class="w500p inline">
96 <div class="row">
97 {{ form_label(form.user.name) }} 89 {{ form_label(form.user.name) }}
98 {{ form_errors(form.user.name) }} 90 {{ form_errors(form.user.name) }}
99 {{ form_widget(form.user.name) }} 91 {{ form_widget(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
27 27
28 $this->assertCount(1, $crawler->filter('button[id=config_save]')); 28 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); 29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=user_save]')); 30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
31 $this->assertCount(1, $crawler->filter('button[id=new_user_save]')); 31 $this->assertCount(1, $crawler->filter('button[id=new_user_save]'));
32 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); 32 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
33 } 33 }
@@ -189,25 +189,15 @@ class ConfigControllerTest extends WallabagTestCase
189 return array( 189 return array(
190 array( 190 array(
191 array( 191 array(
192 'user[username]' => '', 192 'update_user[name]' => '',
193 'user[name]' => '', 193 'update_user[email]' => '',
194 'user[email]' => '',
195 ), 194 ),
196 'This value should not be blank.', 195 'This value should not be blank.',
197 ), 196 ),
198 array( 197 array(
199 array( 198 array(
200 'user[username]' => 'ad', 199 'update_user[name]' => '',
201 'user[name]' => '', 200 'update_user[email]' => 'test',
202 'user[email]' => '',
203 ),
204 'This value is too short.',
205 ),
206 array(
207 array(
208 'user[username]' => 'admin',
209 'user[name]' => '',
210 'user[email]' => 'test',
211 ), 201 ),
212 'This value is not a valid email address.', 202 'This value is not a valid email address.',
213 ), 203 ),
@@ -226,7 +216,7 @@ class ConfigControllerTest extends WallabagTestCase
226 216
227 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 217 $this->assertEquals(200, $client->getResponse()->getStatusCode());
228 218
229 $form = $crawler->filter('button[id=user_save]')->form(); 219 $form = $crawler->filter('button[id=update_user_save]')->form();
230 220
231 $crawler = $client->submit($form, $data); 221 $crawler = $client->submit($form, $data);
232 222
@@ -245,12 +235,11 @@ class ConfigControllerTest extends WallabagTestCase
245 235
246 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 236 $this->assertEquals(200, $client->getResponse()->getStatusCode());
247 237
248 $form = $crawler->filter('button[id=user_save]')->form(); 238 $form = $crawler->filter('button[id=update_user_save]')->form();
249 239
250 $data = array( 240 $data = array(
251 'user[username]' => 'admin', 241 'update_user[name]' => 'new name',
252 'user[name]' => 'new name', 242 'update_user[email]' => 'admin@wallabag.io',
253 'user[email]' => 'admin@wallabag.io',
254 ); 243 );
255 244
256 $client->submit($form, $data); 245 $client->submit($form, $data);
@@ -298,6 +287,14 @@ class ConfigControllerTest extends WallabagTestCase
298 ), 287 ),
299 'Password should by at least', 288 'Password should by at least',
300 ), 289 ),
290 array(
291 array(
292 'new_user[username]' => 'admin',
293 'new_user[password]' => 'wallacewallace',
294 'new_user[email]' => 'wallace@wallace.me',
295 ),
296 'This value is already used',
297 ),
301 ); 298 );
302 } 299 }
303 300