You are here

function simplesamlphp_auth_user_insert in simpleSAMLphp Authentication 7.3

Same name and namespace in other branches
  1. 7 simplesamlphp_auth.module \simplesamlphp_auth_user_insert()
  2. 7.2 simplesamlphp_auth.module \simplesamlphp_auth_user_insert()

Implements hook_user_insert().

File

./simplesamlphp_auth.module, line 202
simpleSAMLphp authentication module for Drupal.

Code

function simplesamlphp_auth_user_insert(&$edit, $account, $category = NULL) {
  global $_simplesamlphp_auth_as;
  global $_simplesamlphp_auth_saml_attributes;
  if (!_simplesaml_auth_autoload()) {

    // Exit without initializing.
    return;
  }
  if ($category == 'account') {

    // If user registration has a valid session...
    if ($_simplesamlphp_auth_as
      ->isAuthenticated() && _simplesamlphp_auth_get_authname() == $account->init) {

      // Get name from default attributes.
      try {
        if (variable_get('simplesamlphp_auth_debug', 0)) {
          watchdog('simplesamlphp_auth', 'Registering user [%acctname]', array(
            '%acctname' => $account->name,
          ), WATCHDOG_DEBUG);
        }
        $account->name = _simplesamlphp_auth_get_default_name($account->uid);
      } catch (Exception $e) {
        drupal_set_message(t('Your user name was not provided by your identity provider (IDP).'), "error");
        watchdog('simplesamlphp_auth', $e
          ->getMessage(), NULL, WATCHDOG_CRITICAL);
      }
      module_load_include('inc', 'simplesamlphp_auth');

      // Update username and email address.
      // @todo Make this conditional.
      _simplesaml_auth_user_update($account);
      if (module_exists('rules')) {
        rules_invoke_all('simplesamlphp_auth_rules_event_register', $account);
      }

      // Reload the user object to ensure that all properties are populated.
      $user = user_load($account->uid);
      _simplesaml_auth_user_login($user);
    }
  }
}