Browse Source

Mise en place de la procédure de changement de mot de passe.

bastien 13 years ago
parent
commit
e95ad62fbc

+ 47 - 8
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -2,18 +2,57 @@
2 2
 
3 3
 namespace Muzich\UserBundle\Controller;
4 4
 
5
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
5
+use Muzich\CoreBundle\lib\Controller;
6 6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
+use Symfony\Component\HttpFoundation\RedirectResponse;
8
+use Symfony\Component\Security\Core\Exception\AccessDeniedException;
9
+use FOS\UserBundle\Model\UserInterface;
7 10
 
8 11
 class UserController extends Controller
9 12
 {
10
-    /**
11
-     * @Template()
12
-     */
13
-    public function accountAction()
13
+  /**
14
+   * @Template()
15
+   */
16
+  public function accountAction()
17
+  {
18
+    $user = $this->getUser();
19
+
20
+    $form_password = $this->container->get('fos_user.change_password.form');
21
+
22
+      return array(
23
+        'user' => $user,
24
+        'form_password' => $form_password->createView()
25
+      );
26
+  }
27
+    
28
+  public function changePasswordAction()
29
+  {
30
+    $user = $this->getUser();
31
+    if (!is_object($user) || !$user instanceof UserInterface) {
32
+        throw new AccessDeniedException('This user does not have access to this section.');
33
+    }
34
+
35
+    $form = $this->container->get('fos_user.change_password.form');
36
+    $formHandler = $this->container->get('fos_user.change_password.form.handler');
37
+    
38
+    $process = $formHandler->process($user);
39
+    if ($process)
14 40
     {
15
-        return array(
16
-          
17
-        );
41
+      $this->container->get('session')->setFlash('fos_user_success', 'change_password.flash.success');
42
+      return new RedirectResponse($this->generateUrl('my_account'));
18 43
     }
44
+    else
45
+    {
46
+      return $this->container->get('templating')->renderResponse(
47
+        'MuzichUserBundle:User:account.html.twig',
48
+        array(
49
+          'form_password' => $form->createView(),
50
+          'user' => $user
51
+        )
52
+      );
53
+    }
54
+
55
+    
56
+  }
57
+    
19 58
 }

+ 7 - 3
src/Muzich/UserBundle/Resources/config/routing.yml View File

@@ -1,6 +1,10 @@
1 1
 
2 2
 
3 3
 my_account:
4
-   pattern:  /account
5
-   defaults: { _controller: MuzichUserBundle:User:account }
6
-     
4
+  pattern:  /account
5
+  defaults: { _controller: MuzichUserBundle:User:account }
6
+     
7
+change_password:
8
+  pattern: /account/change-password
9
+  defaults: { _controller: MuzichUserBundle:User:changePassword }
10
+  

+ 28 - 1
src/Muzich/UserBundle/Resources/views/User/account.html.twig View File

@@ -1,9 +1,36 @@
1
-{% extends "MuzichHomeBundle::layout.html.twig" %}
1
+{% extends "MuzichUserBundle::layout.html.twig" %}
2 2
 
3 3
 {% block title %}Mon compte{% endblock %}
4 4
 
5 5
 {% block content %}
6 6
 
7
+  <h2>Mon compte</h2>
7 8
   
9
+  <ul>
10
+    <li>
11
+      <b>Nom d'utilisateur</b>: {{ user.name }}
12
+    </li>
13
+    <li>
14
+      <b>Adresse email</b>: {{ user.email }}
15
+    </li>
16
+  </ul>
17
+  
18
+  <h3>Changer mon mot de passe</h3>
19
+  
20
+  <form action="{{ path('change_password') }}" method="post" {{ form_enctype(form_password) }}>
21
+    {{ form_errors(form_password) }}
22
+
23
+    {{ form_row(form_password.current) }}
24
+      
25
+    {{ form_row(form_password.new.first) }}
26
+      
27
+    {{ form_row(form_password.new.second) }}
28
+      
29
+    {{ form_rest(form_password) }}
30
+
31
+    <input type="submit" />
32
+  </form>
33
+  
34
+  <h3>Changer mon adresse email</h3>
8 35
     
9 36
 {% endblock %}

+ 10 - 4
src/Muzich/UserBundle/Resources/views/layout.html.twig View File

@@ -1,7 +1,13 @@
1
-{% extends "MuzichCoreBundle::layout.html.twig" %}
1
+{% extends 'MuzichCoreBundle::layout.html.twig' %}
2 2
 
3
-{% block title %}{% endblock %}
3
+{% block css %}
4
+	<link href="{{ asset('bundles/muzichuser/css/user.css') }}" rel="stylesheet" media="screen" type="text/css" />
5
+{% endblock %}
4 6
 
5
-{% block content %}
6
-    {% block fos_user_content %}{% endblock %}
7
+{% block main_content %}
8
+  
9
+    {% include "MuzichCoreBundle:Menu:containerMenu.html.twig" with { 'active': null } %}
10
+  
11
+    {% block content %}{% endblock %}
12
+  
7 13
 {% endblock %}

+ 0 - 0
web/bundles/muzichuser/css/user.css View File