Advertisement
Guest User

Untitled

a guest
Aug 10th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. $username = 'tempadmin';
  3. $password = 'sc00byd00';
  4. $email = 'tempadmin@domain.com';
  5. $sudo = false;
  6.  
  7. /* Find out where the MODX core is */
  8. require "config.core.php";
  9.  
  10. /* get the MODX class file */
  11. require MODX_CORE_PATH . 'model/modx/modx.class.php';
  12.  
  13. /* instantiate the $modx object */
  14. $modx = new modX();
  15. if ((!$modx) || (!$modx instanceof modX)) {
  16. echo 'Could not create MODX class';
  17. }
  18. /* initialize MODX and set current context */
  19. $modx->initialize('mgr');
  20.  
  21. /* load the error handler */
  22. $modx->getService('error', 'error.modError', '', '');
  23.  
  24. $user = $modx->newObject('modUser');
  25. $profile = $modx->newObject('modUserProfile');
  26.  
  27. if ($user && $profile) {
  28. $user->set('username', $username);
  29. $user->set('password', $password);
  30. $profile->set('blocked', 0);
  31. $profile->set('blockeduntil', 0);
  32. $profile->set('blockedafter', 0);
  33. $profile->set('email', $email);
  34. $user->addOne($profile);
  35.  
  36. if ($sudo) {
  37. $user->set('sudo', true);
  38. }
  39. if ($user->save()) {
  40. echo "User Created";
  41. $user->joinGroup('Administrator');
  42. } else {
  43. echo "Could not create specified user";
  44. }
  45. } else {
  46. echo "Could not create a new user and/or profile object";
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement