We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27672
    • 168 Posts
    i have webloginpe setup and is working great. when i do this call:
    [!WebLoginPE? &type=`users`!]
    on a test page i am shown the list of users as you would expect to see it. the links to the profile are like so:
    http://www.domain.com/profile?service=viewprofile&username=gtitcomb
    what i am interested in doing is creating links to the user’s profile page with a link like:
    http://www.domain.com/profile?service=viewprofile&userid=1234
    or something similar, so that i am not putting the user’s login name in a clearly visible link. just for a little more security/privacy.

    anyone know a method of doing this directly through WebLoginPE, or will i end up having to pass the id, then do a query to get the username and then pass it into WebLoginPE somehow? thanks for any insight.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      "Obfuscating" only the user’s name isn’t going to do anything for your security, really...

      Is the page containing that list a public page? Or do you have it locked down at least?

      You could pass the user id in the URL as you spec’d out, then the target page can lookup user info using a SQL statement... something that looks up info by the user id. Have a look at the web_user tables... I think the column containing the ID is named "internalKey" or something...
        • 27672
        • 168 Posts
        the page containing the data will be available to the public. was just looking for a simple way to display the data without blatantly passing the username field in the url.

        the id is indeed called `internalKey`, so maybe i’ll try and do something with that, or perhaps come up with some arbitrary number or identifier and store that in the `...attributes_extended` table for lookup purposes. anyway, i’ll look into creating a method, i’m just a bit new to modx and webloginpe, so i wanted to make sure there wasn’t a clearly developed method already in existence before i go making something up.

        thanks.
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          Good question... I’m not sure what the WebLoginPE’s function does that lists all users (i.e. I don’t know if you can tap into it to do what you need).
            • 27672
            • 168 Posts
            okay, think i came up with a decent solution to this. in the webloginpe.snippet.php(and the snippet code in the modx manager) change:
            case 'viewprofile':
            				if (in_array('viewprofile', $disableServices)){return;}
            				$wlpe->ViewUserProfile($_REQUEST['username'],$inputHandler);
            				return $displayViewProfileTpl;
            				break;

            to this:
            case 'viewprofile':
            				if (in_array('viewprofile', $disableServices)){return;}
            				//$wlpe->ViewUserProfile($_REQUEST['username'],$inputHandler);
            				$tmpViewProfileArray = array('userid'=>$_REQUEST['userid'], 'username'=>$_REQUEST['username']);
            				$wlpe->ViewUserProfile($tmpViewProfileArray,$inputHandler);
            				return $displayViewProfileTpl;
            				break;

            which passes over an array of the username(if given) and the user’s id, which is passed in a GET variable called ’userid’. this new data is passed in an array, so within the function(next step) you can check to see if it’s getting this new data with the is_array() function, so if it’s not an array it’ll maintain the old functionality.

            then in the ViewUserProfile function in webloginpe.class.phpchange:
            function ViewUserProfile($username,$inputHandler=array())
            	{
            		global $modx;
            		
            		$web_users = $modx->getFullTableName('web_users');
            		$web_user_attributes = $modx->getFullTableName('web_user_attributes');
            		
            		$findID = $modx->db->query("SELECT * FROM ".$web_users." WHERE `username` = '".$username."'");

            to this:
            function ViewUserProfile($username,$inputHandler=array())
            	{
            		global $modx;
            		
            		$web_users = $modx->getFullTableName('web_users');
            		$web_user_attributes = $modx->getFullTableName('web_user_attributes');		
            		############
            		## NEW STUFF
            		############
            		if(is_array($username)){
            			$newQuery = "SELECT * FROM ".$web_users." WHERE `id` = '".$username['userid']."'";
            			$username = $username['username'];
            		}else{
            			$newQuery = "SELECT * FROM ".$web_users." WHERE `username` = '".$username."'";
            		}
            		################
            		## END NEW STUFF
            		################	
            		$findID = $modx->db->query($newQuery);

            which makes the query lookup the user by their id, rather than by username.

            now in your chunk (&usersTpl) which displays the user list, change:
            <a href = "[~[*id*]~]?service=viewprofile&username=[+view.username+]">

            to this:
            <a href = "[~[*id*]~]?service=viewprofile&userid=[+view.internalKey+]">

            so it passes over the user’s id in the url, rather than the username which they use to login with.

            this seems to work great for viewing the profiles, i’m not sure if it messes up the built in messaging through WebLoginPE, as i’m not using that feature on this project. and i know this isn’t doing anything to make anything more secure, i just know many clients i’ve worked with never want their users’ `username` field displayed anywhere on the site.
              • 3647
              • 177 Posts
              Brilliant! just what I was looking for (because we imported some legacy data and put the email address in as the user name, and it was looking rather insecure)

              Thanks a bunch
                • 27672
                • 168 Posts
                ah yes, i can see where having the email displayed in the url would even worse than just a standard username! glad this could be of use to you. smiley
                  • 3647
                  • 177 Posts
                  slush puppie I hope you are there, because now I have come to deploy this I can’t get it to work

                  I think I did everything but it just comes back with a blank page if I change the Tpl to username=[+view.id+].

                  I suspect I’ve missed something when updating webloginpe.class.php

                  I noticed that the
                  $findID = $modx->db->query($newQuery);
                  you had after your ’end new stuff’ was not in my version
                  I tried adding that and commenting out the next line
                  $findID = $modx->db->query("SELECT * FROM ".$web_users." WHERE `username` = ’".$username."’");

                  but that didn’t help.

                  could you maybe add a bit more detail to this step?
                    • 27672
                    • 168 Posts
                    bluespark, it’s been a while since i wrote this, but i believe:

                    $findID = $modx->db->query($newQuery);

                    replaces

                    $findID = $modx->db->query("SELECT * FROM ".$web_users." WHERE `username` = ’".$username."’");

                    not sure if that was clear in my example. the way i intended was to replace the entire first code piece with the second code piece.
                      • 3647
                      • 177 Posts
                      Thanks, that makes sense and was what I thought, so the problem must be somewhere else - it just doesn’t seem to want to play, no error just a blank profile. Have to re-trace my steps and try again!

                      Mark