You are here

function hybridauth_user_identity in HybridAuth Social Login 7.2

Same name and namespace in other branches
  1. 6.2 hybridauth.pages.inc \hybridauth_user_identity()

Menu callback; manage HybridAuth identities for the specified user.

1 string reference to 'hybridauth_user_identity'
hybridauth_menu in ./hybridauth.module
Implements hook_menu().

File

./hybridauth.pages.inc, line 639
HybridAuth module pages.

Code

function hybridauth_user_identity($account) {
  global $user;
  drupal_set_title(format_username($account));
  $identities = _hybridauth_identity_load_by_uid($account->uid);
  $providers = hybridauth_providers_list();
  $header = array(
    t('Authentication provider'),
    t('Identity'),
    t('Delete'),
  );
  $rows = array();
  $data_array = array();
  foreach ($identities as $identity) {
    $data = unserialize($identity['data']);
    $data_array[] = $data;
    $rows[] = array(
      $providers[$data['provider']],
      l($data['profileURL'], $data['profileURL'], array(
        'attributes' => array(
          'target' => '_blank',
        ),
        'external' => TRUE,
      )),
      l(t('Delete'), 'user/' . $account->uid . '/hybridauth/delete/' . $identity['id']),
    );
  }
  $build = array();
  $build['identity'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#sticky' => FALSE,
    '#empty' => t("You don't have any identities yet."),
  );

  // Add more identities.
  if ($account->uid == $user->uid && user_access('use hybridauth')) {
    $build['hybridauth_widget'] = array(
      '#type' => 'hybridauth_widget',
      '#title' => t('Add more identities'),
      '#weight' => 10,
      '#hybridauth_widget_type' => 'list',
      '#hybridauth_destination' => '',
      '#hybridauth_destination_error' => '',
    );
  }
  if (variable_get('hybridauth_debug', FALSE)) {
    $connected_providers = hybridauth_get_connected_providers();
    $build['connected_providers'] = array(
      '#markup' => t('Currently connected to (session data):') . ' ' . implode(', ', $connected_providers),
      '#weight' => 15,
    );
  }

  // Tokens browser for admins.
  if (user_access('administer site configuration') || user_access('administer users')) {
    $build['vtabs'] = array(
      '#type' => 'vertical_tabs',
      '#weight' => 20,
    );
    $header = array(
      t('Token'),
      t('Value'),
    );

    // User tokens.
    if (!empty($account->data['hybridauth'])) {
      $build['vtabs']['fset_user_tokens'] = array(
        '#type' => 'fieldset',
        '#title' => t('User tokens'),
      );
      $rows = array();
      foreach ($account->data['hybridauth'] as $key => $value) {
        $rows[] = array(
          '[user:hybridauth:' . $key . ']',
          $value,
        );
      }
      $build['vtabs']['fset_user_tokens']['tokens'] = array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#sticky' => FALSE,
      );
    }

    // Data from auth providers.
    foreach ($data_array as $data) {
      $build['vtabs']['fset_' . $data['provider'] . '_' . $data['identifier']] = array(
        '#type' => 'fieldset',
        '#title' => $providers[$data['provider']],
      );
      $rows = array();
      foreach ($data as $key => $value) {
        $rows[] = array(
          $key,
          $value,
        );
      }
      $build['vtabs']['fset_' . $data['provider'] . '_' . $data['identifier']]['tokens'] = array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#sticky' => FALSE,
      );
    }
  }
  return $build;
}