We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34789
    • 6 Posts
    Hi All,

    After some time searching for someone with the same problem, and found none, I would like to ask you guys, what’s wrong with this piece of code:

    require_once '/home/vhosts/xxxx/subdomains/modx/httpdocs/config.core.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('mgr');
    $modx->getService('error','error.modError');
    $response = $modx->runProcessor('security/user/create',array(
    	'class_key' => 'modUser',
    	'username' => $credentials['username'],
    	'fullname' => $juser->name,
    	'email' => $juser->email,
    	'phone' => $juser->telnr ? $juser->telnr:'0612345678',
    	'newpassword' => TRUE,
    	'password' => 'Testing1989',
    	'passwordnotifymethod' => 'e'
    ));
    if ($response->isError()) {
       if ($response->hasFieldErrors()) {
           $fieldErrors = $response->getAllErrors();
           $errorMessage = implode("\n",$fieldErrors);
       } else {
           $errorMessage = 'An error occurred: '.$response->getMessage();
       }
    }
    

    The error message keeps on saying I should provide a password. When I try to generate a password instead of giving the processor one, it succeeds, but then fails on $user->save() inside the processor. Your help would be appreciated!

    Edit:

    The problem on asking the password is solved by using these params:
    $response = $modx->runProcessor('security/user/create',array(
    	'username' => $credentials['username'],
    	'fullname' => $juser->name,
    	'email' => $juser->email,
    	'phone' => $juser->telnr ? $juser->telnr:'0612345678',
    	'newpassword' => TRUE,
    
            /* Changed theses params */
    	'specifiedpassword' => $credentials['password'],
    	'confirmpassword' => $credentials['password'],
            /* End of change */
    
    	'passwordnotifymethod' => 'e'
    ));
    

    Sadly, it still hangs at $user->save()..
      • 3749
      • 24,544 Posts
      I think the processor may not be fully implemented, though I’m not looking at the current version.

      In the version I have (2.0.7), this code might be the problem:

      $newPassword= '';


      It might work to change it to:

      $newPassword = $scriptProperties['password'];


      BTW, there is a ChangePassword snippet in the Login package.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 34789
        • 6 Posts
        @bobray, see my edit in first post, the password problem is solved, but the other still exists.

        I think it has something to do with switching between databases maybe. I’m going to use this script to transfer joomla users to modx users (both in different db’s).

        I use a hook that jumps in right after a succesful login into joomla, it catches some user info ($juser) en passes it on to the processor. Maybe there is some kind of race condition that occurs when the script switches between the joomla db for the user info and has to switch back to the modx db to insert it.
          • 3749
          • 24,544 Posts
          Could you append the Joomla info to a CSV file and import it later from within MODX?
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 34789
            • 6 Posts
            My current solution is to capture the login data, use it to retrieve some more attributes, put them into the modUser object (so I get a hash, seed, etc.) and then store this information in a CSV. It’s a solution, but it’s one I’m not very proud of wink

            Is there a way to check what the real error is (like ’Lost connection to db "modx_dev"’) instead of ’Something went wrong during save, have a nice day.’?

            Later today I will try to save another type of object like modResource or one of my custom classes to see what happens. If it succeeds it might be modUser specific.
              • 3749
              • 24,544 Posts
              I’m sure there is, but troubleshooting database connection issues isn’t something I know much about.

              It could be sending the email that’s hanging it up. If you set it to something other than ’e’, it will skip that step.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting