forked from gigya/wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gigya.js
82 lines (67 loc) · 2.35 KB
/
gigya.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var GigyaWp = GigyaWp || {};
(function ($) {
/**
* @class gigyaParams
* @property logoutUrl
*
* @class gigyaLoginParams
* @class gigyaRaasParams
*/
// --------------------------------------------------------------------
window.__gigyaConf = gigyaParams;
// --------------------------------------------------------------------
$(document).ready(function () {
// jQueryUI dialog element.
$('body').append('<div id="dialog-modal"></div>');
GigyaWp.logout = function (response) {
jQuery.post(ajaxurl, {action: 'gigya_logout'}, function (response) {
window.location.reload();
});
};
} );
GigyaWp.userLoggedIn = function (response) {
GigyaWp.loggedUser = response.user.UID;
if (GigyaWp.loggedUser.length === 0) {
location.replace(gigyaParams.logoutUrl);
}
return GigyaWp.loggedUser;
};
// --------------------------------------------------------------------
GigyaWp.errHandle = function (errEvent) {
return false;
};
// --------------------------------------------------------------------
GigyaWp.redirect = function () {
var redirectTarget = '';
if (location.pathname.indexOf('wp-login.php') !== -1) {
/* Sets redirect after login page */
if (typeof gigyaLoginParams !== 'undefined') {
redirectTarget = gigyaLoginParams.redirect;
}
else if (typeof gigyaRaasParams !== 'undefined') {
redirectTarget = gigyaRaasParams.redirect;
}
}
else {
/* Sets self-redirect (refresh) */
redirectTarget = window.location.href;
}
/* This part relies on a global variable called sendSetSSOToken, which is not part of the connector's code base. It needs to be set in an outside script.
* This was done in order to allow to add logic to this variable from the outside, ideally in Gigya's global configuration, which can be set in the connector's UI. */
if (typeof sendSetSSOToken === 'undefined' || sendSetSSOToken === false)
location.replace(redirectTarget);
else if (sendSetSSOToken === true)
gigya.setSSOToken({redirectURL: redirectTarget});
};
GigyaWp.getEssentialParams = function (gigyaObj) {
var esData = {};
var primitive = ['string', 'number', 'boolean'];
$.each(gigyaObj.response, function (key, val) {
if ($.inArray($.type(val), primitive) >= 0) {
esData[key] = val;
}
});
return esData;
};
// --------------------------------------------------------------------
})(jQuery);