We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19980 ☆ A M B ☆
    • 275 Posts
    Hi

    I managed to add new users with this code:

    $userTmp = $modx->newObject("modUser");
    	  $userTmp->set('username', $lender);
    	  $userTmp->set("password", md5($pass));
              $userTmp->save();
    	  $idUser = $userTmp->get('id');


    This add user to Manger area but only to table : *prefix*users
    Then I add :
    	  $_usr = $modx->getObject('modUser',$idUser);
    	  if (!$_usr) return 'no user??';
    	  $_profile = $_usr->getOne('Profile');  
    	  $_profile->setValue('email', '[email protected]');  
    	  $_profile->save();


    I am sure I get this crashed ((

    I need to populate *prefix*user_attributes table cause I think this must be updated / synchronised together with the first table but my first part code does not do it. That's why i am trying to use Profile and SET..

    Probably I should not use profile and set method? Or I use it wrong in terms of users updates?

    Thanks
      modx and ecommerce pro
      • 3548
      • 102 Posts
      $userTmp = $modx->newObject("modUser");
      $userTmp->set('username', $lender);
      //you don't need md5
      $userTmp->set("password", $pass);
      $profile = $modx->newObject("modProfile");
      $profile->set('email', '[email protected]');
      $userTmp->addOne($profile);
      $userTmp->save()
      
        Antonio Zdilar
        linearvector.com
        • 19980 ☆ A M B ☆
        • 275 Posts
        Hi

        thanks a lot.

        You are right I do not need to md5 it makes it as I see now when followed your note, thanks.

        I checked the structure of users table and the pass column is not auto md5 so how the string gets md5 , please?

        On your line 6: $profile->set('email', '[email protected]');
        The script dies. Do you kn0w what is wrong with this method?

        Here is my script now:

        	 
                  $userTmp = $modx->newObject("modUser");
        	  $userTmp->set('username', $lender);
        	  $userTmp->set("password", $pass);
         	  $profile1 = $modx->newObject("modProfile");
        // 	  $profile1->set('email', '[email protected]');
        	  $userTmp->addOne($profile1);
        	  $userTmp->save();
        


        But it still does not add any data to second table **atributes .. Is it due to no field for that table was set? Could you suggest what is wrong with line 6 please?

        Thanks a lot.
          modx and ecommerce pro
          • 3548
          • 102 Posts
          $userTmp = $modx->newObject("modUser");
          $userTmp->set('username', $lender);
          $userTmp->set("password", $pass);
          //this should be modUserProfile, not modProfile as I wrote before, sorry
          $profile1 = $modx->newObject("modUserProfile");
          $profile1->set('email', '[email protected]');
          $userTmp->addOne($profile1);
          $userTmp->save();
          


          If you still have problems, feel free to ask.

          P.S. As for md5, I haven't investigated it, but i suspect that modx does it internally when new user is saved. Also, modx adds salt to whole thing. md5 can be also set as a function on table cell (modx doesn't do it that way) [ed. note: blankcheck last edited this post 14 years, 7 months ago.]
            Antonio Zdilar
            linearvector.com
            • 19980 ☆ A M B ☆
            • 275 Posts
            Thanks for the fix - I get it working now ;-)

            And many thanks for commenting the md5 for pass in modx.

            Hope it will be usable for many people who import old data into modx with creating web users.
              modx and ecommerce pro