function user_external_login_register

7.x user.module user_external_login_register($name, $module)
6.x user.module user_external_login_register($name, $module)

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

drupal-6.x/modules/user/user.module, line 1447
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'));
  }
}