Pārlūkot izejas kodu

Evolution #582: Implémenter le mode nopass

Sevajol Bastien 11 gadus atpakaļ
vecāks
revīzija
44e7dcca1d

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

@@ -31,6 +31,9 @@ user:
31 31
     success:       Your address has been updated.
32 32
     wait:          You must wait to change your email again.
33 33
   session_expired: You have been disconnecter, please, log in again.
34
+  change_username:
35
+    success:       Your username has been updated.
36
+    failure:       An error occured.
34 37
 
35 38
 presubscription:
36 39
   success:         An email has been sent for confirmation.

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

@@ -31,6 +31,9 @@ user:
31 31
     success:       Votre email a correctement été mis à jour.
32 32
     wait:          Vous devez attendre avant de pouvoir faire une nouvelle demande de changement d'email.
33 33
   session_expired: Vous avez été déconnecté, veuillez vous ré-identifier
34
+  change_username:
35
+    success:       Votre nom d'utilisateur a bien été modifié
36
+    failure:       Une erreur s'est produite
34 37
 
35 38
 presubscription:
36 39
   success:         Un email a été envoyé a votre adresse email pour confirmation (vérifiez aussi dans vos SPAM)

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

@@ -2,5 +2,6 @@
2 2
 password.actual: Actual
3 3
 password.new.first: New
4 4
 password.new.second: New (check)
5
-
5
+username: Username
6
+new_username:  New username
6 7
 accept_cgu_registration: By processing registration you accept <a href="%link%">terms of service</a> of muzi.ch

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

@@ -3,7 +3,8 @@ password.actual: Actuel
3 3
 password.new.first: Nouveau
4 4
 password.new.second: Nouveau (vérification)
5 5
 
6
-username:  Nom d'utilisateur
6
+username:      Nom d'utilisateur
7
+new_username:  Nouveau nom d'utilisateur
7 8
 email:     Email
8 9
 password:
9 10
   first:   Mot de passe

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

@@ -40,10 +40,12 @@ title:
40 40
   about:         À propos
41 41
   search:        Recherche
42 42
   cgu:           Informations légales
43
-    
43
+  change_username: Change son nom d'utilisateur
44
+  
44 45
 my_account: 
45 46
   title:          Mon compte
46 47
   username:         Nom d'utilisateur
48
+  change_username:  modifier
47 49
   email:            Adresse email
48 50
   favorite_tags:    Vos tags préférés
49 51
   change_password:  Changer mon mot de passe
@@ -73,7 +75,11 @@ my_account:
73 75
     submit:         Enregistrer mes préférences
74 76
     success:        Vos préférences ont bien été mises à jour
75 77
     error:          Une erreur est survenue lors de la mise à jour de vos préférences
76
-  
78
+
79
+change_username:
80
+  submit:           Changer
81
+  warning:          Attention: une fois votre nom d'utilisateur modifié vous ne pourrez plus en changer !
82
+
77 83
 connexion:
78 84
   password_lost:    Mot de passe perdu ?
79 85
   

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

@@ -38,8 +38,9 @@ error:
38 38
   registration:
39 39
     email:
40 40
       duplicate:         Email address is already in use on muzi.ch
41
+  change_username:
42
+    duplicate:           Username is already in use on muzi.ch
41 43
   
42
-      
43 44
 registration:
44 45
   token:
45 46
     error:               The code entered for validation is not valid anymore.

+ 4 - 2
app/Resources/translations/validators.fr.yml Parādīt failu

@@ -7,7 +7,6 @@
7 7
 'The username is already used'   :   Le nom d'utilisateur est déjà utilisé.
8 8
 'The email is already used'      :   Cette adresse email est déjà utilisée.
9 9
 
10
-
11 10
 error:
12 11
   group:
13 12
     name:
@@ -38,8 +37,11 @@ error:
38 37
   registration:
39 38
     email:
40 39
       duplicate:         L'adresse email est déjà utilisé sur muzi.ch
40
+  change_username:
41
+    duplicate:           Le nom d'utilisateur est déjà utilisé sur muzi.ch
42
+    min:               Votre nom d'utilisateur doit contenir au moins %limit% caractères.
43
+    max:               Votre nom d'utilisateur doit contenir au maximum %limit% caractères.
41 44
   
42
-      
43 45
 registration:
44 46
   token:
45 47
     error:               Le code saisi pour l'inscription est incorrect ou n'est plus utilisable

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

@@ -1112,7 +1112,7 @@ class User extends BaseUser
1112 1112
       $this->username_updatable = false;
1113 1113
   }
1114 1114
   
1115
-  public function isUsernameUpdateable()
1115
+  public function isUsernameUpdatable()
1116 1116
   {
1117 1117
     if ($this->username_updatable)
1118 1118
       return true;

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

@@ -2055,4 +2055,13 @@ div.side_margin_top
2055 2055
 p.accept_cgu
2056 2056
 {
2057 2057
   font-size: 11px;
2058
-}
2058
+}
2059
+
2060
+li.user_name a
2061
+{
2062
+  color: inherit;
2063
+}
2064
+
2065
+li.user_name a:hover
2066
+{
2067
+text-decoration: underline;

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

@@ -685,4 +685,74 @@ class UserController extends Controller
685 685
     ));
686 686
   }
687 687
   
688
+  public function changeUsernameAction(Request $request)
689
+  {
690
+    if (!$this->getUser()->isUsernameUpdatable())
691
+    {
692
+      return new RedirectResponse($this->generateUrl('my_account'));
693
+    }
694
+    $errors = array();
695
+    $form = $this->getChangeUsernameForm($this->getUser());
696
+    if ($request->getMethod() == 'POST')
697
+    {
698
+      $form->bind($request);
699
+      $errors = $this->checkChangeUsernameValues($form);
700
+      if ($form->isValid() && !count($errors))
701
+      {
702
+        $form->getData()->setUsernameUpdatable(false);
703
+        $this->persist($form->getData());
704
+        $this->flush();
705
+        $this->setFlash('success', 'user.change_username.success');
706
+        return new RedirectResponse($this->generateUrl('my_account'));
707
+      }
708
+      else
709
+      {
710
+        $this->setFlash('error', 'user.change_username.failure');
711
+      }
712
+    }
713
+    
714
+    return $this->render('MuzichUserBundle:User:change_username.html.twig', array(
715
+      'form'   => $form->createView(),
716
+      'errors' => $errors
717
+    ));
718
+  }
719
+  
720
+  protected function checkChangeUsernameValues($form)
721
+  {
722
+    $errors = array();
723
+    $userManager = $this->container->get('fos_user.user_manager');
724
+    if ($userManager->findUserByUsername($form->getData()->getUsername()))
725
+    {
726
+      $errors[] = $this->trans('error.change_username.duplicate', array(), 'validators');
727
+    }
728
+    
729
+    if (strlen($form->getData()->getUsername()) < 3)
730
+    {
731
+      $errors[] = $this->trans(
732
+        'error.change_username.min', 
733
+        array('%limit%' => 3),
734
+        'validators'
735
+      );
736
+    }
737
+  
738
+    if (strlen($form->getData()->getUsername()) > 32)
739
+    {
740
+      $errors[] = $this->trans(
741
+        'error.change_username.max', 
742
+        array('%limit%' => 32),
743
+        'validators'
744
+      );
745
+    }
746
+    
747
+    return $errors;
748
+  }
749
+  
750
+  protected function getChangeUsernameForm(User $user)
751
+  {
752
+    return $this->createFormBuilder($user)
753
+      ->add('username', 'text')
754
+      ->getForm()
755
+    ;
756
+  }
757
+  
688 758
 }

+ 4 - 0
src/Muzich/UserBundle/Resources/config/routing.yml Parādīt failu

@@ -64,3 +64,7 @@ user_hide_help:
64 64
 subscribe_or_login:
65 65
   pattern: /ajax/subscribe-or-login
66 66
   defaults: { _controller: MuzichUserBundle:User:subscribeOrLogin }
67
+
68
+change_username:
69
+  pattern: /account/username/update
70
+  defaults: { _controller: MuzichUserBundle:User:changeUsername }

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

@@ -12,6 +12,9 @@
12 12
     <ul>
13 13
       <li>
14 14
         <b>{{ 'my_account.username'|trans({}, 'userui') }}</b>: {{ user.name }}
15
+        {% if app.user.isUsernameUpdatable %}
16
+          (<a href="{{ path('change_username') }}">{{ 'my_account.change_username'|trans({}, 'userui') }}</a>)
17
+        {% endif %}
15 18
       </li>
16 19
       <li>
17 20
         <b>{{ 'my_account.email'|trans({}, 'userui') }}</b>: {{ user.email }}

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

@@ -0,0 +1,40 @@
1
+{% extends "MuzichUserBundle::layout.html.twig" %}
2
+
3
+{% block title %}{{ 'title.change_username'|trans({}, 'userui') }}{% endblock %}
4
+{% block mainbox_classes %}mainbox_padding{% endblock %}
5
+
6
+{% block content %}
7
+
8
+<h1>{{ 'title.change_username'|trans({}, 'userui') }}</h1>
9
+
10
+  <form id="change_username_update" action="{{ path('change_username') }}" method="post">
11
+    
12
+    <p class="warning">
13
+      {{ 'change_username.warning'|trans({}, 'userui') }}
14
+    </p>
15
+    
16
+    {{ form_errors(form) }}
17
+    
18
+    {% if errors|length > 0 %}
19
+    <ul class="error_list">
20
+      {% for error in errors %}
21
+        <li>{{ error }}</li>
22
+      {% endfor %}
23
+    </ul>
24
+    {% endif %}
25
+    
26
+    <div class="field">
27
+      {{ form_errors(form.username) }}
28
+      {{ form_label(form.username, 'new_username'|trans({}, 'userform')) }}:
29
+      {{ form_widget(form.username, {'attr':{'class':'niceinput'}}) }}
30
+    </div>
31
+    
32
+    {{ form_widget(form._token) }}
33
+    
34
+    <div class="alignright">
35
+      <input type="submit" class="button" value="{{ 'change_username.submit'|trans({}, 'userui') }}" />
36
+    </div>
37
+    
38
+  </form>
39
+
40
+{% endblock %}