Browse Source

Mise en place du système login/register sur la page d'accueil, avec redirection dessus si pas identifié.

bastien 12 years ago
parent
commit
3db4892070

+ 1 - 0
app/AppKernel.php View File

@@ -22,6 +22,7 @@ class AppKernel extends Kernel
22 22
             new Muzich\CoreBundle\MuzichCoreBundle(),
23 23
             new Muzich\UserBundle\MuzichUserBundle(),
24 24
             new Muzich\IndexBundle\MuzichIndexBundle(),
25
+            new Muzich\HomeBundle\MuzichHomeBundle(),
25 26
         );
26 27
 
27 28
         if (in_array($this->getEnvironment(), array('dev', 'test'))) {

+ 4 - 0
app/config/routing.yml View File

@@ -6,3 +6,7 @@
6 6
 MuzichIndexBundle:
7 7
   resource: "@MuzichIndexBundle/Resources/config/routing.yml"
8 8
   prefix: /
9
+
10
+MuzichHomeBundle:
11
+  resource: "@MuzichHomeBundle/Resources/config/routing.yml"
12
+  prefix: /

File diff suppressed because it is too large
+ 7644 - 0
app/logs/dev.log


+ 14 - 0
app/logs/prod.log View File

@@ -3,3 +3,17 @@
3 3
 [2011-09-09 10:43:54] security.INFO: Populated SecurityContext with an anonymous Token [] []
4 4
 [2011-09-09 10:43:54] request.INFO: Matched route "index" (parameters: "_controller": "Muzich\IndexBundle\Controller\IndexController::indexAction", "_route": "index") [] []
5 5
 [2011-09-09 10:43:54] request.CRITICAL: Twig_Error_Syntax: The function "code" does not exist in {} at line 7 (uncaught exception) at /home/bux/NetBeansProjects/muzich/vendor/twig/lib/Twig/Node/Expression/Function.php line 22 [] []
6
+[2011-09-09 17:10:54] security.INFO: Populated SecurityContext with an anonymous Token [] []
7
+[2011-09-09 17:10:54] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php line 85 [] []
8
+[2011-09-09 17:10:56] security.INFO: Populated SecurityContext with an anonymous Token [] []
9
+[2011-09-09 17:10:56] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/app/cache/prod/classes.php line 4539 [] []
10
+[2011-09-09 17:10:57] security.INFO: Populated SecurityContext with an anonymous Token [] []
11
+[2011-09-09 17:10:57] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/app/cache/prod/classes.php line 4539 [] []
12
+[2011-09-09 17:12:45] security.INFO: Populated SecurityContext with an anonymous Token [] []
13
+[2011-09-09 17:12:45] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/app/cache/prod/classes.php line 4539 [] []
14
+[2011-09-09 17:14:06] security.INFO: Populated SecurityContext with an anonymous Token [] []
15
+[2011-09-09 17:14:06] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/app/cache/prod/classes.php line 4539 [] []
16
+[2011-09-09 17:14:07] security.INFO: Populated SecurityContext with an anonymous Token [] []
17
+[2011-09-09 17:14:07] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/app/cache/prod/classes.php line 4539 [] []
18
+[2011-09-09 17:14:08] security.INFO: Populated SecurityContext with an anonymous Token [] []
19
+[2011-09-09 17:14:08] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /images/favicon.ico" (uncaught exception) at /home/bux/NetBeansProjects/muzich/app/cache/prod/classes.php line 4539 [] []

+ 38 - 9
src/Muzich/CoreBundle/Resources/config/security.yml View File

@@ -6,25 +6,30 @@ security:
6 6
 
7 7
     firewalls:
8 8
         main:
9
-            pattern:      .*
9
+            pattern:      ^/
10 10
             form_login:
11 11
                 provider:       fos_userbundle
12
-                login_path:     /login
12
+                login_path:     /hello
13 13
                 use_forward:    false
14 14
                 check_path:     /login_check
15 15
                 failure_path:   null
16
-                default_target_path: /
16
+                default_target_path: /hello
17 17
             logout:
18 18
                 path:   /logout
19
-                target: /
20
-            anonymous:  true
19
+                target: /hello
20
+            anonymous:  ~
21 21
             
22 22
     role_hierarchy:
23
-        ROLE_ADMIN:       ROLE_USER
24
-        ROLE_SUPER_ADMIN: ROLE_ADMIN
23
+      # Attention, pas sur de ces lignes là !
24
+        ROLE_USER:        ROLE_USER
25
+        ROLE_ADMIN:       ROLE_ADMIN
26
+        ROLE_SUPER_ADMIN: ROLE_SUPER_ADMIN
25 27
         
26 28
     ## La en tant qu'exemple, exploiter ça (http://j-place.developpez.com/tutoriels/php/ameliorez-vos-applications-developpees-avec-symfony2/#LVI-A-3)
27
-#    access_control:
29
+    access_control:
30
+        - { path: ^/hello, roles: IS_AUTHENTICATED_ANONYMOUSLY }
31
+        - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
32
+        - { path: ^/, roles: ROLE_USER }
28 33
 #        # Liste des pages accessibles à tous les utilisateurs (ne pas toucher)
29 34
 #        - { path: ^/_wdt/, role: IS_AUTHENTICATED_ANONYMOUSLY }
30 35
 #        - { path: ^/_profiler/, role: IS_AUTHENTICATED_ANONYMOUSLY }
@@ -42,4 +47,28 @@ security:
42 47
 #        - { path: ^/myapp/change-password, role: ROLE_USER }
43 48
 #
44 49
 #        # PAGES ACCESSIBLES À TOUS
45
-#        - { path: ^/myapp.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
50
+#        - { path: ^/myapp.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
51
+
52
+#security:
53
+#    firewalls:
54
+#        secured_area:
55
+#            pattern:    ^/
56
+#            anonymous: ~
57
+#            form_login:
58
+#                login_path:  /login
59
+#                check_path:  /login_check
60
+#            logout:
61
+#                path:   /logout
62
+#                target: /hello
63
+#
64
+#    access_control:
65
+#        - { path: ^/admin, roles: ROLE_ADMIN }
66
+#
67
+#    providers:
68
+#        in_memory:
69
+#            users:
70
+#                ryan:  { password: ryanpass, roles: 'ROLE_USER' }
71
+#                admin: { password: kitten, roles: 'ROLE_ADMIN' }
72
+#
73
+#    encoders:
74
+#        Symfony\Component\Security\Core\User\User: plaintext

+ 3 - 2
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

@@ -11,8 +11,9 @@
11 11
 	<meta name="keywords" content="" />
12 12
 	<meta name="author" content="" />
13 13
 	
14
-	{#<link href="{{ asset('images/favicon.ico') }}" rel="icon" type="image/x-icon" />#}
15
-	{#<link href="{{ asset('css/main.css') }}" rel="stylesheet" media="screen" type="text/css" />#}
14
+	<link href="{{ asset('favicon.ico') }}" rel="icon" type="image/x-icon" />
15
+	<link href="{{ asset('bundles/muzichcore/css/base.css') }}" rel="stylesheet" media="screen" type="text/css" />
16
+	<link href="{{ asset('bundles/muzichcore/css/main.css') }}" rel="stylesheet" media="screen" type="text/css" />
16 17
 	{#<script src="{{ asset('js/main.js') }}" type="text/javascript"></script>#}
17 18
 </head>
18 19
 <body>

+ 20 - 0
src/Muzich/HomeBundle/Controller/HomeController.php View File

@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+namespace Muzich\HomeBundle\Controller;
4
+
5
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8
+
9
+
10
+class HomeController extends Controller
11
+{
12
+  /**
13
+   * @Route("/")
14
+   * @Template()
15
+   */
16
+  public function indexAction()
17
+  {        
18
+    return array();
19
+  }
20
+}

+ 9 - 0
src/Muzich/HomeBundle/MuzichHomeBundle.php View File

@@ -0,0 +1,9 @@
1
+<?php
2
+
3
+namespace Muzich\HomeBundle;
4
+
5
+use Symfony\Component\HttpKernel\Bundle\Bundle;
6
+
7
+class MuzichHomeBundle extends Bundle
8
+{
9
+}

+ 5 - 0
src/Muzich/HomeBundle/Resources/config/routing.yml View File

@@ -0,0 +1,5 @@
1
+## Routing du Bundle
2
+
3
+index:
4
+  pattern:  /
5
+  defaults: { _controller: MuzichHomeBundle:Home:index }

+ 2 - 0
src/Muzich/HomeBundle/Resources/doc/index.rst View File

@@ -0,0 +1,2 @@
1
+HomeBundle est chargé de gérer l'interface principale de consultation
2
+des éléments.

+ 2 - 0
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig View File

@@ -0,0 +1,2 @@
1
+{% extends "MuzichCoreBundle::layout.html.twig" %}
2
+

+ 82 - 84
src/Muzich/IndexBundle/Controller/IndexController.php View File

@@ -2,101 +2,99 @@
2 2
 
3 3
 namespace Muzich\IndexBundle\Controller;
4 4
 
5
-//use Symfony\Component\HttpFoundation\Response;
6
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
5
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
+use FOS\UserBundle\Controller\SecurityController as BaseController;
7 7
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8
+use Symfony\Component\Security\Core\SecurityContext;
9
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
10
+use Symfony\Component\HttpFoundation\RedirectResponse;
8 11
 
9 12
 use Muzich\CoreBundle\Entity\Tag;
10 13
 use Muzich\CoreBundle\Entity\UsersTagsFavorites;
11 14
 use Muzich\CoreBundle\Entity\User;
12 15
 
13
-class IndexController extends Controller
16
+class IndexController extends BaseController
14 17
 {
18
+  
15 19
   /**
16
-   *
20
+   * 
17 21
    * @Template()
18 22
    */
19 23
   public function indexAction()
20 24
   {
21
-    $em = $this->getDoctrine()->getEntityManager();
22
-    
23
-    $bux = $em
24
-      ->getRepository('MuzichCoreBundle:User')
25
-      ->findOneByUsername('bux')
26
-    ;
27
-//    
28
-//    $tag_hardtek = $em
29
-//      ->getRepository('MuzichCoreBundle:Tag')
30
-//      ->findOneByName('Hardtek')
31
-//    ;
32
-//    
33
-//    if (!$tag_hardtek)
34
-//    {
35
-//      $tag_hardtek = new Tag();
36
-//      $tag_hardtek->setName('Hardtek');
37
-//      $em->persist($tag_hardtek);
38
-//    }
39
-//    
40
-//    $tag_tribe = $em
41
-//      ->getRepository('MuzichCoreBundle:Tag')
42
-//      ->findOneByName('Tribe')
43
-//    ;
44
-//    
45
-//    if (!$tag_tribe)
46
-//    {
47
-//      $tag_tribe = new Tag();
48
-//      $tag_tribe->setName('Tribe');
49
-//      $em->persist($tag_tribe);
50
-//    }
51
-//    
52
-//    //
53
-//    
54
-//    $user_tag_favorite_bux_hardtek = $em
55
-//      ->getRepository('MuzichCoreBundle:UsersTagsFavorites')
56
-//      ->findOneBy(array(
57
-//        'tag' => $tag_hardtek->getId(),
58
-//        'user' => $bux->getId()
59
-//      ))
60
-//    ;
61
-//    
62
-//    if (!$user_tag_favorite_bux_hardtek)
63
-//    {
64
-//      $user_tag_favorite_bux_hardtek = new UsersTagsFavorites();
65
-//      $user_tag_favorite_bux_hardtek->setTag($tag_hardtek);
66
-//      $user_tag_favorite_bux_hardtek->setUser($bux);
67
-//      $user_tag_favorite_bux_hardtek->setPosition(0);
68
-//      $em->persist($user_tag_favorite_bux_hardtek);
69
-//    }
70
-//    
71
-//    $user_tag_favorite_bux_tribe = $em
72
-//      ->getRepository('MuzichCoreBundle:UsersTagsFavorites')
73
-//      ->findOneBy(array(
74
-//        'tag' => $tag_tribe->getId(),
75
-//        'user' => $bux->getId()
76
-//      ))
77
-//    ;
78
-//    
79
-//    if (!$user_tag_favorite_bux_tribe)
80
-//    {
81
-//      $user_tag_favorite_bux_tribe = new UsersTagsFavorites();
82
-//      $user_tag_favorite_bux_tribe->setTag($tag_tribe);
83
-//      $user_tag_favorite_bux_tribe->setUser($bux);
84
-//      $user_tag_favorite_bux_tribe->setPosition(0);
85
-//      $em->persist($user_tag_favorite_bux_tribe);
86
-//    }
87
-//    
88
-//    $em->flush();
89
-//    
90
-//    //$bux = new User();
91
-//    //var_dump($bux->getTagsFavorites()->get(0)->getTag()->getName());
92
-//    
93
-//    foreach ($bux->getTagsFavorites() as $UserTagFavorite)
94
-//    {
95
-//      echo $UserTagFavorite->getTag()->getName().'<br />';
96
-//    }
97
-    
98
-    //die();
99
-        
100
-    return array('bux' => $bux);
25
+    $vars = $this->proceedLogin();
26
+    $vars = array_merge($vars, $this->proceedRegister());
27
+    return $vars;
101 28
   }
29
+  
30
+  /**
31
+   * Gestion du formulaire d'identification sur la page d'index.
32
+   * 
33
+   * @return type array
34
+   */
35
+  protected function proceedLogin()
36
+  {
37
+    $request = $this->container->get('request');
38
+    /* @var $request \Symfony\Component\HttpFoundation\Request */
39
+    $session = $request->getSession();
40
+    /* @var $session \Symfony\Component\HttpFoundation\Session */
41
+
42
+    // get the error if any (works with forward and redirect -- see below)
43
+    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
44
+        $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
45
+    } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
46
+        $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
47
+        $session->remove(SecurityContext::AUTHENTICATION_ERROR);
48
+    } else {
49
+        $error = '';
50
+    }
51
+
52
+    if ($error) {
53
+        // TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
54
+        $error = $error->getMessage();
55
+    }
56
+    // last username entered by the user
57
+    $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);
58
+
59
+    return array(
60
+        'last_username' => $lastUsername,
61
+        'error'         => $error,
62
+    );
63
+  }
64
+  
65
+  /**
66
+   * Gestion du formulaire d'inscription sur la page d'index.
67
+   * 
68
+   * @return type array
69
+   */
70
+  protected function proceedRegister()
71
+  {
72
+    $form = $this->container->get('fos_user.registration.form');
73
+    $formHandler = $this->container->get('fos_user.registration.form.handler');
74
+    $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');
75
+
76
+    $process = $formHandler->process($confirmationEnabled);
77
+    if ($process) {
78
+        $user = $form->getData();
79
+
80
+        if ($confirmationEnabled) {
81
+            $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
82
+            $route = 'fos_user_registration_check_email';
83
+        } else {
84
+            $this->authenticateUser($user);
85
+            $route = 'fos_user_registration_confirmed';
86
+        }
87
+
88
+        $this->setFlash('fos_user_success', 'registration.flash.user_created');
89
+        $url = $this->container->get('router')->generate($route);
90
+
91
+        return new RedirectResponse($url);
92
+    }
93
+
94
+    return array(
95
+        'form' => $form->createView(),
96
+        'theme' => $this->container->getParameter('fos_user.template.theme'),
97
+    );
98
+  }
99
+  
102 100
 }

+ 6 - 0
src/Muzich/IndexBundle/MuzichIndexBundle.php View File

@@ -6,4 +6,10 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
6 6
 
7 7
 class MuzichIndexBundle extends Bundle
8 8
 {
9
+  
10
+  public function getParent()
11
+  {
12
+    return 'FOSUserBundle';
13
+  }
14
+  
9 15
 }

+ 1 - 1
src/Muzich/IndexBundle/Resources/config/routing.yml View File

@@ -1,7 +1,7 @@
1 1
 ## Routing du Bundle Index
2 2
 
3 3
 index:
4
-    pattern:  /
4
+    pattern:  /hello
5 5
     defaults: { _controller: MuzichIndexBundle:Index:index }
6 6
 
7 7
 fos_user_security:

+ 36 - 2
src/Muzich/IndexBundle/Resources/views/Index/index.html.twig View File

@@ -1,8 +1,42 @@
1 1
 {% extends "MuzichCoreBundle::layout.html.twig" %}
2 2
 
3
-{% block title %}Hello {{ bux.username }}{% endblock %}
3
+{% block title %}Hello{% endblock %}
4 4
 
5 5
 {% block content %}
6
-    <h1>Hello {{ bux.username }}!</h1>
6
+    <h1>Hello</h1>
7
+    
8
+    <img src="/favicon.ico" />
9
+    
10
+    <div>
11
+      {% if error %}
12
+          <div>{{ error }}</div>
13
+      {% endif %}
14
+
15
+      <form action="{{ path("fos_user_security_check") }}" method="post">
16
+          <label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>
17
+          <input type="text" id="username" name="_username" value="{{ last_username }}" />
18
+
19
+          <label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>
20
+          <input type="password" id="password" name="_password" />
21
+
22
+          <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
23
+          <label for="remember_me">{{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}</label>
24
+
25
+          <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
26
+      </form>
27
+    </div>
28
+    
29
+    <div>
30
+      <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} 
31
+        method="POST" 
32
+        class="fos_user_registration_register"
33
+      >
34
+        {{ form_widget(form) }}
35
+        <div>
36
+            <input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
37
+        </div>
38
+    </form>
39
+    </div>
40
+    
7 41
 {% endblock %}
8 42
 

+ 4 - 4
src/Muzich/UserBundle/MuzichUserBundle.php View File

@@ -7,9 +7,9 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
7 7
 class MuzichUserBundle extends Bundle
8 8
 {
9 9
   
10
-  public function getParent()
11
-  {
12
-      return 'FOSUserBundle';
13
-  }
10
+//  public function getParent()
11
+//  {
12
+//    return 'FOSUserBundle';
13
+//  }
14 14
 
15 15
 }

+ 88 - 0
web/bundles/muzichcore/css/base.css View File

@@ -0,0 +1,88 @@
1
+/* --- STYLES DE BASE --- */
2
+
3
+/* Page */
4
+html {
5
+  font-size: 100%; /* Évite un bug d'IE 6-7. (1) */
6
+}
7
+body {
8
+  margin: 0;
9
+  padding: 1em; /* Remettre à zéro si nécessaire. */
10
+  /* Pensez à utiliser une collection de polices (2), par ex:
11
+  font-family: Arial, Helvetica, FreeSans, sans-serif; */
12
+  font-size: .8em; /* À adapter pour la police choisie. (3) */
13
+  line-height: 1.4; /* À adapter au design. (4) */
14
+  color: black;
15
+  background: white;
16
+}
17
+
18
+/* Titres */
19
+h1, h2, h3, h4, h5, h6 {
20
+  margin: 1em 0 .5em 0; /* Rapproche le titre du texte. (5) */
21
+  line-height: 1.2;
22
+  font-weight: bold; /* Valeur par défaut. (6) */
23
+  font-style: normal;
24
+}
25
+h1 {
26
+  font-size: 1.75em;
27
+}
28
+h2 {
29
+  font-size: 1.5em;
30
+}
31
+h3 {
32
+  font-size: 1.25em;
33
+}
34
+h4 {
35
+  font-size: 1em;
36
+}
37
+
38
+/* Listes */
39
+ul, ol {
40
+  margin: .75em 0 .75em 32px;
41
+  padding: 0;
42
+}
43
+
44
+/* Paragraphes */
45
+p {
46
+  margin: .75em 0; /* Marges plus faibles que par défaut. (7) */
47
+}
48
+address {
49
+  margin: .75em 0;
50
+  font-style: normal;
51
+}
52
+
53
+/* Liens */
54
+a {
55
+  text-decoration: underline;
56
+}
57
+a:link {
58
+  color: #11C;
59
+}
60
+a:visited {
61
+  color: #339;
62
+}
63
+a:hover, a:focus, a:active {
64
+  color: #00F;
65
+}
66
+
67
+/* Pas de bordure autour des images dans les liens */
68
+a img {
69
+  border: none;
70
+}
71
+
72
+/* Divers éléments de type en-ligne (8) */
73
+em {
74
+  font-style: italic;
75
+}
76
+strong {
77
+  font-weight: bold;
78
+}
79
+
80
+/* Formulaires */
81
+form, fieldset {
82
+  margin: 0;
83
+  padding: 0;
84
+  border: none;
85
+}
86
+input, button, select {
87
+  vertical-align: middle; /* Solution pb. d'alignement. (9) */
88
+}

+ 0 - 0
web/bundles/muzichcore/css/main.css View File


BIN
web/favicon.ico View File