Guest User

Untitled

a guest
Jun 6th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. $newUser = array(
  2. 'name' => $mail,
  3. 'pass' => 'password', // note: do not md5 the password
  4. 'mail' => $mail,
  5. 'status' => 1,
  6. 'init' => $mail,
  7. 'roles' => array(5)
  8. );
  9. $user = user_save(null, $newUser);
  10.  
  11. $new_user = array(
  12. 'name' => $name,
  13. 'pass' => $sifra, // note: do not md5 the password
  14. 'mail' => $email,
  15. 'status' => 1,
  16. 'init' => $email,
  17. 'roles' => array(
  18. DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  19. 3 => 'custom role',
  20. ),
  21. );
  22.  
  23. // The first parameter is sent blank so a new user is created.
  24. user_save('', $new_user);
  25.  
  26. $account = new stdClass;
  27. $account->is_new = TRUE;
  28. $account->name = 'foo';
  29. $account->pass = user_hash_password('bar');
  30. $account->mail = 'foo@example.com';
  31. $account->init = 'foo@example.com';
  32. $account->status = TRUE;
  33. $account->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
  34. $account->timezone = variable_get('date_default_timezone', '');
  35. user_save($account);
  36.  
  37. $new_user = array(
  38. 'name' => 'xgramp',
  39. 'pass' => 'idontwantnoonebutyoutoloveme',
  40. 'mail' => 'xgparsons@flyingburritobrothers.la',
  41. 'signature_format' => 'full_html',
  42. 'status' => 1,
  43. 'language' => 'en',
  44. 'timezone' => 'America/Los_Angeles',
  45. 'init' => 'Email',
  46. 'roles' => array(
  47. DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  48. 6 => 'member', // role id for custom roles varies per website
  49. ),
  50. 'field_first_name' => array(
  51. 'und' => array(
  52. 0 => array(
  53. 'value' => 'Gram',
  54. ),
  55. ),
  56. ),
  57. 'field_last_name' => array(
  58. 'und' => array(
  59. 0 => array(
  60. 'value' => 'Parsons',
  61. ),
  62. ),
  63. ),
  64. );
  65.  
  66. $account = user_save(NULL, $new_user);
  67.  
  68. $newUser = array(
  69. 'name' => 'theUserName,
  70. 'pass' => 'thePassWord',
  71. 'mail' => 'the@mail.com',
  72. 'status' => 1,
  73. 'roles' => array(DRUPAL_AUTHENTICATED_RID => 'authenticated user'),
  74. 'init' => 'the@mail.com',
  75. );
  76. user_save(null, $newUser);
  77.  
  78. // Use the e-mail address prefix as a user name.
  79. $name = substr($mail, 0, strpos($mail, '@'));
  80.  
  81. // Make sure the user name isn't already taken.
  82. $query = db_select('users', 'u')
  83. ->fields('u', array('uid'))
  84. ->condition('u.name', $name)
  85. ->execute();
  86. $result = $query->fetch();
  87.  
  88. // If the user name is taken, append a random string to the end of it.
  89. if ($result->uid) { $name .= '-' . user_password(); }
  90.  
  91. // Build the user account object and then save it.
  92. $account = new stdClass();
  93. $account->name = $name;
  94. $account->mail = $mail;
  95. $account->init = $mail;
  96. $account->pass = user_password();
  97. $account->status = 1;
  98. $account->roles = array(DRUPAL_AUTHENTICATED_RID => 'authenticated user');
  99. user_save($account);
  100. if ($account->uid) {
  101. drupal_set_message('Created new user with id %uid', array('%uid' => $account->uid));
  102. }
Add Comment
Please, Sign In to add comment