You are here

function _hybridauth_popup_auth in HybridAuth Social Login 7

1 call to _hybridauth_popup_auth()
hybridauth_popup in ./hybridauth.pages.inc

File

./hybridauth.pages.inc, line 177

Code

function _hybridauth_popup_auth($hybridauth, $provider_id) {
  $_SESSION['hybridauth'] = array();
  $_SESSION['hybridauth']['stat'] = 'ok';
  $params = array();
  if (isset($_GET['openid_identifier'])) {
    $params['openid_identifier'] = $_GET['openid_identifier'];
  }
  try {
    $adapter = $hybridauth
      ->authenticate($provider_id, $params);
    $profile = (array) $adapter
      ->getUserProfile();
  } catch (Exception $e) {
    $_SESSION['hybridauth']['stat'] = $e
      ->getMessage();
    drupal_set_message(t('We were unable to complete your request.'), 'error');
    watchdog_exception('hybridauth', $e);

    // Cleanly close popup and redirect
    $GLOBALS['devel_shutdown'] = FALSE;

    // Prevent devel module from spewing.
    $destination = isset($_GET['destination']) ? $_GET['destination'] : 'user';
    drupal_add_js('
      if (window.opener){
        try { window.opener.parent.$.colorbox.close(); } catch(err) {}
        window.opener.parent.location.href = "' . url($destination, array(
      'absolute' => TRUE,
    )) . '";
      }
      window.self.close();
    ', 'inline');
    $page = array(
      'page_top' => '',
      '#children' => 'Closing...',
      'page_bottom' => '',
    );
    print theme('html', array(
      'page' => $page,
    ));
    drupal_exit();
  }

  // If we got here then success!
  return _hybridauth_popup_process_auth($hybridauth, $adapter, $profile, $provider_id);
}