We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27002
    • 32 Posts
    Is modx the right tool for the job?

    I have a project where I will need to create over 1500 user accounts and email them their password and user name in one hit.
    I will only have a csv file or similar with their name and email to begin with.

    thanks - just need the headlines if its possible, don’t need to no how yet thanks
      • 3749
      • 24,544 Posts
      If it’s MODx Revolution, the addition of the users would be fairly easy and the mail should be easy in either version. I assume that you can get the data out of the CSV file with explode(). Then it’s just something like this:

      <?php
      $user=$modx->newObject('modUser');
      $user->set('username', $username);
      $user->set('password',$password);
      $user->set('fullname',$fullname);
      // etc.
      
      $user->save();


        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
        • 27002
        • 32 Posts
        many thanks
          • 21943
          • 6 Posts
          Quote from: BobRay at Oct 28, 2010, 04:05 PM

          <?php
          $user=$modx->newObject('modUser');
          $user->set('username', $username);
          $user->set('password',$password);
          $user->set('fullname',$fullname);
          // etc.
          
          $user->save();


          Whoa, that’s an enlightening piece of code.

          Could you show me how to login a user with the API?

          Also, can I set any custom field in the user profile like this?
          $profile->set('fieldname',$fieldvalue);


          Say, the user has been validated via OpenID, and if we find them in the MODx users already, then we log them in without asking for a password. If we don’t have them, then we create a user and save OpenID attributes on their profile (identity link, email, first+last name).
            • 3749
            • 24,544 Posts
            There’s some stuff on OpenId here, but I haven’t used it: http://modxcms.com/forums/index.php/topic,7501.msg324523.html#msg324523
              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
              • 21943
              • 6 Posts
              OK, digged around in Jason’s login code until finally I figured that these bits are responsible for logging a MODx user in:

              <?php
              $loginContext = isset($_REQUEST['login_context']) && !empty($_REQUEST['login_context']) ? $_REQUEST['login_context'] : $modx->context->get('key');
              $contexts = !empty($scriptProperties['contexts']) ? $scriptProperties['contexts'] : '';
              $contexts = !empty($_REQUEST['add_contexts']) ? $_REQUEST['add_contexts'] : $contexts;
              $authenticated = $modx->user->isAuthenticated($loginContext);
              
              if (!$authenticated) {
                  // get the username and password in a way that fits your snippet
                  $_POST['username'] = $username;
                  $_POST['password'] = $password;
              
                  if (!isset($_POST['login_context'])) $_POST['login_context'] = $loginContext;
                  $response = $modx->executeProcessor(array(
                      'action' => 'login',
                      'location' => 'security',
                      'login_context' => $loginContext,
                      'add_contexts' => $contexts,
                      'rememberme' => !empty($_REQUEST['rememberme']) ? true : false,
                  ));
                  if (empty($response['success']) ) {
                      // code to handle unhappy user
                  } else {
                      // code to handle happy user
                  }
              }