-
Notifications
You must be signed in to change notification settings - Fork 5
/
gigyaHelper.js
87 lines (81 loc) · 2.38 KB
/
gigyaHelper.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
83
84
85
86
87
var gigyaHelper = {
addGigyaScript: function (apiKey, lang) {
var gig = document.createElement('script');
gig.type = 'text/javascript';
gig.async = true;
gig.src = ('https:' === document.location.protocol ? 'https://cdns' : 'http://cdn') + '.gigya.com/js/gigya.js?apiKey=' + apiKey + '&lang=' + lang;
document.getElementsByTagName('head')[0].appendChild(gig);
},
checkLogout: function () {
var logoutCookie = gigya.utils.cookie.get("gigyaLogout");
if (logoutCookie) {
gigya.accouts.logout();
}
},
addGigyaFunctionCall: function (method, params) {
window.gigyaCmsInit = window.gigyaCmsInit || [];
var func = {function: method, parameters: params};
window.gigyaCmsInit.push(func);
},
onLoginHandler: function (res) {
/* This is an example for an onLogin event handler it uses jQuery, if jQuery is not available at your system
* replace with your own version of ajax call
* NOTE: this example should be a edited to work.
*/
var data = {
"uid": res.UID,
"uigSig": res.UIDSignature,
"sigTimestamp": res.signatureTimestamp
},
serverSideUrl = "edit this to point to the url that would receive the the info";
jQuery.ajax(serverSideUrl, {
data: data,
dataType: "text",
type: "POST",
async: false,
global: false
}).done(function (res) {
var response = JSON.parse(res);
if (response.success === "success") {
// Do what is needed to show that the user is logged in (reload the page etc...)
} else {
// Logout user from gigya
gigya.account.logout();
// Show error etc...
}
}).fail(function () {
// Logout user from gigya
gigya.account.logout();
// Show error etc...
});
},
runGigyaCmsInit: function () {
if (window.gigyaCmsInit) {
var length = window.gigyaCmsInit.length,
element = null;
if (length > 0) {
for (var i = 0; i < length; i++) {
element = window.gigyaCmsInit[i];
var func = element.function;
var parts = func.split("\.");
var f = gigya[parts[0]][parts[1]];
if (typeof f === "function") {
f(element.parameters);
}
}
}
}
}
};
(function addGigya() {
var apiKey = gigyaCmsConfig.apiKey,
lang = gigyaCmsConfig.lang;
gigyaHelper.addGigyaScript(apiKey, lang);
})();
function onGigyaServiceReady(serviceName) {
gigyaHelper.checkLogout();
gigyaHelper.runGigyaCmsInit();
gigya.accounts.addEventHandlers(
{onLogin: gigyaHelper.onLoginHandler}
);
}