Pārlūkot izejas kodu

Evolution #701: Nopass: Saisie du mot de passe

Bastien Sevajol 11 gadus atpakaļ
vecāks
revīzija
5de7a72b7f

+ 1 - 0
app/Resources/translations/userui.en.yml Parādīt failu

@@ -51,6 +51,7 @@ my_account:
51 51
   change_password_submit: Mettre à jour mon mot de passe
52 52
   change_email:     Changer mon adresse email
53 53
   change_email_submit: Mettre à jour mon email
54
+  choose_password:  Choisir un mot de passe pour mon compte
54 55
   address:
55 56
     title:          Mon adresse
56 57
     description:    Avec votre adresse Muzi.ch pourra vous avertir plus aisément des événements à venirs dans votre région.

+ 1 - 0
app/Resources/translations/userui.fr.yml Parādīt failu

@@ -52,6 +52,7 @@ my_account:
52 52
   change_password_submit: Mettre à jour mon mot de passe
53 53
   change_email:     Changer mon adresse email
54 54
   change_email_submit: Mettre à jour mon email
55
+  choose_password:  Choisir un mot de passe pour mon compte
55 56
   address:
56 57
     title:          Mon adresse
57 58
     description:    Avec votre adresse Muzi.ch pourra vous avertir plus aisément des événements à venir dans votre région.

+ 16 - 0
src/Muzich/CoreBundle/Entity/User.php Parādīt failu

@@ -276,6 +276,12 @@ class User extends BaseUser
276 276
   protected $email_confirmation_sent_timestamp = 0;
277 277
   
278 278
   /**
279
+   * @ORM\Column(type="boolean", nullable=false)
280
+   * @var type boolean
281
+   */
282
+  private $password_set = true;
283
+  
284
+  /**
279 285
    * 
280 286
    */
281 287
   public function __construct()
@@ -1150,4 +1156,14 @@ class User extends BaseUser
1150 1156
     return $this->email_confirmation_sent_timestamp;
1151 1157
   }
1152 1158
   
1159
+  public function isPasswordSet()
1160
+  {
1161
+    return ($this->password_set)?true:false;
1162
+  }
1163
+  
1164
+  public function setPasswordSet($set)
1165
+  {
1166
+    $this->password_set = ($set)?true:false;
1167
+  }
1168
+  
1153 1169
 }

+ 26 - 0
src/Muzich/CoreBundle/Form/User/PasswordForm.php Parādīt failu

@@ -0,0 +1,26 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Form\User;
4
+
5
+use Symfony\Component\Form\AbstractType;
6
+use Symfony\Component\Form\FormBuilderInterface;
7
+
8
+class PasswordForm extends AbstractType
9
+{
10
+  public function buildForm(FormBuilderInterface $builder, array $options)
11
+  {
12
+    $builder->add('plain_password', 'repeated', array(
13
+      'type' => 'password',
14
+      'options' => array('translation_domain' => 'FOSUserBundle'),
15
+      'first_options' => array('label' => 'form.new_password', 'always_empty' => true),
16
+      'second_options' => array('label' => 'form.new_password_confirmation', 'always_empty' => true),
17
+      'invalid_message' => 'fos_user.password.mismatch',
18
+    ));
19
+  }
20
+  
21
+  public function getName()
22
+  {
23
+    return 'user_password';
24
+  }
25
+
26
+}

+ 77 - 1
src/Muzich/CoreBundle/Resources/public/css/main.css Parādīt failu

@@ -2064,4 +2064,80 @@ li.user_name a
2064 2064
 
2065 2065
 li.user_name a:hover
2066 2066
 {
2067
-text-decoration: underline;
2067
+  text-decoration: underline;
2068
+}
2069
+
2070
+@-webkit-keyframes clignote
2071
+{
2072
+  0%{box-shadow:0px 0px 10px #909090;}
2073
+  50%{box-shadow:0px 0px 2px #909090;}
2074
+  100%{box-shadow:0px 0px 10px #909090;}
2075
+}
2076
+
2077
+@-moz-keyframes clignote
2078
+{
2079
+  0%{box-shadow:0px 0px 10px #909090;}
2080
+  50%{box-shadow:0px 0px 2px #909090;}
2081
+  100%{box-shadow:0px 0px 10px #909090;}
2082
+}
2083
+
2084
+@-ms-keyframes clignote
2085
+{
2086
+  0%{box-shadow:0px 0px 10px #909090;}
2087
+  50%{box-shadow:0px 0px 2px #909090;}
2088
+  100%{box-shadow:0px 0px 10px #909090;}
2089
+}
2090
+
2091
+@-o-keyframes clignote
2092
+{
2093
+  0%{box-shadow:0px 0px 10px #909090;}
2094
+  50%{box-shadow:0px 0px 2px #909090;}
2095
+  100%{box-shadow:0px 0px 10px #909090;}
2096
+}
2097
+
2098
+@keyframes clignote
2099
+{
2100
+  0%{box-shadow:0px 0px 10px #909090;}
2101
+  50%{box-shadow:0px 0px 2px #909090;}
2102
+  100%{box-shadow:0px 0px 10px #909090;}
2103
+}
2104
+
2105
+
2106
+.flashing
2107
+{
2108
+  font-weight: bold;
2109
+  text-shadow: 0 1px 0 white;
2110
+  border-radius: 3px;
2111
+  padding: 5px 10px;
2112
+  box-shadow:0px 0px 10px #909090;
2113
+  
2114
+  -webkit-animation-name: clignote;
2115
+  -webkit-animation-duration: 1s;
2116
+  -webkit-animation-iteration-count:infinite;
2117
+  
2118
+  -moz-animation-name: clignote;
2119
+  -moz-animation-duration: 1s;
2120
+  -moz-animation-iteration-count:infinite;
2121
+  
2122
+  -ms-animation-name: clignote;
2123
+  -ms-animation-duration: 1s;
2124
+  -ms-animation-iteration-count:infinite;
2125
+  
2126
+  -o-animation-name: clignote;
2127
+  -o-animation-duration: 1s;
2128
+  -o-animation-iteration-count:infinite;
2129
+  
2130
+  animation-name: clignote;
2131
+  animation-duration: 1s;
2132
+  animation-iteration-count:infinite;
2133
+}
2134
+
2135
+div.myaccount_part.flashing
2136
+{
2137
+  padding: 2px;
2138
+}
2139
+
2140
+div.choose_password
2141
+{
2142
+  text-align: center;
2143
+}

+ 10 - 0
src/Muzich/CoreBundle/Resources/views/Layout/side.html.twig Parādīt failu

@@ -1,9 +1,19 @@
1 1
 {% if app.user %}
2
+  
2 3
   <div id="user_statusbox" class="nicebox">
3 4
     {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
4 5
       {% render "MuzichUserBundle:Event:infoBar" %}
5 6
     {% endif %}
6 7
   </div>
8
+
9
+  {% if not app.user.PasswordSet and not app.request.get('open') == 'change_password' %}
10
+    <div class="nicebox choose_password flashing">
11
+      <a href="{{ path('my_account', {'open':'change_password'}) }}">
12
+        {{ 'my_account.choose_password'|trans({}, 'userui') }}
13
+      </a>
14
+    </div>
15
+  {% endif %}
16
+
7 17
 {% else %}
8 18
   <div class="side_margin_top"></div>
9 19
 {% endif %}

+ 0 - 0
src/Muzich/CoreBundle/Security/Context.php Parādīt failu


+ 0 - 0
src/Muzich/CoreBundle/Tests/Security/ContextTest.php Parādīt failu


+ 36 - 32
src/Muzich/UserBundle/Controller/UserController.php Parādīt failu

@@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraints\Collection;
13 13
 use Symfony\Component\HttpFoundation\Request;
14 14
 use Muzich\UserBundle\Form\Type\RegistrationFormType;
15 15
 use Muzich\CoreBundle\Entity\User;
16
+use Muzich\CoreBundle\Form\User\PasswordForm;
16 17
 
17 18
 class UserController extends Controller
18 19
 {
@@ -107,7 +108,7 @@ class UserController extends Controller
107 108
   public function accountAction()
108 109
   {
109 110
     $user = $this->getUser();
110
-    $form_password = $this->container->get('fos_user.change_password.form');
111
+    $form_password = $this->getChangePasswordForm();
111 112
     $form_tags_favorites = $this->getTagsFavoritesForm($user);
112 113
     $change_email_form = $this->getChangeEmailForm();
113 114
     
@@ -123,6 +124,11 @@ class UserController extends Controller
123 124
     );
124 125
   }
125 126
   
127
+  protected function getChangePasswordForm()
128
+  {
129
+    return $this->createForm(new PasswordForm(), $this->getUser());
130
+  }
131
+  
126 132
   protected function getAvatarForm()
127 133
   {
128 134
     return $this->createFormBuilder($this->getUser())
@@ -166,6 +172,7 @@ class UserController extends Controller
166 172
     $user->setEnabled(true);
167 173
     $user->setCguAccepted(true);
168 174
     $user->setUsernameUpdatable(true);
175
+    $user->setPasswordSet(false);
169 176
     return $user;
170 177
   }
171 178
   
@@ -280,7 +287,7 @@ class UserController extends Controller
280 287
     return $errors;
281 288
   }
282 289
     
283
-  public function changePasswordAction()
290
+  public function changePasswordAction(Request $request)
284 291
   {
285 292
     $user = $this->getUser();
286 293
     
@@ -296,40 +303,37 @@ class UserController extends Controller
296 303
       )->getSingleResult();
297 304
     }
298 305
     
299
-    if (!is_object($user) || !$user instanceof UserInterface) {
300
-        throw new AccessDeniedException('This user does not have access to this section.');
301
-    }
302
-
303
-    $form = $this->container->get('fos_user.change_password.form');
304
-    $formHandler = $this->container->get('fos_user.change_password.form.handler');
306
+    $form = $this->getChangePasswordForm();
307
+    $form->bind($request);
305 308
     
306
-    $process = $formHandler->process($user);
307
-    if (count(($errors = $this->checkChangePasswordInformations($form))) < 1 && $process)
309
+    if ($form->isValid())
308 310
     {
311
+      $userManager = $this->container->get('fos_user.user_manager');
312
+      $userManager->updateUser($form->getData());
313
+      $form->getData()->setPasswordSet(true);
314
+      $this->persist($form->getData());
315
+      $this->flush();
309 316
       $this->container->get('session')->setFlash('fos_user_success', 'change_password.flash.success');
310
-      return new RedirectResponse($this->generateUrl('my_account'));
311
-    }
312
-    else
313
-    {
314
-      $form_tags_favorites = $this->getTagsFavoritesForm($user);
315
-      $change_email_form = $this->getChangeEmailForm();
316
-      
317
-      return $this->container->get('templating')->renderResponse(
318
-        'MuzichUserBundle:User:account.html.twig',
319
-        array(
320
-          'form_password'            => $form->createView(),
321
-          'errors_pers'              => $errors,
322
-          'user'                     => $user,
323
-          'form_tags_favorites'      => $form_tags_favorites->createView(),
324
-          'form_tags_favorites_name' => $form_tags_favorites->getName(),
325
-          'favorite_tags_id'         => $this->getTagsFavorites(),
326
-          'change_email_form'        => $change_email_form->createView(),
327
-          'avatar_form'              => $this->getAvatarForm()->createView()
328
-        )
329
-      );
317
+      return new RedirectResponse($this->generateUrl('home'));
330 318
     }
331
-
332 319
     
320
+    $form_tags_favorites = $this->getTagsFavoritesForm($user);
321
+    $change_email_form = $this->getChangeEmailForm();
322
+
323
+    return $this->container->get('templating')->renderResponse(
324
+      'MuzichUserBundle:User:account.html.twig',
325
+      array(
326
+        'form_password'            => $form->createView(),
327
+        'errors_pers'              => array(),
328
+        'user'                     => $user,
329
+        'form_tags_favorites'      => $form_tags_favorites->createView(),
330
+        'form_tags_favorites_name' => $form_tags_favorites->getName(),
331
+        'favorite_tags_id'         => $this->getTagsFavorites(),
332
+        'change_email_form'        => $change_email_form->createView(),
333
+        'avatar_form'              => $this->getAvatarForm()->createView(),
334
+        'preferences_form'         => $this->getPreferencesForm()->createView()
335
+      )
336
+    );
333 337
   }
334 338
   
335 339
   /**
@@ -500,7 +504,7 @@ class UserController extends Controller
500 504
     }
501 505
     
502 506
     // En cas d'échec
503
-    $form_password = $this->container->get('fos_user.change_password.form');
507
+    $form_password = $this->getChangePasswordForm();
504 508
     $form_tags_favorites = $this->getTagsFavoritesForm($user);
505 509
     
506 510
     return $this->container->get('templating')->renderResponse(

+ 6 - 12
src/Muzich/UserBundle/Resources/views/Security/change_password_form.html.twig Parādīt failu

@@ -11,21 +11,15 @@
11 11
 {% endif %}
12 12
     
13 13
   <div class="field">
14
-    {{ form_errors(form.current_password) }}
15
-    {{ form_label(form.current_password, 'password.actual'|trans({}, 'userform')) }}
16
-    {{ form_widget(form.current_password, {'attr':{'class':'niceinput'}}) }}
14
+    {{ form_errors(form.plain_password.first) }}
15
+    {{ form_label(form.plain_password.first, 'password.new.first'|trans({}, 'userform')) }}
16
+    {{ form_widget(form.plain_password.first, {'attr':{'class':'niceinput'}}) }}
17 17
   </div>
18 18
 
19 19
   <div class="field">
20
-    {{ form_errors(form.new.first) }}
21
-    {{ form_label(form.new.first, 'password.new.first'|trans({}, 'userform')) }}
22
-    {{ form_widget(form.new.first, {'attr':{'class':'niceinput'}}) }}
23
-  </div>
24
-
25
-  <div class="field">
26
-    {{ form_errors(form.new.second) }}
27
-    {{ form_label(form.new.second, 'password.new.second'|trans({}, 'userform')) }}
28
-    {{ form_widget(form.new.second, {'attr':{'class':'niceinput'}}) }}
20
+    {{ form_errors(form.plain_password.second) }}
21
+    {{ form_label(form.plain_password.second, 'password.new.second'|trans({}, 'userform')) }}
22
+    {{ form_widget(form.plain_password.second, {'attr':{'class':'niceinput'}}) }}
29 23
   </div>
30 24
 
31 25
 {{ form_rest(form) }}

+ 3 - 3
src/Muzich/UserBundle/Resources/views/User/account.html.twig Parādīt failu

@@ -56,12 +56,12 @@
56 56
 
57 57
     <h2 data-open="myaccount_favorites_password">{{ 'my_account.change_password'|trans({}, 'userui') }}</h2>
58 58
 
59
-    <div id="myaccount_favorites_password" class="myaccount_part" 
60
-      {% if not form_password|form_has_errors %}
59
+    <div id="myaccount_favorites_password" class="myaccount_part {% if app.request.get('open') == 'change_password' %}flashing{% endif %}" 
60
+      {% if not form_password|form_has_errors and not app.request.get('open') == 'change_password' %}
61 61
        style="display: none;"
62 62
       {% endif %}
63 63
      >
64
-      <form class="nicelabels changepassword" action="{{ path('change_password') }}" method="post" {{ form_enctype(form_password) }}>
64
+      <form class="nicelabels changepassword" action="{{ path('change_password', {'open':'change_password'}) }}" method="post" {{ form_enctype(form_password) }}>
65 65
 
66 66
         {% include "MuzichUserBundle:Security:change_password_form.html.twig" with { 
67 67
           'form': form_password

+ 0 - 0
src/Muzich/UserBundle/Resources/views/User/change_username.html.twig Parādīt failu


+ 0 - 0
web/img/icon_thumb_gray.png Parādīt failu


+ 0 - 0
web/js/admin.js Parādīt failu