PageSourceSearch

https://www.realclearhealth.com/asset/top/rcmg_users_v2/rcmg_spot.js

js realclearhealth.com collected 2026-09-25 14:23:47 UTC 3,465 bytes, 135 lines download raw bytes

1// If user clicks on submit (see if they are logged in)
2document.addEventListener('spot-im-login-start', function(event) {
3    console.log('spot-im-login-start sent');
4    console.log(event.detail);
5
6    loginModal.loadModal("sign-in-up");
7
8    loginModal.login_success = function () {
9      
10      rcmg_auth();
11      login_spot_im();
12    };
13});
14
15
16if(getCookie('rcmg_token') && getCookie('rcmg_guid')) {
17  login_spot_im();
18} else {
19  logout_spot_im(); // Because Spot.IM wants logout on every non-sso pageload
20}
21
22function login_spot_im() {
23
24  // Start SSO process
25  if (window.SPOTIM && window.SPOTIM.startSSO) {
26    console.log('here1');
27    startSSO();
28  } else {
29    console.log('here2');
30    document.addEventListener('spot-im-api-ready', startSSO, false);
31  }
32}
33
34// Listen for Logout action
35function logout_spot_im() {
36  
37  if(window.SPOTIM && window.SPOTIM.logout){
38    window.SPOTIM.logout();
39  } else {
40    document.addEventListener('spot-im-api-ready', function() { window.SPOTIM.logout(); }, false);
41  }
42}
43
44function login_callback(response, completeSSOCallback)
45{ 
46  if(typeof response !== 'undefined' && typeof response.data !== 'undefined' && 
47    typeof response.data['code_b'] !== 'undefined') {
48
49    if(typeof completeSSOCallback !== 'undefined') {
50      completeSSOCallback(response.data['code_b']);
51    }
52
53  } else {
54    console.log("Spot.IM code_b retreival error:");
55    console.log(response);
56
57    logout_spot_im(); // Because Spot.IM wants logout on every non-sso pageload
58  }
59    
60  //if there is a php error (we check with js first, sometimes an error might get to php we double check)       
61  if(response.success){
62    jQuery(document).trigger('close.facebox'); 
63  }else{
64    $('#errorDisplay').html(rcmg_api_first_error(response.messages));
65  }
66}
67
68function cookie_sso(codeA, completeSSOCallback)
69{
70  console.log({
71    'codeA': codeA,
72    'completeSSOCallback': completeSSOCallback
73  })
74  // call your backend to receive codeB and return it
75  // to Spot.IM via completeSSOCallback function
76  
77  var rcmg_token = getCookie('rcmg_token');
78  var rcmg_guid = getCookie('rcmg_guid');
79
80  var data_send = {
81    token: rcmg_token,
82    guid: rcmg_guid,
83    userAgent: navigator.userAgent
84  };
85
86  if(typeof codeA !== 'undefined') {
87    data_send['code_a'] = codeA;
88  }
89
90  rcmg_api_call('spot_login', data_send, function(response) {
91
92    login_callback(response, completeSSOCallback);
93
94    // if this fails, delete cookies and refresh?
95  });
96}
97
98var spot_im_callback = function(codeA, completeSSOCallback) {
99
100  var rcmg_token = getCookie('rcmg_token');
101  var rcmg_guid = getCookie('rcmg_guid');
102
103  if(rcmg_token && rcmg_guid) {
104    cookie_sso(codeA, completeSSOCallback);
105  } else {
106    // Not logged in (no cookies) so no SSO
107  }
108};
109
110function startSSO() {
111
112  window.SPOTIM.startSSO(spot_im_callback).then(function(result) {
113    // result.type === 'SSO_Complete'
114    // or
115    // result.type === 'SSO_AlreadyLoggedIn'
116    console.log('spotim result:');
117    console.log(result);
118
119    // SUCCESSFULLY LOGGED IN
120
121  }).catch(function(reason){
122    // reason contains error details
123    console.log("Spot.IM startSSO error:");
124    console.log(reason);
125
126    // Tries one more time
127    if(reason == "Can't start SSO process since SSO is in progress") {
128      startSSO();
129    }
130  });
131}
132
133/*testing Deployment sync
134* 10/14/20
135* */

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.