You are here

function hosting_client_register_user in Hostmaster (Aegir) 6

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 modules/hosting/client/hosting_client.module
Implementation of hook_insert().
4 string references to 'hosting_client_register_user'
hosting_client_configure in modules/hosting/client/hosting_client.module
Menu callback for the module's settings.
hosting_client_form in modules/hosting/client/hosting_client.module
Implementation of hook_form().
hosting_client_insert in modules/hosting/client/hosting_client.module
Implementation of hook_insert().
hosting_signup_form in modules/hosting/signup/hosting_signup.module
Form definition

File

modules/hosting/client/hosting_client.module, line 347

Code

function hosting_client_register_user($node) {
  $pass = user_password();
  $user = new stdClass();
  $edit['name'] = $node->email;
  $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(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;
}