Browse Source

Evolution #792: Log me and do what i want to do

Bastien Sevajol 11 years ago
parent
commit
6a3ba35f64

+ 2 - 2
src/Muzich/CommentBundle/Controller/CommentController.php View File

18
    * @param string $token
18
    * @param string $token
19
    * @return \Symfony\Component\HttpFoundation\Response 
19
    * @return \Symfony\Component\HttpFoundation\Response 
20
    */
20
    */
21
-  public function addAction($element_id, $token)
21
+  public function addAction($element_id)
22
   {
22
   {
23
     if (($non_condition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_COMMENT_ADD)) !== false)
23
     if (($non_condition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_COMMENT_ADD)) !== false)
24
     {
24
     {
26
     }
26
     }
27
     
27
     
28
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
28
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
29
-      ->findOneById($element_id)) || $this->getUser()->getPersonalHash($element_id) != $token)
29
+      ->findOneById($element_id)) || !$this->tokenIsCorrect())
30
     {
30
     {
31
       return $this->jsonResponse(array(
31
       return $this->jsonResponse(array(
32
         'status' => 'error',
32
         'status' => 'error',

+ 19 - 0
src/Muzich/CoreBundle/Controller/CoreController.php View File

701
     return $this->jsonSuccessResponse($csrfToken);
701
     return $this->jsonSuccessResponse($csrfToken);
702
   }
702
   }
703
   
703
   
704
+  public function reloadTopEndSideBarAction()
705
+  {
706
+    return $this->jsonSuccessResponse(array(
707
+      'top'   => $this->render('MuzichCoreBundle:Layout:header.html.twig')->getContent(),
708
+      'right' => $this->render('MuzichCoreBundle:Layout:side.html.twig')->getContent()
709
+    ));
710
+  }
711
+  
712
+  public function getUrlAction()
713
+  {
714
+    if (($response = $this->mustBeConnected(true)))
715
+      return $response;
716
+    
717
+    return $this->jsonSuccessResponse($this->generateUrl(
718
+      $this->getRequest()->get('route'),
719
+      $this->getRequest()->get('parameters') 
720
+    ));
721
+  }
722
+  
704
 }
723
 }

+ 3 - 0
src/Muzich/CoreBundle/Resources/config/routing.yml View File

222
   pattern: /ajax/getcsrf
222
   pattern: /ajax/getcsrf
223
   defaults: { _controller: MuzichCoreBundle:Core:getCsrfToken }
223
   defaults: { _controller: MuzichCoreBundle:Core:getCsrfToken }
224
   
224
   
225
+reload_top_right_bars:
226
+  pattern: /ajax/reload-bars
227
+  defaults: { _controller: MuzichCoreBundle:Core:reloadTopEndSideBar }

+ 54 - 19
src/Muzich/CoreBundle/Resources/public/js/muzich.js View File

1551
   });
1551
   });
1552
   $('form[name="add"]').ajaxForm(function(response) {
1552
   $('form[name="add"]').ajaxForm(function(response) {
1553
     
1553
     
1554
-    var callback_login = null;
1555
-    // Dans le cas d'un ajout depuis l'extérieur (iframe)
1556
-    if ($('form[name="add"] input[name="shared_from"]').val() === "1")
1557
-    {
1558
-      callback_login = function(){ 
1559
-        $('#form_add_loader').show();
1560
-        JQueryJson(url_csrf, {}, function(response){
1561
-          if (response.status == 'success')
1562
-          {
1563
-            $('form[name="add"] input[name="element_add[_token]"]').val(response.data);
1564
-            $('form[name="add"]').submit();
1565
-            $('#form_add_loader').hide();
1566
-          }
1567
-        });
1568
-         
1569
-      };
1570
-    }
1554
+    var callback_login = function(){ 
1555
+      $('#form_add_loader').show();
1556
+      JQueryJson(url_csrf, {}, function(response){
1557
+        if (response.status == 'success')
1558
+        {
1559
+          $('form[name="add"] input[name="element_add[_token]"]').val(response.data);
1560
+          $('form[name="add"]').submit();
1561
+          $('#form_add_loader').hide();
1562
+        }
1563
+      });
1564
+    };
1565
+    
1571
     
1566
     
1572
     $('form[name="add"] img.tag_loader').hide();
1567
     $('form[name="add"] img.tag_loader').hide();
1573
     window.ResponseController.execute(
1568
     window.ResponseController.execute(
1969
       li_element.find('form.add_comment').show();
1964
       li_element.find('form.add_comment').show();
1970
       
1965
       
1971
       li_element.find('form.add_comment').ajaxForm(function(response) {
1966
       li_element.find('form.add_comment').ajaxForm(function(response) {
1967
+        
1972
         window.ResponseController.execute(
1968
         window.ResponseController.execute(
1973
         response,
1969
         response,
1974
         function(){},
1970
         function(){},
1975
-        function(){}
1971
+        function(){},
1972
+        function(){
1973
+  
1974
+          JQueryJson(url_csrf, {}, function(response){
1975
+            if (response.status === 'success')
1976
+            {
1977
+              li_element.find('form.add_comment').attr('action', str_replace('unknown', response.data, li_element.find('form.add_comment').attr('action')));
1978
+              li_element.find('form.add_comment').submit();
1979
+            }
1980
+          });
1981
+          scrollTo(li_element);
1982
+  
1983
+        }
1976
       );
1984
       );
1977
 
1985
 
1978
         li_element.find('img.comments_loader').hide();
1986
         li_element.find('img.comments_loader').hide();
3045
     * MUSTBECONNECTED links
3053
     * MUSTBECONNECTED links
3046
     */
3054
     */
3047
    
3055
    
3048
-    $('a.mustbeconnected').live('click', function(){open_connection_or_subscription_window();});
3056
+    $('a.mustbeconnected').live('click', function(){
3057
+      open_connection_or_subscription_window();
3058
+    });
3049
     $('a.mustbeconnected').off('click').on('click',function(){
3059
     $('a.mustbeconnected').off('click').on('click',function(){
3050
       open_connection_or_subscription_window();
3060
       open_connection_or_subscription_window();
3051
     });
3061
     });
3424
           {
3434
           {
3425
             $('a#helpbox_close').click();
3435
             $('a#helpbox_close').click();
3426
             login_success_callback();
3436
             login_success_callback();
3437
+            reload_top_and_side();
3427
           }
3438
           }
3428
           else
3439
           else
3429
           {
3440
           {
3449
           {
3460
           {
3450
             $('a#helpbox_close').click();
3461
             $('a#helpbox_close').click();
3451
             login_success_callback();
3462
             login_success_callback();
3463
+            reload_top_and_side();
3452
           }
3464
           }
3453
           else
3465
           else
3454
           {
3466
           {
3501
       $('.sidebar').css('bottom', '')
3513
       $('.sidebar').css('bottom', '')
3502
     });
3514
     });
3503
   }
3515
   }
3516
+}
3517
+
3518
+function reload_top_and_side()
3519
+{
3520
+  JQueryJson(url_reload_top_and_side, {}, function(response){
3521
+    if (response.status == 'success')
3522
+    {
3523
+      if ($('div#header'))
3524
+      {
3525
+        $('div#header').html(response.data.top);
3526
+      }
3527
+        
3528
+      if ($('aside#sidebar div.sidebar'))
3529
+      {
3530
+        $('aside#sidebar div.sidebar').html(response.data.right);
3531
+      }
3532
+    }
3533
+  });
3534
+}
3535
+
3536
+function scrollTo(element)
3537
+{
3538
+  $('html, body').animate({ scrollTop: element.offset().top }, 'fast');
3504
 }
3539
 }

+ 1 - 0
src/Muzich/CoreBundle/Resources/views/Layout/head_js.html.twig View File

133
   url_subscription_or_login = "{{ path('subscribe_or_login') }}";
133
   url_subscription_or_login = "{{ path('subscribe_or_login') }}";
134
   url_email_not_confirmed = "{{ path('email_not_confirmed') }}";
134
   url_email_not_confirmed = "{{ path('email_not_confirmed') }}";
135
   url_send_email_confirmation = "{{ path('send_email_confirmation') }}";
135
   url_send_email_confirmation = "{{ path('send_email_confirmation') }}";
136
+  url_reload_top_and_side = "{{ path('reload_top_right_bars') }}";
136
   
137
   
137
   config_player_youtube_width = "{{ player_config_youtube_width }}";
138
   config_player_youtube_width = "{{ player_config_youtube_width }}";
138
   config_player_youtube_height = "{{ player_config_youtube_height }}";
139
   config_player_youtube_height = "{{ player_config_youtube_height }}";

+ 18 - 26
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig View File

397
           {%endif %}
397
           {%endif %}
398
         {% endautoescape %}
398
         {% endautoescape %}
399
         
399
         
400
-        {% if app.user %}
401
-          <a href="#add_comment_{{ element.id }}" class="add_comment">
402
-            {{ 'element.comments.add'|trans({}, 'elements') }}
403
-          </a>
404
-        {% else %}
405
-          <a href="#" class="mustbeconnected add_comment_disabled">
406
-            {{ 'element.comments.add'|trans({}, 'elements') }}
407
-          </a>
408
-        {% endif %}
400
+        <a href="#add_comment_{{ element.id }}" class="add_comment">
401
+          {{ 'element.comments.add'|trans({}, 'elements') }}
402
+        </a>
409
       
403
       
410
       {% endif %}
404
       {% endif %}
411
       
405
       
481
     <div class="comments_loader">
475
     <div class="comments_loader">
482
       <img class="comments_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading"/>
476
       <img class="comments_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading"/>
483
     </div>
477
     </div>
484
-    
485
-    {% if app.user %}
486
-      <form 
487
-        action="{{ path('ajax_add_comment', {'element_id':element.id, 'token':app.user.getPersonalHash(element.id)}) }}" 
488
-        method="post" 
489
-        name="add_comment"
490
-        style="display: none;"
491
-        class="add_comment"
492
-      >
493
-        {% include "MuzichCommentBundle:Comment:form.html.twig" with {
494
-          'submit_value' : 'element.comments.add_submit'|trans({}, 'elements'),
495
-          'cancel_value' : 'element.comments.add_cancel'|trans({}, 'elements'),
496
-          'following'    : element.userFollowComments(app.user.id),
497
-          'own'          : (app.user.id == element.owner.id)
498
-        } %}
499
-      </form>
500
-    {% endif %}
478
+          
479
+    <form 
480
+      action="{{ path('ajax_add_comment', {'element_id':element.id, 'token' : token_or_unknow(app.user)}) }}" 
481
+      method="post" 
482
+      name="add_comment"
483
+      style="display: none;"
484
+      class="add_comment"
485
+    >
486
+      {% include "MuzichCommentBundle:Comment:form.html.twig" with {
487
+        'submit_value' : 'element.comments.add_submit'|trans({}, 'elements'),
488
+        'cancel_value' : 'element.comments.add_cancel'|trans({}, 'elements'),
489
+        'following'    : element.userFollowComments(app.user|userId),
490
+        'own'          : (app.user|userId == element.owner.id)
491
+      } %}
492
+    </form>
501
       
493
       
502
     <a href="#add_comment_{{ element.id }}" class="add_comment">
494
     <a href="#add_comment_{{ element.id }}" class="add_comment">
503
       {{ 'element.comments.add'|trans({}, 'elements') }}
495
       {{ 'element.comments.add'|trans({}, 'elements') }}

+ 21 - 1
src/Muzich/CoreBundle/Twig/Extensions/MyTwigExtension.php View File

41
       'event_const'            => new \Twig_Function_Method($this, 'event_const'),
41
       'event_const'            => new \Twig_Function_Method($this, 'event_const'),
42
       'css_list_length_class'  => new \Twig_Function_Method($this, 'getCssLengthClassForList'),
42
       'css_list_length_class'  => new \Twig_Function_Method($this, 'getCssLengthClassForList'),
43
       'token'                  => new \Twig_Function_Method($this, 'token'),
43
       'token'                  => new \Twig_Function_Method($this, 'token'),
44
-      'path_token'             => new \Twig_Function_Method($this, 'path_token')
44
+      'path_token'             => new \Twig_Function_Method($this, 'path_token'),
45
+      'token'                  => new \Twig_Function_Method($this, 'getToken'),
46
+      'token_or_unknow'        => new \Twig_Function_Method($this, 'getTokenOrUnknown')
45
     );
47
     );
46
   }
48
   }
47
   
49
   
249
     return null;
251
     return null;
250
   }
252
   }
251
 
253
 
254
+  public function getToken()
255
+  {
256
+    return $this->container->get('form.csrf_provider')->generateCsrfToken('unknown');
257
+  }
258
+  
259
+  public function getTokenOrUnknown($user)
260
+  {
261
+    if ($user)
262
+    {
263
+      if ($user instanceof User)
264
+      {
265
+        return $this->getToken();
266
+      }
267
+    }
268
+    
269
+    return 'unknown';
270
+  }
271
+  
252
 }
272
 }

+ 2 - 2
src/Muzich/CoreBundle/lib/Controller.php View File

701
     return $this->createForm(new PlaylistForm(), $playlist);
701
     return $this->createForm(new PlaylistForm(), $playlist);
702
   }
702
   }
703
   
703
   
704
-  protected function tokenIsCorrect($intention = '')
705
-  {
704
+  protected function tokenIsCorrect($intention = 'unknown')
705
+  {    
706
     if ($this->getRequest()->get('token') != $this->container->get('form.csrf_provider')->generateCsrfToken($intention))
706
     if ($this->getRequest()->get('token') != $this->container->get('form.csrf_provider')->generateCsrfToken($intention))
707
       return false;
707
       return false;
708
     
708