We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25996
    • 18 Posts
    Hey Yall,

    Was hoping to get some help using WebLogin on my Evolution install. I do have a system installed for logging in and out, and all seems to work properly.

    I am hoping to add a 'Welcome, [user-name] ' at the top of the webpage when a user logs into the system, as opposed to the 'Logout' default ,or in addition to actually..

    As most of you know, any online documentation for WebLogin is almost non existent, so am hoping to get help pointing me to where i could find some tag information on some snippet variables..

    I do have this for reference:

    https://forums.modx.com/thread/54226/login


    And this is pretty much all Ican find. Can someone help me find the correct syntax for my 'Welcome' message at the top of my page?

    Much thanks

    Ed

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

      • 19369
      • 1,098 Posts
      Install this snippet:
      Snippet Name: username
      Snippet Code:
      <?php
      /* See if the page visitor is a logged in web user or manager user */
         $userName = $modx->getLoginUserName();
      
      return $userName;
      ?>


      Now you can use this to output the name:
      [[username]]


      You can also install another snippet that check if you are logged in or logged out:
      Snippet Name: checklogin
      Snippet Code:
      <?php
      #::::::::::::::::::::::::::::::::::::::::
      # Snippet Name: CheckLogin
      # Short Desc: Checks if a user is logged in and returns a linktext accordingly
      # Version: 0.1
      # Created By: Wim Beerens ([email protected])
      #
      # Date: November 26, 2006
      #
      # Changelog: 
      # November 26, 2006 -- initial release
      #
      #::::::::::::::::::::::::::::::::::::::::
      # Usage: 	
      #	Checks if a user is logged in and returns a linktext accordingly
      #       Snippet based on Personalize and WebLogin snippet
      #       To be used uncached only
      #
      # Installation:
      #       In the Manager create a new snipped called CheckLogin
      #       and copy/paste this code into the new snippet
      #       For ease of use click on the tab Properties
      #       and copy/paste the following code into the Default Properties Field:
      #       &logintext=Login link text;string; &logouttext=Logout link text;string;
      #
      # Params:	
      #
      #	&logintext [string] (optional) 
      #		Linktext to be displayed when user is logged out (!)
      #
      #	&logouttext [string] (optional)
      #		Linktext to be displayed when user is logged in (!)
      #	
      #
      # Examples:
      #
      #	[!CheckLogin!] 
      #
      #	[!CheckLogin? &logintext=`Loginpage` &logouttext=`Logoutpage`!] 
      #
      #::::::::::::::::::::::::::::::::::::::::
      
      # check if inside manager
      if ($m = $modx->insideManager()) {
      	return ''; # don't go any further when inside manager
      }
      
      # Snippet customize settings
      $loginText	= isset($logintext)? $logintext:'Login';
      $logoutText	= isset($logouttext)? $logouttext:'Logout';
      
      # Check if user is logged in
      $output = '';
      $test = $modx->getLoginUserName();
      
      if ($test == '') {
      	$output = $loginText;
      } else {
      	$output = $logoutText;
      }
      
      return $output;
      ?>


      And use it for example in this way:
      [!checklogin? &logintext=`LOGIN TEXT` &logouttext=`LOGOUT TEXT Welcome [[username]]`!]
        • 25996
        • 18 Posts
        Thank you tons. .trying these out now..
        Will let you know if I have success
        ED
          • 25996
          • 18 Posts
          Hmm, OK, i've implemented the checklogin snippet, but for some reason, its having trouble displaying the username . Just says 'Welcome, ' and no username. Would there be a modX setting/config that would be keeping this from displaying properly?
          Thanks..

          Ed
            • 25996
            • 18 Posts
            OK, for some reason, it is working now.. but it seems to be intermittent, maybe a browser cache thing?
            Hmmm, thoughts?
              • 19369
              • 1,098 Posts
              It is probably a problem with the cache, play with cached and uncached version of the snippet.
                • 25996
                • 18 Posts
                would that be this? :

                [[checklogin? &logintext=`LOGIN TEXT` &logouttext=`LOGOUT TEXT Welcome [[username]]`]]
                  • 19369
                  • 1,098 Posts
                  No, like this:
                  [!checklogin? &logintext=`LOGIN TEXT` &logouttext=`LOGOUT TEXT Welcome [[username]]`!]
                  
                    • 25996
                    • 18 Posts
                    Thx.. testing now.
                      • 25996
                      • 18 Posts
                      Quote from: microcipcip at Jun 25, 2012, 05:22 PM
                      No, like this:
                      [!checklogin? &logintext=`LOGIN TEXT` &logouttext=`LOGOUT TEXT Welcome [[username]]`!]
                      
                      So is this the Uncached version then?
                      If so, whats the Cached version?

                      Finding a delay from when the name actually shows up..