aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php21
-rw-r--r--src/Wallabag/CoreBundle/Entity/User.php19
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php9
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/ConfigType.php2
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/UserType.php31
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig34
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php89
7 files changed, 185 insertions, 20 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 7540f756..b3236e3c 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Config; 8use Wallabag\CoreBundle\Entity\Config;
9use Wallabag\CoreBundle\Form\Type\ConfigType; 9use Wallabag\CoreBundle\Form\Type\ConfigType;
10use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 10use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
11use Wallabag\CoreBundle\Form\Type\UserType;
11 12
12class ConfigController extends Controller 13class ConfigController extends Controller
13{ 14{
@@ -20,13 +21,13 @@ class ConfigController extends Controller
20 { 21 {
21 $em = $this->getDoctrine()->getManager(); 22 $em = $this->getDoctrine()->getManager();
22 $config = $this->getConfig(); 23 $config = $this->getConfig();
24 $user = $this->getUser();
23 25
24 // handle basic config detail 26 // handle basic config detail
25 $configForm = $this->createForm(new ConfigType(), $config); 27 $configForm = $this->createForm(new ConfigType(), $config);
26 $configForm->handleRequest($request); 28 $configForm->handleRequest($request);
27 29
28 if ($configForm->isValid()) { 30 if ($configForm->isValid()) {
29
30 $em->persist($config); 31 $em->persist($config);
31 $em->flush(); 32 $em->flush();
32 33
@@ -43,7 +44,6 @@ class ConfigController extends Controller
43 $pwdForm->handleRequest($request); 44 $pwdForm->handleRequest($request);
44 45
45 if ($pwdForm->isValid()) { 46 if ($pwdForm->isValid()) {
46 $user = $this->getUser();
47 $user->setPassword($pwdForm->get('new_password')->getData()); 47 $user->setPassword($pwdForm->get('new_password')->getData());
48 $em->persist($user); 48 $em->persist($user);
49 $em->flush(); 49 $em->flush();
@@ -56,9 +56,26 @@ class ConfigController extends Controller
56 return $this->redirect($this->generateUrl('config')); 56 return $this->redirect($this->generateUrl('config'));
57 } 57 }
58 58
59 // handle changing user information
60 $userForm = $this->createForm(new UserType(), $user);
61 $userForm->handleRequest($request);
62
63 if ($userForm->isValid()) {
64 $em->persist($user);
65 $em->flush();
66
67 $this->get('session')->getFlashBag()->add(
68 'notice',
69 'Information updated'
70 );
71
72 return $this->redirect($this->generateUrl('config'));
73 }
74
59 return $this->render('WallabagCoreBundle:Config:index.html.twig', array( 75 return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
60 'configForm' => $configForm->createView(), 76 'configForm' => $configForm->createView(),
61 'pwdForm' => $pwdForm->createView(), 77 'pwdForm' => $pwdForm->createView(),
78 'userForm' => $userForm->createView(),
62 )); 79 ));
63 } 80 }
64 81
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php
index c83250c3..193dfebc 100644
--- a/src/Wallabag/CoreBundle/Entity/User.php
+++ b/src/Wallabag/CoreBundle/Entity/User.php
@@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
7use Symfony\Component\Security\Core\User\UserInterface; 7use Symfony\Component\Security\Core\User\UserInterface;
8use Symfony\Component\Security\Core\User\AdvancedUserInterface; 8use Symfony\Component\Security\Core\User\AdvancedUserInterface;
9use Symfony\Component\Validator\Constraints as Assert;
9 10
10/** 11/**
11 * User 12 * User
@@ -29,6 +30,11 @@ class User implements AdvancedUserInterface, \Serializable
29 * @var string 30 * @var string
30 * 31 *
31 * @ORM\Column(name="username", type="text") 32 * @ORM\Column(name="username", type="text")
33 * @Assert\NotBlank()
34 * @Assert\Length(
35 * min = "3",
36 * max = "255"
37 * )
32 */ 38 */
33 private $username; 39 private $username;
34 40
@@ -56,14 +62,16 @@ class User implements AdvancedUserInterface, \Serializable
56 /** 62 /**
57 * @var string 63 * @var string
58 * 64 *
59 * @ORM\Column(name="email", type="text", nullable=true) 65 * @ORM\Column(name="email", type="text", nullable=false)
66 * @Assert\Email()
67 * @Assert\NotBlank()
60 */ 68 */
61 private $email; 69 private $email;
62 70
63 /** 71 /**
64 * @ORM\Column(name="is_active", type="boolean") 72 * @ORM\Column(name="is_active", type="boolean", nullable=false)
65 */ 73 */
66 private $isActive; 74 private $isActive = true;
67 75
68 /** 76 /**
69 * @var date 77 * @var date
@@ -86,9 +94,8 @@ class User implements AdvancedUserInterface, \Serializable
86 94
87 public function __construct() 95 public function __construct()
88 { 96 {
89 $this->isActive = true; 97 $this->salt = md5(uniqid(null, true));
90 $this->salt = md5(uniqid(null, true)); 98 $this->entries = new ArrayCollection();
91 $this->entries = new ArrayCollection();
92 } 99 }
93 100
94 /** 101 /**
diff --git a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php
index 8bf4ca1e..de0ad537 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;
3 3
4use Symfony\Component\Form\AbstractType; 4use Symfony\Component\Form\AbstractType;
5use Symfony\Component\Form\FormBuilderInterface; 5use Symfony\Component\Form\FormBuilderInterface;
6use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; 6use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
8use Symfony\Component\Validator\Constraints; 7use Symfony\Component\Validator\Constraints;
9 8
@@ -23,11 +22,11 @@ class ChangePasswordType extends AbstractType
23 'second_options' => array('label' => 'Repeat new password'), 22 'second_options' => array('label' => 'Repeat new password'),
24 'constraints' => array( 23 'constraints' => array(
25 new Constraints\Length(array( 24 new Constraints\Length(array(
26 'min' => 6, 25 'min' => 8,
27 'minMessage' => 'Password should by at least 6 chars long' 26 'minMessage' => 'Password should by at least 6 chars long',
28 )), 27 )),
29 new Constraints\NotBlank() 28 new Constraints\NotBlank(),
30 ) 29 ),
31 )) 30 ))
32 ->add('save', 'submit') 31 ->add('save', 'submit')
33 ; 32 ;
diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
index 74e2a6f1..a1e0ce47 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
21 'solarized_dark' => 'Solarized Dark', 21 'solarized_dark' => 'Solarized Dark',
22 ), 22 ),
23 )) 23 ))
24 ->add('items_per_page') 24 ->add('items_per_page', 'text')
25 ->add('language') 25 ->add('language')
26 ->add('save', 'submit') 26 ->add('save', 'submit')
27 ; 27 ;
diff --git a/src/Wallabag/CoreBundle/Form/Type/UserType.php b/src/Wallabag/CoreBundle/Form/Type/UserType.php
new file mode 100644
index 00000000..b479a0b5
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Form/Type/UserType.php
@@ -0,0 +1,31 @@
1<?php
2namespace Wallabag\CoreBundle\Form\Type;
3
4use Symfony\Component\Form\AbstractType;
5use Symfony\Component\Form\FormBuilderInterface;
6use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7
8class UserType extends AbstractType
9{
10 public function buildForm(FormBuilderInterface $builder, array $options)
11 {
12 $builder
13 ->add('username', 'text')
14 ->add('name', 'text')
15 ->add('email', 'text')
16 ->add('save', 'submit')
17 ;
18 }
19
20 public function setDefaultOptions(OptionsResolverInterface $resolver)
21 {
22 $resolver->setDefaults(array(
23 'data_class' => 'Wallabag\CoreBundle\Entity\User',
24 ));
25 }
26
27 public function getName()
28 {
29 return 'user';
30 }
31}
diff --git a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig
index 94145177..7a45ec1f 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 @@
7{% endblock %} 7{% endblock %}
8 8
9{% block content %} 9{% block content %}
10 <h2>{% trans %}Basic config{% endtrans %}</h2> 10 <h2>{% trans %}Wallabag configuration{% endtrans %}</h2>
11 11
12 <form action="{{ path('config') }}" method="post" {{ form_enctype(configForm) }}> 12 <form action="{{ path('config') }}" method="post" {{ form_enctype(configForm) }}>
13 {{ form_errors(configForm) }} 13 {{ form_errors(configForm) }}
@@ -39,6 +39,38 @@
39 {{ form_rest(configForm) }} 39 {{ form_rest(configForm) }}
40 </form> 40 </form>
41 41
42 <h2>{% trans %}User information{% endtrans %}</h2>
43
44 <form action="{{ path('config') }}" method="post" {{ form_enctype(userForm) }}>
45 {{ form_errors(userForm) }}
46
47 <fieldset class="w500p inline">
48 <div class="row">
49 {{ form_label(userForm.username) }}
50 {{ form_errors(userForm.username) }}
51 {{ form_widget(userForm.username) }}
52 </div>
53 </fieldset>
54
55 <fieldset class="w500p inline">
56 <div class="row">
57 {{ form_label(userForm.name) }}
58 {{ form_errors(userForm.name) }}
59 {{ form_widget(userForm.name) }}
60 </div>
61 </fieldset>
62
63 <fieldset class="w500p inline">
64 <div class="row">
65 {{ form_label(userForm.email) }}
66 {{ form_errors(userForm.email) }}
67 {{ form_widget(userForm.email) }}
68 </div>
69 </fieldset>
70
71 {{ form_rest(userForm) }}
72 </form>
73
42 <h2>{% trans %}Change your password{% endtrans %}</h2> 74 <h2>{% trans %}Change your password{% endtrans %}</h2>
43 75
44 <form action="{{ path('config') }}" method="post" {{ form_enctype(pwdForm) }}> 76 <form action="{{ path('config') }}" method="post" {{ form_enctype(pwdForm) }}>
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
index 4aceed15..519b4ba2 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
@@ -25,9 +25,9 @@ class ConfigControllerTest extends WallabagTestCase
25 25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27 27
28 $this->assertCount(1, $crawler->filter('input[type=number]'));
29 $this->assertCount(1, $crawler->filter('button[id=config_save]')); 28 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
30 $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]'));
31 } 31 }
32 32
33 public function testUpdate() 33 public function testUpdate()
@@ -104,7 +104,7 @@ class ConfigControllerTest extends WallabagTestCase
104 'change_passwd[new_password][first]' => '', 104 'change_passwd[new_password][first]' => '',
105 'change_passwd[new_password][second]' => '', 105 'change_passwd[new_password][second]' => '',
106 ), 106 ),
107 'Wrong value for your current password' 107 'Wrong value for your current password',
108 ), 108 ),
109 array( 109 array(
110 array( 110 array(
@@ -112,7 +112,7 @@ class ConfigControllerTest extends WallabagTestCase
112 'change_passwd[new_password][first]' => '', 112 'change_passwd[new_password][first]' => '',
113 'change_passwd[new_password][second]' => '', 113 'change_passwd[new_password][second]' => '',
114 ), 114 ),
115 'This value should not be blank' 115 'This value should not be blank',
116 ), 116 ),
117 array( 117 array(
118 array( 118 array(
@@ -120,7 +120,7 @@ class ConfigControllerTest extends WallabagTestCase
120 'change_passwd[new_password][first]' => 'hop', 120 'change_passwd[new_password][first]' => 'hop',
121 'change_passwd[new_password][second]' => '', 121 'change_passwd[new_password][second]' => '',
122 ), 122 ),
123 'The password fields must match' 123 'The password fields must match',
124 ), 124 ),
125 array( 125 array(
126 array( 126 array(
@@ -128,7 +128,7 @@ class ConfigControllerTest extends WallabagTestCase
128 'change_passwd[new_password][first]' => 'hop', 128 'change_passwd[new_password][first]' => 'hop',
129 'change_passwd[new_password][second]' => 'hop', 129 'change_passwd[new_password][second]' => 'hop',
130 ), 130 ),
131 'Password should by at least 6 chars long' 131 'Password should by at least 6 chars long',
132 ), 132 ),
133 ); 133 );
134 } 134 }
@@ -181,4 +181,83 @@ class ConfigControllerTest extends WallabagTestCase
181 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text'))); 181 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
182 $this->assertContains('Password updated', $alert[0]); 182 $this->assertContains('Password updated', $alert[0]);
183 } 183 }
184
185 public function dataForUserFailed()
186 {
187 return array(
188 array(
189 array(
190 'user[username]' => '',
191 'user[name]' => '',
192 'user[email]' => '',
193 ),
194 'This value should not be blank.',
195 ),
196 array(
197 array(
198 'user[username]' => 'ad',
199 'user[name]' => '',
200 'user[email]' => '',
201 ),
202 'This value is too short.',
203 ),
204 array(
205 array(
206 'user[username]' => 'admin',
207 'user[name]' => '',
208 'user[email]' => 'test',
209 ),
210 'This value is not a valid email address.',
211 ),
212 );
213 }
214
215 /**
216 * @dataProvider dataForUserFailed
217 */
218 public function testUserFailed($data, $expectedMessage)
219 {
220 $this->logInAs('admin');
221 $client = $this->getClient();
222
223 $crawler = $client->request('GET', '/config');
224
225 $this->assertEquals(200, $client->getResponse()->getStatusCode());
226
227 $form = $crawler->filter('button[id=user_save]')->form();
228
229 $crawler = $client->submit($form, $data);
230
231 $this->assertEquals(200, $client->getResponse()->getStatusCode());
232
233 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
234 $this->assertContains($expectedMessage, $alert[0]);
235 }
236
237 public function testUserUpdate()
238 {
239 $this->logInAs('admin');
240 $client = $this->getClient();
241
242 $crawler = $client->request('GET', '/config');
243
244 $this->assertEquals(200, $client->getResponse()->getStatusCode());
245
246 $form = $crawler->filter('button[id=user_save]')->form();
247
248 $data = array(
249 'user[username]' => 'admin',
250 'user[name]' => 'new name',
251 'user[email]' => 'admin@wallabag.io',
252 );
253
254 $client->submit($form, $data);
255
256 $this->assertEquals(302, $client->getResponse()->getStatusCode());
257
258 $crawler = $client->followRedirect();
259
260 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
261 $this->assertContains('Information updated', $alert[0]);
262 }
184} 263}