PageSourceSearch

https://www.1057thepoint.com/wp-content/plugins/hbi-sso/public/js/hbi-sso-public.js?ver=1.0.1

js 1057thepoint.com collected 2026-10-02 11:20:38 UTC 10,468 bytes, 325 lines download raw bytes

1// Handles Hubbard SSO
2(function($, LiveLogin, live_data) {
3	$.extend(LiveLogin, {
4		init: function(){
5			var _this = this;
6			this.cookieDomainName = '.' + window.LiveLoginSettings.cookie_domain;
7			this.menu = $('#live_login_menu');
8			this.menu_display_name = this.menu.find('.live_login_name');
9			this.menu_notification_count = this.menu.find('.notification-count');
10
11			// Revalidate token
12			this.revalidateToken();
13
14			// Start
15			this.checkUser();
16
17			// Show hover on click
18			this.menu.find('.open-drop, .live_login_name').click(function(e) {
19				var closest = $(e.target).closest('.open-drop');
20				closest.next('.sub-menu').removeClass('hide');
21				e.preventDefault();
22			});
23
24			// Hide on unclick
25			$(document).click(function(e) {
26				if($(e.target).closest('.open-drop').length > 0) {
27					return;
28				}
29
30				var closest = $(e.target).closest('.sub-menu');
31				if(closest.length <= 1) {
32					_this.menu.find('.active').find('.sub-menu').addClass('hide');
33				}
34			});
35
36			// Login Form Submission
37			$('#live_login_menu form').submit( function(e){
38				$('.loginform .error-message').hide();
39				var email = $( 'input[name=email]', e.currentTarget ).val() ;
40				var password = $( 'input[name=password]', e.currentTarget ).val();
41				$.ajax({
42					url : window.LiveLoginSettings.endpoint + '/wp-json/jwt-auth/v1/token',
43					type : 'post',
44					data: JSON.stringify({
45						username: email,
46						password: password
47					}),
48					contentType: 'application/json',
49					crossDomain: true,
50					dataType: 'json',
51					success : function( data ) {
52						if( ! data.error ){
53							_this.setCookies( data );
54							_this.checkUser();
55							_this.updateRewardsGridWidgets();
56						} else {
57							$('.loginform .error-message').html( data.error.replace('username','email') );
58							$('.loginform .error-message').show();
59						}
60					},
61					error: function( xhr, textStatus, errorThrown){
62						$('.loginform .error-message').html( xhr.responseJSON.message.replace('username','email') );
63						$('.loginform .error-message').show();
64					}
65				});
66				return false;
67			});
68
69			// Logout Link
70			this.menu.find('.logout-action').click(function(e) {
71				// Delete cookies
72				_this.deleteTokenCookie();
73				_this.deleteUserInfoCookie();
74
75				// Reset user info
76				_this.user_info = null;
77				_this.checkUser();
78				_this.updateRewardsGridWidgets();
79
80				// Logout Facebook
81				if(FB !== undefined) { // I don't think this works, you need to pass the session token
82					FB.logout();
83				}
84			});
85		},
86		fbLoginAction: function() {
87			FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
88				console.log('FB login status', response);
89				window.LiveLogin.facebookCheckStatus(response);        // Returns the login status.
90			});
91		},
92		// Called by FB initializer after login/logout and page reload
93		facebookCheckStatus: function(response) {
94				$('.loginform .error-message').hide();
95
96				// User is already logged in
97				var user = this.getUserInfo();
98				if( user ) {
99					console.log('FB login - user already logged in');
100					return;
101				}
102
103				// If FB user is not logged in
104				if (response.status !== 'connected') {
105					return;
106				}
107
108				console.log('FB login status connected -- logging in user');
109				console.log('response: ', response)
110
111				// Send token to Player and get user
112				this.loginFacebookUser(response.authResponse.accessToken);
113
114		},
115		loginFacebookUser: function(fb_access_token) {
116			var _this = this;
117			$.ajax({
118				url : window.LiveLoginSettings.endpoint + '/wp-json/hll/v1/hll_facebook_token_ex',
119				type : 'post',
120				data: JSON.stringify({
121					request_method: "GET",
122					token: fb_access_token,
123					send_jwt: true
124				}),
125				contentType: 'application/json',
126				crossDomain: true,
127				dataType: 'json',
128				success : function( data ) {
129					if( ! data.error ){
130						_this.setCookies( data );
131						_this.checkUser();
132					} else {
133						$('.loginform .error-message').html( data.error.replace('username','email') );
134						$('.loginform .error-message').show();
135					}
136
137				},
138				error: function( data, textStatus, errorThrown){
139					var errorMessage = "A problem occurred.";
140					if(data.status === 404) {
141						if(window.LiveLoginSettings.stationSSOEnabled) {
142							errorMessage = "There is not a profile associated with this Facebook account, please " + `<a style='text-decoration: underline' href='/profile/register'>` + "create an account" + "</a>" + ".";
143						} else {
144							errorMessage = "There is not a profile associated with this Facebook account, please " + `<a style='text-decoration: underline' href='${window.LiveLoginSettings.endpoint}/listen/register' target='_blank'>` + "create an account" + "</a>" + ".";
145						}
146					}
147
148					$('.loginform .error-message').html( errorMessage );
149					$('.loginform .error-message').show();
150				}
151			});
152		},
153		checkUser: function() {
154			// Reset active menu
155			this.menu.find('.non-logged,.logged').removeClass('active');
156
157			// Reset submenus
158			this.menu.find(".sub-menu").addClass('hide');
159
160			// Reset count
161			this.menu_notification_count.html("");
162
163			// User
164			var user = this.getUserInfo();
165			if( user ){
166				this.setupUserLoggedIn();
167				this.getNotifications();
168			} else {
169				this.setupUserNotLoggedIn();
170			}
171		},
172		setupUserLoggedIn: function() {
173			this.menu.find('.non-logged').addClass('hide');
174			this.menu.find('.logged').removeClass('hide').addClass('active');
175			var user = this.getUserInfo();
176			this.menu_display_name.html(user.display_name);
177		},
178		setupUserNotLoggedIn: function() {
179			this.menu.find('.logged').addClass('hide');
180			this.menu.find('.non-logged').removeClass('hide').addClass('active');
181		},
182		getUserInfo: function () {
183			if(this.user_info) {
184				return this.user_info;
185			} else if(this.getCookieByName(window.LiveLoginSettings.user_info_cookie_name)) {
186				let cookieValue = decodeURIComponent(this.getCookieByName(window.LiveLoginSettings.user_info_cookie_name));
187
188				try {
189					this.user_info = JSON.parse(cookieValue);
190				} catch (e) {
191					try {
192						this.user_info = JSON.parse(decodeURIComponent(cookieValue));
193					} catch (e2) {
194						this.user_info = null;
195					}
196				}
197
198				return this.user_info;
199			} else {
200				return null;
201			}
202		},
203		getCookieByName: function( name ) {
204			var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
205			return v ? v[2].replace('+',' ') : null;
206		},
207		setCookies: function( data ){
208			var user_data = {
209				display_name : data.user_display_name,
210				user_id : data.user_id,
211			};
212
213			// Separate First and Last name
214			var split_name = data.user_display_name.split(" ", 1);
215			if(split_name.length > 0) {
216				user_data.display_name = split_name[0];
217			}
218
219			this.setUserInfoCookie( JSON.stringify(user_data));
220			this.setTokenCookie( data.token );
221		},
222		setTokenCookie: function( value ){
223			var key = window.LiveLoginSettings.token_cookie_name;
224			var expires = new Date();
225			expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000));
226			document.cookie = key + '=' + value + ';domain=' + this.cookieDomainName + ';path=/;expires=' + expires.toUTCString();
227		},
228		deleteTokenCookie: function(){
229			document.cookie = window.LiveLoginSettings.token_cookie_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=" + this.cookieDomainName + "; path=/;";
230		},
231		setUserInfoCookie: function (value ){
232			var expires = new Date();
233			expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000));
234			document.cookie = window.LiveLoginSettings.user_info_cookie_name + '=' + value + ';domain=' + this.cookieDomainName + ';path=/;expires=' + expires.toUTCString();
235		},
236		deleteUserInfoCookie: function() {
237			document.cookie = window.LiveLoginSettings.user_info_cookie_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=" + this.cookieDomainName + "; path=/;";
238		},
239		deleteUserSegmentCookie: function() {
240			//Delete the cookie that WP Engine uses to serve different cached versions to different user segments
241			document.cookie = window.LiveLoginSettings.user_segment_cookie_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=" + this.cookieDomainName + "; path=/;";
242		},
243		revalidateToken: function () {
244			var _this = this;
245			//If this.lastValidationTime was less than 5 minutes ago, don't revalidate the token
246			if(this.lastValidationTime && (new Date().getTime() - this.lastValidationTime) < 300000) {
247				return;
248			}
249
250			var token = this.getCookieByName( window.LiveLoginSettings.token_cookie_name );
251			if(!token) {
252				return;
253			}
254
255			$.ajax({
256				type: "POST",
257				url: window.LiveLoginSettings.endpoint + "/wp-json/jwt-auth/v1/token/validate?new_token=1",
258				success: function( data ) {
259					if( ! data.error ){
260						_this.setCookies( data );
261					}
262				},
263				error: function(jqXHR, textStatus, errorThrown) {
264
265				},
266				beforeSend: function (xhr ) {
267					xhr.setRequestHeader("Authorization", 'Bearer ' + token);
268				},
269			});
270
271			_this.lastValidationTime = new Date().getTime();
272		},
273		getNotifications: function( ){
274			var _this = this;
275			var token = this.getCookieByName( window.LiveLoginSettings.token_cookie_name );
276			$.ajax({
277				type: "GET",
278				url: window.LiveLoginSettings.endpoint + "/wp-json/hll/v1/hll_notifications_get",
279				success: function( data ) {
280					var total_unseen = 0;
281					for( var i=0; i < data.data.length ; i++){
282						if (data.data[i].seen === null){
283							total_unseen += 1;
284						}
285					}
286					_this.setNotificationsCount(total_unseen);
287				},
288				error: function(jqXHR, textStatus, errorThrown) {
289					console.log( jqXHR );
290					console.log( textStatus );
291					console.log( errorThrown );
292				},
293				beforeSend: function (xhr ) {
294					xhr.setRequestHeader("Authorization", 'Bearer ' + token);
295				},
296			});
297		},
298		updateRewardsGridWidgets: function(){
299			if(typeof window.hllRewardsGridWidgets === 'undefined'){
300				return;
301			}
302
303			window.hllRewardsGridWidgets.forEach(function(widget){
304				widget.div.innerHTML = '';
305				widget.init();
306			});
307		},
308		setNotificationsCount: function(total_unseen) {
309			if(total_unseen > 0) {
310				this.menu_notification_count.html(total_unseen).removeClass('hide');
311			} else {
312				this.menu_notification_count.html("").addClass('hide');
313			}
314		}
315	});
316
317	// Make our namespace globally accessible
318	window.LiveLogin = LiveLogin;
319
320	// Run initialization script on DOM ready
321	$(document).ready(function() {
322		LiveLogin.init();
323	});
324
325})(jQuery, window.LiveLogin || {}, window.live_data || {}, window.LiveLoginSettings);

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.