You are here

function user_external_login_register in Shibboleth Authentication 5.2

Same name and namespace in other branches
  1. 5.3 shib_auth.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.

Backport this function from user.module of Drupal 6.x.

Parameters

$name The user's name.:

$module Name of the module which process the authetication.:

1 call to user_external_login_register()
shib_auth_init in ./shib_auth.module
Create a new user based on informations from the Shibboleth handler if it's necessary or log in.

File

./shib_auth.module, line 292

Code

function user_external_login_register($name, $module) {
  global $user;

  // Try to load the user
  $user = user_load(array(
    'name' => $name,
  ));
  if (!isset($user->uid)) {

    // 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'));
  }
}