Explorar el Código

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

Bastien Sevajol hace 11 años
padre
commit
6a3ba35f64

+ 2 - 2
src/Muzich/CommentBundle/Controller/CommentController.php Ver fichero

@@ -18,7 +18,7 @@ class CommentController extends Controller
18 18
    * @param string $token
19 19
    * @return \Symfony\Component\HttpFoundation\Response 
20 20
    */
21
-  public function addAction($element_id, $token)
21
+  public function addAction($element_id)
22 22
   {
23 23
     if (($non_condition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_COMMENT_ADD)) !== false)
24 24
     {
@@ -26,7 +26,7 @@ class CommentController extends Controller
26 26
     }
27 27
     
28 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 31
       return $this->jsonResponse(array(
32 32
         'status' => 'error',

+ 19 - 0
src/Muzich/CoreBundle/Controller/CoreController.php Ver fichero

@@ -701,4 +701,23 @@ class CoreController extends Controller
701 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 Ver fichero

@@ -222,3 +222,6 @@ get_csrf_token:
222 222
   pattern: /ajax/getcsrf
223 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 Ver fichero

@@ -1551,23 +1551,18 @@ $(document).ready(function(){
1551 1551
   });
1552 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 1567
     $('form[name="add"] img.tag_loader').hide();
1573 1568
     window.ResponseController.execute(
@@ -1969,10 +1964,23 @@ $(document).ready(function(){
1969 1964
       li_element.find('form.add_comment').show();
1970 1965
       
1971 1966
       li_element.find('form.add_comment').ajaxForm(function(response) {
1967
+        
1972 1968
         window.ResponseController.execute(
1973 1969
         response,
1974 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 1986
         li_element.find('img.comments_loader').hide();
@@ -3045,7 +3053,9 @@ $(document).ready(function(){
3045 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 3059
     $('a.mustbeconnected').off('click').on('click',function(){
3050 3060
       open_connection_or_subscription_window();
3051 3061
     });
@@ -3424,6 +3434,7 @@ function open_connection_or_subscription_window(open_login_part, data, login_suc
3424 3434
           {
3425 3435
             $('a#helpbox_close').click();
3426 3436
             login_success_callback();
3437
+            reload_top_and_side();
3427 3438
           }
3428 3439
           else
3429 3440
           {
@@ -3449,6 +3460,7 @@ function open_connection_or_subscription_window(open_login_part, data, login_suc
3449 3460
           {
3450 3461
             $('a#helpbox_close').click();
3451 3462
             login_success_callback();
3463
+            reload_top_and_side();
3452 3464
           }
3453 3465
           else
3454 3466
           {
@@ -3501,4 +3513,27 @@ function sidebar_fix_to_bottom_finish()
3501 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 Ver fichero

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

+ 18 - 26
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig Ver fichero

@@ -397,15 +397,9 @@
397 397
           {%endif %}
398 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 404
       {% endif %}
411 405
       
@@ -481,23 +475,21 @@
481 475
     <div class="comments_loader">
482 476
       <img class="comments_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading"/>
483 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 494
     <a href="#add_comment_{{ element.id }}" class="add_comment">
503 495
       {{ 'element.comments.add'|trans({}, 'elements') }}

+ 21 - 1
src/Muzich/CoreBundle/Twig/Extensions/MyTwigExtension.php Ver fichero

@@ -41,7 +41,9 @@ class MyTwigExtension extends \Twig_Extension {
41 41
       'event_const'            => new \Twig_Function_Method($this, 'event_const'),
42 42
       'css_list_length_class'  => new \Twig_Function_Method($this, 'getCssLengthClassForList'),
43 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,4 +251,22 @@ class MyTwigExtension extends \Twig_Extension {
249 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 Ver fichero

@@ -701,8 +701,8 @@ class Controller extends BaseController
701 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 706
     if ($this->getRequest()->get('token') != $this->container->get('form.csrf_provider')->generateCsrfToken($intention))
707 707
       return false;
708 708