Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implements hook_user_logout().
- */
- function edb_idp_user_logout($account) {
- if (!empty($_COOKIE)) {
- foreach($_COOKIE as $name => $cookie) {
- setcookie($name, '', time()-1000, '');
- setcookie($name, '', time()-1000, '/');
- setcookie($name, '', time()-1000, '/', 'www.enterprisedb.com');
- setcookie($name, '', time()-1000, '/', '.www.enterprisedb.com');
- }
- }
- }
- /**
- * Implements hook_user_init().
- */
- function edb_idp_init() {
- if(isset($_GET['ReturnTo'])) {
- $urls = array(
- 'ssobeta.viewcentral.com',
- 'sso.viewcentral.com',
- 'salesforce.com',
- 'ssoqa.viewcentral.com',
- 'community.postgresrocks.net',
- 'stage-community.postgresrocks.net',
- );
- $haystack = $_GET['ReturnTo'];
- foreach ($urls as $needle) {
- if (strpos($haystack, $needle) > 0) {
- if(stristr($needle, 'community.postgresrocks.net')) {
- setcookie('ReturnTo', $needle, time() + 240);
- } else {
- setcookie('ReturnTo', $needle);
- }
- }
- }
- }
- }
- /**
- * Implements hook_user_presave().
- */
- function edb_idp_user_presave(&$edit, $account, $category) {
- if(isset($_COOKIE['ReturnTo']) && ($_COOKIE['ReturnTo'] == 'sso.viewcentral.com' || $_COOKIE['ReturnTo'] == 'ssobeta.viewcentral.com' || $_COOKIE['ReturnTo'] == 'ssoqa.viewcentral.com')) {
- $lang = LANGUAGE_NONE;
- if(isset($account->language) && strlen($account->language) > 0) {
- $lang = $account->language;
- }
- $edit['field_user_last_campaign'][$lang][0]['value'] = variable_get('edb_idp_view_central_campaign_id','70138000001AepQ');
- }
- }
- /**
- * Implements hook_user_view().
- */
- function edb_idp_user_view($account, $view_mode, $langcode) {
- if (!empty($_COOKIE['ReturnTo'])) {
- if ($_COOKIE['ReturnTo'] == 'community.postgresrocks.net') {
- _edb_idp_destroy_returnto_cookie();
- _edb_idp_lithium_user_view_redirect();
- } elseif ($_COOKIE['ReturnTo'] == 'stage-community.postgresrocks.net') {
- _edb_idp_destroy_returnto_cookie();
- _edb_idp_lithium_stage_user_view_redirect();
- }
- }
- }
- function lithium_cookie_check() {
- if(!empty($_COOKIE['ReturnTo']) && stristr($_COOKIE['ReturnTo'], 'community.postgresrocks.net')) {
- return true;
- } elseif (!empty($_GET['ReturnTo']) && stristr($_GET['ReturnTo'], 'community.postgresrocks.net')) {
- return true;
- } else {
- return false;
- }
- }
- /*
- * Implements hook_preprocess_html to destroy return_to cookie when a user views
- * a page other than user login, registration, or password reset and their cookie is Lithium
- */
- function edp_idp_preprocess_html(&$variables) {
- if (!stristr(current_path(), 'user') && lithium_cookie_check()) {
- _edb_idp_destroy_returnto_cookie();
- }
- }
- function _edb_idp_destroy_returnto_cookie() {
- setcookie("ReturnTo", "", time()-3600);
- }
- /**
- * Implements hook_form_alter()
- */
- function edb_idp_form_alter(&$form, &$form_state, $form_id) {
- if (($form_id == 'user_login_block' || $form_id == 'user_login') && isset($_GET['login_redirect']) && $_GET['login_redirect'] == 'salesforce') {
- setcookie('login_redirect', $_GET['login_redirect']);
- $form['#submit'][] = '_edb_idp_salesforce_redirect';
- } elseif($form_id == 'user_register_form' && !empty($_COOKIE['login_redirect']) && $_COOKIE['login_redirect'] == 'salesforce') {
- $form['#submit'][] = '_edb_idp_salesforce_redirect';
- }
- elseif($form_id == 'user_register_form' && !empty($_COOKIE['ReturnTo'])) {
- switch ($_COOKIE['ReturnTo']) {
- case 'ssobeta.viewcentral.com':
- $form['#submit'][] = '_edb_idp_viewcentral_beta_redirect';
- break;
- case 'sso.viewcentral.com':
- $form['#submit'][] = '_edb_idp_viewcentral_inter_redirect';
- break;
- case 'ssoqa.viewcentral.com':
- $form['#submit'][] = '_edb_idp_viewcentral_inter_redirect';
- break;
- case 'stage-community.postgresrocks.net':
- $form['#submit'][] = '_edb_idp_lithium_stage_redirect';
- break;
- case 'community.postgresrocks.net':
- $form['#submit'][] = '_edb_idp_lithium_prod_redirect';
- break;
- }
- }
- if($form_id == 'edb_landing_page_user_form' || $form_id == 'user_register' || $form_id == 'user_register_form') {
- $form['actions']['submit']['#value'] = t('Submit');
- }
- }
- function _edb_idp_lithium_stage_user_view_redirect() {
- $url = '/simplesaml/saml2/idp/SSOService.php';
- $query = array(
- 'spentityid' => 'https://stage-community.postgresrocks.net/auth/saml',
- );
- drupal_goto($url, array('query' => $query));
- }
- function _edb_idp_lithium_user_view_redirect() {
- $url = '/simplesaml/saml2/idp/SSOService.php';
- $query = array(
- 'spentityid' => 'https://community.postgresrocks.net/auth/saml',
- );
- drupal_goto($url, array('query' => $query));
- }
- function _edb_idp_lithium_stage_redirect($form, &$form_state) {
- $query = array(
- 'spentityid' => 'https://stage-community.postgresrocks.net/auth/saml',
- );
- $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
- }
- function _edb_idp_lithium_prod_redirect($form, &$form_state) {
- $query = array(
- 'spentityid' => 'https://community.postgresrocks.net/auth/saml',
- );
- $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
- }
- function _edb_idp_viewcentral_inter_redirect($form, &$form_state) {
- $query = array(
- 'spentityid' => 'https://sso.viewcentral.com/ServiceProvider',
- );
- $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
- }
- function _edb_idp_viewcentral_beta_redirect($form, &$form_state) {
- $query = array(
- 'spentityid' => 'https://ssobeta.viewcentral.com/ServiceProvider',
- );
- $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
- }
- function _edb_idp_salesforce_redirect($form, &$form_state) {
- $query = array(
- 'spentityid' => 'https://enterprisedbpartners.force.com',
- );
- $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
- }
Advertisement
Add Comment
Please, Sign In to add comment