You are here

function hosting_client_register_user in Hosting 7.4

Same name and namespace in other branches
  1. 5 client/hosting_client.module \hosting_client_register_user()
  2. 6.2 client/hosting_client.module \hosting_client_register_user()
  3. 7.3 client/hosting_client.module \hosting_client_register_user()

Register a new user account for the client.

This is a helper function for client forms that will create a user alongside a new client if the hosting_client_register_user setting is true.

See also

hosting_client_insert()

1 call to hosting_client_register_user()
hosting_client_insert in client/hosting_client.module
Implements hook_insert().
4 string references to 'hosting_client_register_user'
hosting_client_configure in client/hosting_client.module
Menu callback for the module's settings.
hosting_client_form in client/hosting_client.module
Implements hook_form().
hosting_client_insert in client/hosting_client.module
Implements hook_insert().
hosting_signup_form in signup/hosting_signup.module
Form definition

File

client/hosting_client.module, line 481

Code

function hosting_client_register_user($node) {
  $pass = user_password();
  $user = new stdClass();
  $edit['name'] = $node->uname;
  $edit['hosting_client'] = $node->nid;
  $edit['mail'] = $node->email;
  $edit['pass'] = $pass;
  $edit['status'] = 1;
  $edit['roles'][_hosting_client_get_role()] = TRUE;
  $user = user_save($user, $edit);
  if ($user->uid && variable_get('hosting_client_send_welcome', FALSE)) {
    if ($node->client_name) {
      $to = sprintf("%s <%s>", $node->client_name, $node->email);
    }
    else {
      $to = $node->email;
    }
    $params = array(
      '!username' => $user->name,
      '!site' => variable_get('site_name', 'Drupal'),
      '!password' => $pass,
      '!uri' => $GLOBALS['base_url'],
      '!uri_brief' => substr($base_url, strlen('http://')),
      '!date' => format_date(REQUEST_TIME),
      '!login_uri' => url('user', array(
        'absolute' => TRUE,
      )),
      '!edit_uri' => url('user/' . $user->uid . '/edit', array(
        'absolute' => TRUE,
      )),
      '!login_url' => user_pass_reset_url($user),
    );

    // No e-mail verification is required.
    // Create new user account, and login user immediately.
    $language = user_preferred_language($user);
    drupal_mail('hosting_client', 'hosting-client-register-welcome', $to, $language, $params);
  }
  return $user;
}