We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17412
    • 270 Posts
    I have a question relating to the web user login system in modx. (snippet: WebLogin)

    If you specify a home document for a user and that user logs in and is forwarded to that start doc and later navigates away and then tries to return, he will see the message:

    You’re already logged in Do you wish to logout? (chunk: FormLogin)

    So the user has to log out in order to access his homepage again.

    Is there a way, to also display the message "Would you like to return to your page?" so that user can re-enter their protected area ?

    Any ideas on how such a thing would be done in Modx smiley?
      • 22303 MODX Staff
      • 10,725 Posts
      Sure; in the Chunk you use as a template for WebLogin (&tpl=`FormLogin` or whatever you are calling it with), just add a link to it with that content ?
        • 17412
        • 270 Posts
        Hi opengeek,

        ah bugger, "display the message "Would you like to return to your page?" so that user can re-enter their protected area ?"

        should read "display a link back to the users home page with anchor text "would you like..."

        I’m just wondering how to grab the users home page ID and make it a link? (Each user will have a different home page"

          • 19797
          • 18 Posts
          Start with something similar to the following. If you’re certain every user will have a homepage, you can probably do away with the if else stuff.

              global $modx;
              $userID = $modx->getLoginUserID();
          
              $wus = $modx->getFullTableName('web_user_settings');
          
              $sql =  "SELECT wus.setting_value";
              $sql .= " FROM {$wus} wus";
              $sql .= " WHERE wus.setting_name='login_home'";
              $sql .= " AND wus.webuser='{$userID}'";
          
              $qr = $modx->db->query($sql);
          
              $homePageDefault = "1";
              $homePageID = $homePageDefault;
              $count = $modx->db->getRecordCount($qr);
              if($count == 0) {
                  //Default to home?
                  $homePageID = $homePageDefault;
              } else if($count > 1) {
                  //Can this happen?
                  $homePageID = $homePageDefault;
              } else {
                  $item = $modx->db->getRow($qr);
                  if($item != '') {
                      $homePageID = $item['setting_value'];
                  }
                  if($homePageID == "") {
                      $homePageID = $homePageDefault;
                  }
              }
          
              return $homePageID;
          
            • 17412
            • 270 Posts
            wow!
            That was pure genius!
            Absolutely works perfectly.

            So I made your code into a snippet "UserID" and then added a link to chunk: FormLogin
            <a href="[[UserID]]" title="Back to your page">Back to your page</a>


            Very happy - thanks very much.

            I guess this snippet could be adapted to grab the Full Name of the web user so you could greet them by their name instead of by their user name?
              • 4041
              • 788 Posts
              If a web user is logged in, you can grab alot of their info from the $_SESSION....

              make this a snippet or grab the relevent part and add it to yours...

              <?php
              $output ="";
              $webusername = $_SESSION['webShortname'];
              
              $output .="Welcome <strong>$webusername</strong>";
              
               return $output;
              ?>
                xforum
                http://frsbuilders.net (under construction) forum for evolution
                • 17412
                • 270 Posts
                Is it possible to grab their Full Name from the session? Or would I need to dig a little deeper into the database for that?

                eg. Instead of "Welcome UserName, you are now logged in" - greet them as - "Welcome Mark Jones, you are now logged in"
                  • 4041
                  • 788 Posts
                  here is the $_SESSION output for a webuser (using 095)

                  Array ( 
                  [webShortname] => Breezer 
                  [webFullname] => Breezer Frazer
                  [webEmail] => [email protected] 
                  [webValidated] => 1 
                  [webInternalKey] => 1 
                  [webValid] => 
                  [webFailedlogins] => 0 
                  [webLastlogin] => 1180112943 
                  [webnrlogins] => 22 
                  [webUserGroupNames] => 
                  [webDocgroups] => 
                  [modx.web.session.cookie.lifetime] => 0 
                  [log_time] => 1180141250 
                  [ip] => xxx.xxx.xxx.xxx 
                  [webUsrConfigSet] => Array ( ) 
                  [mgrUsrConfigSet] => Array ( ) ) 


                  these can all be accessed by using $_SESSION[’variablename’] in your scripts....

                  you can also find them for yourself, make a page and then use this in a snippet :

                  $output .= print_r($_SESSION);
                    xforum
                    http://frsbuilders.net (under construction) forum for evolution
                    • 17412
                    • 270 Posts
                    thanks Breezer. It’s dawning upon me that there’s not a great deal you can’t do with this framework.
                    Thanks for letting me know how to access the session data.
                      • 12511
                      • 4 Posts
                      Hi all,

                      I have install 0.96, why i can’t login from another computer, the page redirect to the localhost.
                      in my 0.95 no problem.

                      Thank’s

                      Yono