Subscribe: RSS
  • I have a website where there are many slide out panels that can be popped into view by clicking on tabs and i want one that is on the bottom to appear only when the user is logged in. So I did some digging and i thought way not use some kind of event? So I tried the plugin method of using OnWebLogin but It did not work. So I thought that a login post hook would be simpler and more direct so here is a snippet i did up for the login post hook.

    Code:
    <?php
    $modx->regClientStartupHTMLBlock('
    <script type="text/javascript">
    $(function(){
       var $windowWidth=$( document ).width();
                       $("#extruderBottom").buildMbExtruder({
                            position:"bottom",
                            width:$windowWidth,
                            extruderOpacity:.9,
                            onExtOpen:function(){},
                            onExtContentLoad:function(){},
                            onExtClose:function(){}
                        }); 
                        $("#extruderBottom .text").height(235);
      });
    
    </script>');


    Now when i set the post hook in the Login call then i logged in on the front end the snippet worked great. Or so I thought.. The bottom panel showed up but my login text (to say welcome basically when the user was logged in) did not appear. So I take it my code actually stopped the login process temporarily. I refreshed the page and suddenly i was logged in but the bottom panel was gone. So my question is what did I do wrong? Is there a better way to do this? and way the weird login stuff? Any help will be appreciated.


    Thanks,
    Modxnooby
    p.s. I have already checked my javascript code in regards to the slide out panels so that is not the problem.

    This question has been answered by sottwell. See the first response.

    • discuss.answer
      I used a slightly different method. I have a plugin using OnWebLogin
      <?php
      $_SESSION['loginmessage'] = 'true';

      Then a snippet (the login message is itself a resource for easier editing by the client since they change it a lot)
      <?php
      if(isset($_SESSION['loginmessage']) && $_SESSION['loginmessage'] == 'true') {
        $js = '
        <script type="text/javascript">
      	  $(function() {
      		  $( "#popupMessage" ).dialog({ 
      			   position: { my: "right bottom", at: "right bottom", of: window },
      			   hide: {effect: "fade", duration: 6000}
      		  });
      		  setTimeout(function(){ $("#popupMessage").dialog("close"); }, 8000);
      	  });
        </script>
        ';
        $modx->regClientScript($js);
        
        $document = $modx->getObject('modResource',array(
      	  'id' => 58
        ));
        
        $_SESSION['loginmessage'] = '';
        unset($_SESSION['loginmessage']);
        
        return $document->get('content');
      }
      return;

      This checks for the SESSION loginmessage flag that gets set by the plugin on web login, sets up the javascript and the content, and removes the SESSION loginmessage field. The snippet is in the template, so it works wherever the user is when he logs in. [ed. note: sottwell last edited this post 4 years, 9 months ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • If you want to show something only for logged in users, I would suggest the Personalize snippet. See http://modx.com/extras/package/personalize för more details.
        • Wow I wish I could flag two replies as answers. Thanks both of you very much! You have my thanks. With Sottwells script and Kristoffers post on the personalize snippet im sure ill figure this out.

          p.s. I wont mark this as answered until I have tried it and made sure it works but i'm sure it will smiley

          Thanks,
          ModxNooby
          • The Personalize solution may be more suitable for your requirements. Mine is to have a popup show on login, then fade away and not show again. If yours is to have something available at all times to a logged-in user, then Personalize is definitely the way to go.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
            • Ok so I tried your code out sottwell and It was awesome! Thank you so much! And though both answers where good and I'm sure would both work fine I will label Satts as my answer. If you guys wish I can post what I did and how I got it working. I had to do some modification to sottwells code but It worked great.

              Thanks so much,
              ModxNooby