Same name and namespace in other branches
  1. 7.x modules/user/user.module \user_external_login_register()

Helper function for authentication modules. Either login in or registers the current user, based on username. Either way, the global $user object is populated based on $name.

File

modules/user/user.module, line 1454
Enables the user registration and login system.

Code

function user_external_login_register($name, $module) {
  global $user;
  $existing_user = user_load(array(
    'name' => $name,
  ));
  if (isset($existing_user->uid)) {
    $user = $existing_user;
  }
  else {

    // Register this new user.
    $userinfo = array(
      'name' => $name,
      'pass' => user_password(),
      'init' => $name,
      'status' => 1,
      "authname_{$module}" => $name,
      'access' => time(),
    );
    $account = user_save('', $userinfo);

    // Terminate if an error occured during user_save().
    if (!$account) {
      drupal_set_message(t("Error saving user account."), 'error');
      return;
    }
    $user = $account;
    watchdog('user', 'New external user: %name using module %module.', array(
      '%name' => $name,
      '%module' => $module,
    ), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $user->uid . '/edit'));
  }
}