harshancx

dd

Aug 14th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. <?php
  2. /**
  3. * Implements hook_user_logout().
  4. */
  5. function edb_idp_user_logout($account) {
  6. if (!empty($_COOKIE)) {
  7. foreach($_COOKIE as $name => $cookie) {
  8. setcookie($name, '', time()-1000, '');
  9. setcookie($name, '', time()-1000, '/');
  10. setcookie($name, '', time()-1000, '/', 'www.enterprisedb.com');
  11. setcookie($name, '', time()-1000, '/', '.www.enterprisedb.com');
  12. }
  13. }
  14. }
  15.  
  16. /**
  17. * Implements hook_user_init().
  18. */
  19. function edb_idp_init() {
  20. if(isset($_GET['ReturnTo'])) {
  21. $urls = array(
  22. 'ssobeta.viewcentral.com',
  23. 'sso.viewcentral.com',
  24. 'salesforce.com',
  25. 'ssoqa.viewcentral.com',
  26. 'community.postgresrocks.net',
  27. 'stage-community.postgresrocks.net',
  28. );
  29. $haystack = $_GET['ReturnTo'];
  30. foreach ($urls as $needle) {
  31. if (strpos($haystack, $needle) > 0) {
  32. if(stristr($needle, 'community.postgresrocks.net')) {
  33. setcookie('ReturnTo', $needle, time() + 240);
  34. } else {
  35. setcookie('ReturnTo', $needle);
  36. }
  37.  
  38. }
  39. }
  40. }
  41. }
  42.  
  43. /**
  44. * Implements hook_user_presave().
  45. */
  46. function edb_idp_user_presave(&$edit, $account, $category) {
  47. if(isset($_COOKIE['ReturnTo']) && ($_COOKIE['ReturnTo'] == 'sso.viewcentral.com' || $_COOKIE['ReturnTo'] == 'ssobeta.viewcentral.com' || $_COOKIE['ReturnTo'] == 'ssoqa.viewcentral.com')) {
  48. $lang = LANGUAGE_NONE;
  49. if(isset($account->language) && strlen($account->language) > 0) {
  50. $lang = $account->language;
  51. }
  52. $edit['field_user_last_campaign'][$lang][0]['value'] = variable_get('edb_idp_view_central_campaign_id','70138000001AepQ');
  53. }
  54. }
  55.  
  56. /**
  57. * Implements hook_user_view().
  58. */
  59. function edb_idp_user_view($account, $view_mode, $langcode) {
  60. if (!empty($_COOKIE['ReturnTo'])) {
  61. if ($_COOKIE['ReturnTo'] == 'community.postgresrocks.net') {
  62. _edb_idp_destroy_returnto_cookie();
  63. _edb_idp_lithium_user_view_redirect();
  64. } elseif ($_COOKIE['ReturnTo'] == 'stage-community.postgresrocks.net') {
  65. _edb_idp_destroy_returnto_cookie();
  66. _edb_idp_lithium_stage_user_view_redirect();
  67. }
  68. }
  69. }
  70.  
  71. function lithium_cookie_check() {
  72. if(!empty($_COOKIE['ReturnTo']) && stristr($_COOKIE['ReturnTo'], 'community.postgresrocks.net')) {
  73. return true;
  74. } elseif (!empty($_GET['ReturnTo']) && stristr($_GET['ReturnTo'], 'community.postgresrocks.net')) {
  75. return true;
  76. } else {
  77. return false;
  78. }
  79. }
  80.  
  81. /*
  82. * Implements hook_preprocess_html to destroy return_to cookie when a user views
  83. * a page other than user login, registration, or password reset and their cookie is Lithium
  84. */
  85. function edp_idp_preprocess_html(&$variables) {
  86. if (!stristr(current_path(), 'user') && lithium_cookie_check()) {
  87. _edb_idp_destroy_returnto_cookie();
  88. }
  89. }
  90.  
  91. function _edb_idp_destroy_returnto_cookie() {
  92. setcookie("ReturnTo", "", time()-3600);
  93. }
  94.  
  95. /**
  96. * Implements hook_form_alter()
  97. */
  98. function edb_idp_form_alter(&$form, &$form_state, $form_id) {
  99. if (($form_id == 'user_login_block' || $form_id == 'user_login') && isset($_GET['login_redirect']) && $_GET['login_redirect'] == 'salesforce') {
  100. setcookie('login_redirect', $_GET['login_redirect']);
  101. $form['#submit'][] = '_edb_idp_salesforce_redirect';
  102. } elseif($form_id == 'user_register_form' && !empty($_COOKIE['login_redirect']) && $_COOKIE['login_redirect'] == 'salesforce') {
  103. $form['#submit'][] = '_edb_idp_salesforce_redirect';
  104. }
  105. elseif($form_id == 'user_register_form' && !empty($_COOKIE['ReturnTo'])) {
  106. switch ($_COOKIE['ReturnTo']) {
  107. case 'ssobeta.viewcentral.com':
  108. $form['#submit'][] = '_edb_idp_viewcentral_beta_redirect';
  109. break;
  110.  
  111. case 'sso.viewcentral.com':
  112. $form['#submit'][] = '_edb_idp_viewcentral_inter_redirect';
  113. break;
  114.  
  115. case 'ssoqa.viewcentral.com':
  116. $form['#submit'][] = '_edb_idp_viewcentral_inter_redirect';
  117. break;
  118.  
  119. case 'stage-community.postgresrocks.net':
  120. $form['#submit'][] = '_edb_idp_lithium_stage_redirect';
  121. break;
  122.  
  123. case 'community.postgresrocks.net':
  124. $form['#submit'][] = '_edb_idp_lithium_prod_redirect';
  125. break;
  126.  
  127. }
  128. }
  129. if($form_id == 'edb_landing_page_user_form' || $form_id == 'user_register' || $form_id == 'user_register_form') {
  130. $form['actions']['submit']['#value'] = t('Submit');
  131. }
  132. }
  133.  
  134. function _edb_idp_lithium_stage_user_view_redirect() {
  135. $url = '/simplesaml/saml2/idp/SSOService.php';
  136. $query = array(
  137. 'spentityid' => 'https://stage-community.postgresrocks.net/auth/saml',
  138. );
  139. drupal_goto($url, array('query' => $query));
  140. }
  141.  
  142. function _edb_idp_lithium_user_view_redirect() {
  143. $url = '/simplesaml/saml2/idp/SSOService.php';
  144. $query = array(
  145. 'spentityid' => 'https://community.postgresrocks.net/auth/saml',
  146. );
  147. drupal_goto($url, array('query' => $query));
  148. }
  149.  
  150. function _edb_idp_lithium_stage_redirect($form, &$form_state) {
  151. $query = array(
  152. 'spentityid' => 'https://stage-community.postgresrocks.net/auth/saml',
  153. );
  154. $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
  155. }
  156. function _edb_idp_lithium_prod_redirect($form, &$form_state) {
  157. $query = array(
  158. 'spentityid' => 'https://community.postgresrocks.net/auth/saml',
  159. );
  160. $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
  161. }
  162.  
  163. function _edb_idp_viewcentral_inter_redirect($form, &$form_state) {
  164. $query = array(
  165. 'spentityid' => 'https://sso.viewcentral.com/ServiceProvider',
  166. );
  167. $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
  168. }
  169.  
  170. function _edb_idp_viewcentral_beta_redirect($form, &$form_state) {
  171. $query = array(
  172. 'spentityid' => 'https://ssobeta.viewcentral.com/ServiceProvider',
  173. );
  174. $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
  175. }
  176.  
  177. function _edb_idp_salesforce_redirect($form, &$form_state) {
  178. $query = array(
  179. 'spentityid' => 'https://enterprisedbpartners.force.com',
  180. );
  181. $form_state['redirect'] = array('/simplesaml/saml2/idp/SSOService.php', array('query' => $query));
  182. }
Advertisement
Add Comment
Please, Sign In to add comment