Browse Source

Anomalie #105: Ajax et utilisateur déconnecté

bastien 13 years ago
parent
commit
f8e32e7a1c

+ 15 - 1
src/Muzich/CoreBundle/Controller/CoreController.php View File

142
    *  Procédure d'ajout d'un element
142
    *  Procédure d'ajout d'un element
143
    */
143
    */
144
   public function elementAddAction($group_slug)
144
   public function elementAddAction($group_slug)
145
-  {    
145
+  {   
146
+    if ($this->getUser() == 'anon.')
147
+    {
148
+      if ($this->getRequest()->isXmlHttpRequest())
149
+      {
150
+        return $this->jsonResponse(array(
151
+          'status' => 'mustbeconnected'
152
+        ));
153
+      }
154
+      else
155
+      {
156
+        return $this->redirect($this->generateUrl('index'));
157
+      }
158
+    }
159
+    
146
     if ($this->getRequest()->getMethod() != 'POST')
160
     if ($this->getRequest()->getMethod() != 'POST')
147
     {
161
     {
148
       throw $this->createNotFoundException('Cette ressource n\'est pas accessible');
162
       throw $this->createNotFoundException('Cette ressource n\'est pas accessible');

+ 42 - 0
src/Muzich/CoreBundle/Controller/ElementController.php View File

34
    */
34
    */
35
   public function editAction($element_id)
35
   public function editAction($element_id)
36
   {    
36
   {    
37
+    if ($this->getUser() == 'anon.')
38
+    {
39
+      if ($this->getRequest()->isXmlHttpRequest())
40
+      {
41
+        return $this->jsonResponse(array(
42
+          'status' => 'mustbeconnected'
43
+        ));
44
+      }
45
+      else
46
+      {
47
+        return $this->redirect($this->generateUrl('index'));
48
+      }
49
+    }
50
+    
37
     $element = $this->checkExistingAndOwned($element_id);
51
     $element = $this->checkExistingAndOwned($element_id);
38
     
52
     
39
     $element_tags = $element->getTags();
53
     $element_tags = $element->getTags();
77
    */
91
    */
78
   public function updateAction($element_id)
92
   public function updateAction($element_id)
79
   {
93
   {
94
+    if ($this->getUser() == 'anon.')
95
+    {
96
+      if ($this->getRequest()->isXmlHttpRequest())
97
+      {
98
+        return $this->jsonResponse(array(
99
+          'status' => 'mustbeconnected'
100
+        ));
101
+      }
102
+      else
103
+      {
104
+        return $this->redirect($this->generateUrl('index'));
105
+      }
106
+    }
107
+    
80
     $element = $this->checkExistingAndOwned($element_id);
108
     $element = $this->checkExistingAndOwned($element_id);
81
     // Si il y a un groupe on le retire pour le bind
109
     // Si il y a un groupe on le retire pour le bind
82
     $group = $element->getGroup();
110
     $group = $element->getGroup();
145
   
173
   
146
   public function removeAction($element_id)
174
   public function removeAction($element_id)
147
   {
175
   {
176
+    if ($this->getUser() == 'anon.')
177
+    {
178
+      if ($this->getRequest()->isXmlHttpRequest())
179
+      {
180
+        return $this->jsonResponse(array(
181
+          'status' => 'mustbeconnected'
182
+        ));
183
+      }
184
+      else
185
+      {
186
+        return $this->redirect($this->generateUrl('index'));
187
+      }
188
+    }
189
+    
148
     try {
190
     try {
149
       $element = $this->checkExistingAndOwned($element_id);
191
       $element = $this->checkExistingAndOwned($element_id);
150
       $em = $this->getDoctrine()->getEntityManager();
192
       $em = $this->getDoctrine()->getEntityManager();

+ 28 - 0
src/Muzich/CoreBundle/Controller/SearchController.php View File

41
    */
41
    */
42
   public function searchElementsAction($id_limit = null, $invertcolors = false)
42
   public function searchElementsAction($id_limit = null, $invertcolors = false)
43
   {
43
   {
44
+    if ($this->getUser() == 'anon.')
45
+    {
46
+      if ($this->getRequest()->isXmlHttpRequest())
47
+      {
48
+        return $this->jsonResponse(array(
49
+          'status' => 'mustbeconnected'
50
+        ));
51
+      }
52
+      else
53
+      {
54
+        return $this->redirect($this->generateUrl('index'));
55
+      }
56
+    }
57
+    
44
     $request = $this->getRequest();
58
     $request = $this->getRequest();
45
     $search_object = $this->getElementSearcher();
59
     $search_object = $this->getElementSearcher();
46
     
60
     
200
    */
214
    */
201
   public function searchTagAction($string_search, $timestamp)
215
   public function searchTagAction($string_search, $timestamp)
202
   {
216
   {
217
+    if ($this->getUser() == 'anon.')
218
+    {
219
+      if ($this->getRequest()->isXmlHttpRequest())
220
+      {
221
+        return $this->jsonResponse(array(
222
+          'status' => 'mustbeconnected'
223
+        ));
224
+      }
225
+      else
226
+      {
227
+        return $this->redirect($this->generateUrl('index'));
228
+      }
229
+    }
230
+    
203
     if ($this->getRequest()->isXmlHttpRequest())
231
     if ($this->getRequest()->isXmlHttpRequest())
204
     {
232
     {
205
       if (strlen($string_search) > 1)
233
       if (strlen($string_search) > 1)

+ 11 - 0
src/Muzich/CoreBundle/Resources/config/security.yml View File

65
         - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
65
         - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
66
         - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
66
         - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
67
         
67
         
68
+        ## Ouvert pour l'ajax (et le message de redirection en cas de déco)
69
+        - { path: ^/(?:fr|en)/search-elements, role: IS_AUTHENTICATED_ANONYMOUSLY }
70
+        - { path: ^/(?:fr|en)/element, role: IS_AUTHENTICATED_ANONYMOUSLY }
71
+        - { path: ^/(?:fr|en)/favorite/add, role: IS_AUTHENTICATED_ANONYMOUSLY }
72
+        - { path: ^/(?:fr|en)/favorite/remove, role: IS_AUTHENTICATED_ANONYMOUSLY }
73
+        - { path: ^/(?:fr|en)/element/add, role: IS_AUTHENTICATED_ANONYMOUSLY }
74
+        - { path: ^/(?:fr|en)/search/tag, role: IS_AUTHENTICATED_ANONYMOUSLY }
75
+        - { path: ^/(?:fr|en)/show/user/, role: IS_AUTHENTICATED_ANONYMOUSLY }
76
+        - { path: ^/(?:fr|en)/show/group/, role: IS_AUTHENTICATED_ANONYMOUSLY }
77
+        - { path: ^/(?:fr|en)/favoritesajax, role: IS_AUTHENTICATED_ANONYMOUSLY }
78
+                                
68
         - { path: ^/, roles: ROLE_USER }
79
         - { path: ^/, roles: ROLE_USER }
69
         
80
         
70
 #        # Liste des pages accessibles à tous les utilisateurs (ne pas toucher)
81
 #        # Liste des pages accessibles à tous les utilisateurs (ne pas toucher)

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

27
     string_follow_stop = "{{ 'user.stop_follow'|trans({}, 'users') }}";
27
     string_follow_stop = "{{ 'user.stop_follow'|trans({}, 'users') }}";
28
     string_follow_following = "{{ 'user.following'|trans({}, 'users') }}";
28
     string_follow_following = "{{ 'user.following'|trans({}, 'users') }}";
29
     string_follow_follow = "{{ 'user.follow'|trans({}, 'users') }}";
29
     string_follow_follow = "{{ 'user.follow'|trans({}, 'users') }}";
30
+    
31
+    url_index = "{{ path('index') }}";
30
   </script>
32
   </script>
31
   {% block js %}{% endblock %}
33
   {% block js %}{% endblock %}
32
   
34
   

+ 42 - 0
src/Muzich/FavoriteBundle/Controller/FavoriteController.php View File

22
    */
22
    */
23
   public function addAction($id, $token)
23
   public function addAction($id, $token)
24
   {
24
   {
25
+    if ($this->getUser() == 'anon.')
26
+    {
27
+      if ($this->getRequest()->isXmlHttpRequest())
28
+      {
29
+        return $this->jsonResponse(array(
30
+          'status' => 'mustbeconnected'
31
+        ));
32
+      }
33
+      else
34
+      {
35
+        return $this->redirect($this->generateUrl('index'));
36
+      }
37
+    }
38
+    
25
     $user = $this->getUser();
39
     $user = $this->getUser();
26
     
40
     
27
     /**
41
     /**
86
    */
100
    */
87
   public function removeAction($id, $token)
101
   public function removeAction($id, $token)
88
   {
102
   {
103
+    if ($this->getUser() == 'anon.')
104
+    {
105
+      if ($this->getRequest()->isXmlHttpRequest())
106
+      {
107
+        return $this->jsonResponse(array(
108
+          'status' => 'mustbeconnected'
109
+        ));
110
+      }
111
+      else
112
+      {
113
+        return $this->redirect($this->generateUrl('index'));
114
+      }
115
+    }
116
+    
89
     $user = $this->getUser();
117
     $user = $this->getUser();
90
     $em = $this->getDoctrine()->getEntityManager();
118
     $em = $this->getDoctrine()->getEntityManager();
91
     
119
     
193
   
221
   
194
   public function getElementsAction($user_id, $tags_ids_json, $id_limit = null, $invert = false)
222
   public function getElementsAction($user_id, $tags_ids_json, $id_limit = null, $invert = false)
195
   {
223
   {
224
+    if ($this->getUser() == 'anon.')
225
+    {
226
+      if ($this->getRequest()->isXmlHttpRequest())
227
+      {
228
+        return $this->jsonResponse(array(
229
+          'status' => 'mustbeconnected'
230
+        ));
231
+      }
232
+      else
233
+      {
234
+        return $this->redirect($this->generateUrl('index'));
235
+      }
236
+    }
237
+    
196
     $tag_ids = json_decode($tags_ids_json);
238
     $tag_ids = json_decode($tags_ids_json);
197
     $search_object = new ElementSearcher();
239
     $search_object = new ElementSearcher();
198
     
240
     

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

16
   defaults: { _controller: MuzichFavoriteBundle:Favorite:userList }
16
   defaults: { _controller: MuzichFavoriteBundle:Favorite:userList }
17
 
17
 
18
 favorite_get:
18
 favorite_get:
19
-  pattern:   /favorites/{user_id}/getElements/{tags_ids_json}/{id_limit}/{invert}
19
+  pattern:   /favoritesajax/{user_id}/getElements/{tags_ids_json}/{id_limit}/{invert}
20
   defaults: { _controller: MuzichFavoriteBundle:Favorite:getElements, id_limit: null, invert: false }
20
   defaults: { _controller: MuzichFavoriteBundle:Favorite:getElements, id_limit: null, invert: false }

+ 14 - 0
src/Muzich/HomeBundle/Controller/ShowController.php View File

96
   
96
   
97
   public function getElementsAction($type, $object_id, $tags_ids_json, $id_limit = null, $invert = false)
97
   public function getElementsAction($type, $object_id, $tags_ids_json, $id_limit = null, $invert = false)
98
   {
98
   {
99
+    if ($this->getUser() == 'anon.')
100
+    {
101
+      if ($this->getRequest()->isXmlHttpRequest())
102
+      {
103
+        return $this->jsonResponse(array(
104
+          'status' => 'mustbeconnected'
105
+        ));
106
+      }
107
+      else
108
+      {
109
+        return $this->redirect($this->generateUrl('index'));
110
+      }
111
+    }
112
+    
99
     $object_id = null;
113
     $object_id = null;
100
     if ($type != 'user' && $type != 'group')
114
     if ($type != 'user' && $type != 'group')
101
     {
115
     {

+ 69 - 25
web/bundles/muzichcore/js/muzich.js View File

5
  * 
5
  * 
6
  */
6
  */
7
 
7
 
8
-// Controle du focus sur la page
9
-function onBlur() {
10
-  document.body.className = 'blurred';
11
-}
12
-
13
-function onFocus(){
14
-    document.body.className = 'focused';
15
-}
16
-
17
-if (/*@cc_on!@*/false) { // check for Internet Explorer
18
-    document.onfocusin = onFocus;
19
-    document.onfocusout = onBlur;
20
-} else {
21
-    window.onfocus = onFocus;
22
-    window.onblur = onBlur;
23
-}
24
-
25
 // Messages flashs
8
 // Messages flashs
26
 var myMessages = ['info','warning','error','success']; // define the messages types	
9
 var myMessages = ['info','warning','error','success']; // define the messages types	
27
 
10
 
230
 
213
 
231
 $(document).ready(function(){
214
 $(document).ready(function(){
232
     
215
     
216
+  // Controle du focus sur la page
217
+  function onBlur() {
218
+    document.body.className = 'blurred';
219
+  }
220
+
221
+  function onFocus(){
222
+      document.body.className = 'focused';
223
+  }
224
+
225
+  if (/*@cc_on!@*/false) { // check for Internet Explorer
226
+      document.onfocusin = onFocus;
227
+      document.onfocusout = onBlur;
228
+  } else {
229
+      window.onfocus = onFocus;
230
+      window.onblur = onBlur;
231
+  }
233
   
232
   
234
   // Bouton de personalisation du filtre
233
   // Bouton de personalisation du filtre
235
   // pour le moment ce ne sotn que des redirection vers des actions
234
   // pour le moment ce ne sotn que des redirection vers des actions
312
 
311
 
313
   // Mise en favoris
312
   // Mise en favoris
314
   $('a.favorite_link').live("click", function(){
313
   $('a.favorite_link').live("click", function(){
315
-     link = $(this);
316
-     $.getJSON($(this).attr('href'), function(response) {
317
-       img = link.find('img');
318
-       link.attr('href', response.link_new_url);
319
-       img.attr('src', response.img_new_src);
320
-       img.attr('title', response.img_new_title);
321
-     });
322
-     return false;
314
+    link = $(this);
315
+    $.getJSON($(this).attr('href'), function(response) {
316
+      if (response.status == 'mustbeconnected')
317
+      {
318
+        $(location).attr('href', url_index);
319
+      }
320
+      
321
+      img = link.find('img');
322
+      link.attr('href', response.link_new_url);
323
+      img.attr('src', response.img_new_src);
324
+      img.attr('title', response.img_new_title);
325
+    });
326
+    return false;
323
   });
327
   });
324
     
328
     
325
   // Affichage du bouton Modifier et Supprimer
329
   // Affichage du bouton Modifier et Supprimer
358
      }
362
      }
359
      $('img.elements_more_loader').show();
363
      $('img.elements_more_loader').show();
360
      $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
364
      $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
365
+       if (response.status == 'mustbeconnected')
366
+        {
367
+          $(location).attr('href', url_index);
368
+        }
369
+       
361
        if (response.count)
370
        if (response.count)
362
        {
371
        {
363
          $('ul.elements').append(response.html);
372
          $('ul.elements').append(response.html);
386
   
395
   
387
   $('form[name="search"]').ajaxForm(function(response) { 
396
   $('form[name="search"]').ajaxForm(function(response) { 
388
     
397
     
398
+    if (response.status == 'mustbeconnected')
399
+    {
400
+      $(location).attr('href', url_index);
401
+    }
402
+    
389
     $('ul.elements').html(response.html);
403
     $('ul.elements').html(response.html);
390
     
404
     
391
     if (response.count)
405
     if (response.count)
418
       li = link.parent('td').parent('tr').parent().parent().parent('li.element');
432
       li = link.parent('td').parent('tr').parent().parent().parent('li.element');
419
       li.find('img.element_loader').show();
433
       li.find('img.element_loader').show();
420
       $.getJSON(link.attr('href'), function(response){
434
       $.getJSON(link.attr('href'), function(response){
435
+        if (response.status == 'mustbeconnected')
436
+        {
437
+          $(location).attr('href', url_index);
438
+        }
439
+        
421
         if (response.status == 'success')
440
         if (response.status == 'success')
422
         {
441
         {
423
           li.remove();
442
           li.remove();
458
     
477
     
459
     $.getJSON($(this).attr('href'), function(response) {
478
     $.getJSON($(this).attr('href'), function(response) {
460
       
479
       
480
+      if (response.status == 'mustbeconnected')
481
+      {
482
+        $(location).attr('href', url_index);
483
+      }
484
+      
461
       // On prépare le tagBox
485
       // On prépare le tagBox
462
       li.html(response.html);
486
       li.html(response.html);
463
      
487
      
476
       });
500
       });
477
       $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
501
       $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
478
         
502
         
503
+        if (response.status == 'mustbeconnected')
504
+        {
505
+          $(location).attr('href', url_index);
506
+        }
507
+        
479
         if (response.status == 'success')
508
         if (response.status == 'success')
480
         {
509
         {
481
           li.html(response.html);
510
           li.html(response.html);
567
 
596
 
568
       // Récupération des tags correspondants
597
       // Récupération des tags correspondants
569
       $.getJSON('/app_dev.php/fr/search/tag/'+input.val()+'/'+ajax_query_timestamp, function(data) {
598
       $.getJSON('/app_dev.php/fr/search/tag/'+input.val()+'/'+ajax_query_timestamp, function(data) {
599
+        if (data.status == 'mustbeconnected')
600
+        {
601
+          $(location).attr('href', url_index);
602
+        }
603
+        
570
         // Ce contrôle permet de ne pas continuer si une requete
604
         // Ce contrôle permet de ne pas continuer si une requete
571
         // ajax a été faite depuis.
605
         // ajax a été faite depuis.
572
         if (data.timestamp == ajax_query_timestamp)
606
         if (data.timestamp == ajax_query_timestamp)
768
     $('form[name="add"]').find('img.tag_loader').show();
802
     $('form[name="add"]').find('img.tag_loader').show();
769
   });
803
   });
770
   $('form[name="add"]').ajaxForm(function(response) {
804
   $('form[name="add"]').ajaxForm(function(response) {
805
+    if (response.status == 'mustbeconnected')
806
+    {
807
+      $(location).attr('href', url_index);
808
+    }
809
+    
771
     $('form[name="add"] img.tag_loader').hide();
810
     $('form[name="add"] img.tag_loader').hide();
772
     if (response.status == 'success')
811
     if (response.status == 'success')
773
     {
812
     {
812
     $('img.elements_more_loader').show();
851
     $('img.elements_more_loader').show();
813
     $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids), function(response){
852
     $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids), function(response){
814
       
853
       
854
+      if (response.status == 'mustbeconnected')
855
+      {
856
+        $(location).attr('href', url_index);
857
+      }
858
+      
815
       $('ul.elements').html(response.html);
859
       $('ul.elements').html(response.html);
816
       
860
       
817
       if (response.count)
861
       if (response.count)