Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $newUser = array(
- 'name' => $mail,
- 'pass' => 'password', // note: do not md5 the password
- 'mail' => $mail,
- 'status' => 1,
- 'init' => $mail,
- 'roles' => array(5)
- );
- $user = user_save(null, $newUser);
- $new_user = array(
- 'name' => $name,
- 'pass' => $sifra, // note: do not md5 the password
- 'mail' => $email,
- 'status' => 1,
- 'init' => $email,
- 'roles' => array(
- DRUPAL_AUTHENTICATED_RID => 'authenticated user',
- 3 => 'custom role',
- ),
- );
- // The first parameter is sent blank so a new user is created.
- user_save('', $new_user);
- $account = new stdClass;
- $account->is_new = TRUE;
- $account->name = 'foo';
- $account->pass = user_hash_password('bar');
- $account->mail = 'foo@example.com';
- $account->init = 'foo@example.com';
- $account->status = TRUE;
- $account->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
- $account->timezone = variable_get('date_default_timezone', '');
- user_save($account);
- $new_user = array(
- 'name' => 'xgramp',
- 'pass' => 'idontwantnoonebutyoutoloveme',
- 'mail' => 'xgparsons@flyingburritobrothers.la',
- 'signature_format' => 'full_html',
- 'status' => 1,
- 'language' => 'en',
- 'timezone' => 'America/Los_Angeles',
- 'init' => 'Email',
- 'roles' => array(
- DRUPAL_AUTHENTICATED_RID => 'authenticated user',
- 6 => 'member', // role id for custom roles varies per website
- ),
- 'field_first_name' => array(
- 'und' => array(
- 0 => array(
- 'value' => 'Gram',
- ),
- ),
- ),
- 'field_last_name' => array(
- 'und' => array(
- 0 => array(
- 'value' => 'Parsons',
- ),
- ),
- ),
- );
- $account = user_save(NULL, $new_user);
- $newUser = array(
- 'name' => 'theUserName,
- 'pass' => 'thePassWord',
- 'mail' => 'the@mail.com',
- 'status' => 1,
- 'roles' => array(DRUPAL_AUTHENTICATED_RID => 'authenticated user'),
- 'init' => 'the@mail.com',
- );
- user_save(null, $newUser);
- // Use the e-mail address prefix as a user name.
- $name = substr($mail, 0, strpos($mail, '@'));
- // Make sure the user name isn't already taken.
- $query = db_select('users', 'u')
- ->fields('u', array('uid'))
- ->condition('u.name', $name)
- ->execute();
- $result = $query->fetch();
- // If the user name is taken, append a random string to the end of it.
- if ($result->uid) { $name .= '-' . user_password(); }
- // Build the user account object and then save it.
- $account = new stdClass();
- $account->name = $name;
- $account->mail = $mail;
- $account->init = $mail;
- $account->pass = user_password();
- $account->status = 1;
- $account->roles = array(DRUPAL_AUTHENTICATED_RID => 'authenticated user');
- user_save($account);
- if ($account->uid) {
- drupal_set_message('Created new user with id %uid', array('%uid' => $account->uid));
- }
Add Comment
Please, Sign In to add comment