You are here

function simplesamlphp_auth_user_insert in simpleSAMLphp Authentication 7

Same name and namespace in other branches
  1. 7.3 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 286
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 ($category = 'account') {

    // If user registration has a valid session...
    if ($_simplesamlphp_auth_as
      ->isAuthenticated()) {

      // Get name from default attributes.
      try {
        _simplesaml_auth_debug(t('Registering user [%acctname]', array(
          '%acctname' => $account->name,
        )));
        $account->name = _simplesamlphp_auth_get_default_name($account->uid);
      } catch (Exception $e) {
        $message = t('Username is missing.' . $e
          ->getMessage());
        drupal_set_message($message, "error");
        watchdog('simplesamlphp', $message, WATCHDOG_CRITICAL);
      }
      db_update('users')
        ->fields(array(
        'name' => $account->name,
      ))
        ->condition('uid', $account->uid)
        ->execute();
      _simplesaml_auth_debug(t('Updating username [%acctname]', array(
        '%acctname' => $account->name,
      )));

      // Get mail from default attribute.
      try {
        $mail_address = _simplesamlphp_auth_get_mail();
      } catch (Exception $e) {
        $message = t('Email is missing.' . $e
          ->getMessage());
        drupal_set_message($message, "error");
        watchdog('simplesamlphp', $message, WATCHDOG_CRITICAL);
      }
      if (!empty($mail_address)) {
        db_update('users')
          ->fields(array(
          'mail' => $mail_address,
        ))
          ->condition('uid', $account->uid)
          ->execute();
      }
      _simplesaml_auth_debug(t('Updating mail [%mailaddr]', array(
        '%mailaddr' => $mail_address,
      )));
    }
  }
}