var expire5min = (new Date()).getTime() + 120000;
// Global configuration object for Gigya JS API methods
var conf = {
sessionExpiration: 0 // expire the user login session when the browser closes
, connectWithoutLoginBehavior: 'alwaysLogin' // This will cause Gigya's 'Adding Connection' operation (i.e. when the user clicks one of the social network buttons within the Social Plugins) // to behave like a call to login in case the current user is not logged in.
, newUsersPendingRegistration: true // When a new user logs-in (registers) via Gigya his new account is not considered final until socialize.notifyRegistration is called.
, autoShareExpiration: expire5min // User's auto-share selection will expire after 5 min
};
$(document).ready(function(){
gigya.services.socialize.addEventHandlers(conf,{
onLogin:onLoginHandler,
onLogout:onLogoutHandler
});
gigya.services.socialize.showLoginUI(conf,{
showTermsLink:'false',
height:150,
width:250,
containerID:'register-component-div',
UIConfig:'',
enabledProviders:'facebook, twitter, google',
forceAuthentication : 'true',
facepilePosition: 'none',
autoDetectUserProviders: '',
buttonsStyle:'signInWith'
});
gigya.services.socialize.showLoginUI(conf,{
showTermsLink:'false',
height:150,
width:250,
containerID:'login-component-div',
UIConfig:'',
enabledProviders:'facebook, twitter, google',
facepilePosition: 'none',
autoDetectUserProviders: '',
buttonsStyle:'signInWith'
})
});
//onLogout Event handler
function onLogoutHandler(eventObj) {
// Site Logout - update site DB and UI
$("#logout-link").trigger('click');
}
function onLoginHandler(eventObj) {
try {
var form_data = {
userData: $.toJSON(eventObj)
};
$.ajax({
type: "POST",
url: "/gigya/updateSocialProfile.gigya",
data: form_data,
dataType: "json",
statusCode: {
404: function () {
alert("Unable to connect to the server");
},
500: function () {
alert("Unable to serve request due to a server error");
}
},
success: function(response) {
switch(response.responseCode) {
case 0:
window.location.reload();
break;
case 6: // social login failure
alert("Gigya Login error. Please try again...");
break;
case 7:
var user = response.socialuser;
$("#gigya-regbox").dialog("close");
$("#gigya-loginbox").dialog("close");
$("#gigya-link-account-form .email").val(user.email);
$("#gigya-link-account-form .suid").val(user.suid);
$("#gigya-link-account").dialog("open");
break;
case 9: // Email is missing. The registration is pending. The user must supply his email as a condition for the registration completion.
var user = response.socialuser;
if (EVS.gigyaLoginFormCaller !== 'commentLogin') {
$("#completeregistration-form .email").val(user.email);
if (user.email !== "") {
$("#completeregistration-form .email").attr('readonly',true);
}
$("#completeregistration-form .firstname").val(user.firstname);
$("#completeregistration-form .lastname").val(user.lastname);
$("#completeregistration-form .username").val(user.username);
$("#completeregistration-form .postcode").val(user.postcode);
$("#completeregistration-form .mobile").val(user.mobile);
$("#completeregistration-form .gender").val(user.gender);
$("#completeregistration-form .yearofbirth").val(user.yearofbirth);
$("#completeregistration-form .country").val(user.country);
$("#completeregistration-form .suid").val(user.suid);
$("#gigya-regbox").dialog("close");
$("#gigya-loginbox").dialog("close");
$("#gigya-completeregistrationbox").dialog("open");
} else {
$("#lightregistration-form .email").val(user.email);
if (user.email !== "") {
$("#lightregistration-form .email").attr('readonly',true);
}
$("#lightregistration-form .firstname").val(user.firstname);
$("#lightregistration-form .lastname").val(user.lastname);
$("#lightregistration-form .username").val(user.username);
$("#lightregistration-form .suid").val(user.suid);
$("#gigya-regbox").dialog("close");
$("#gigya-loginbox").dialog("close");
$("#gigya-lightregistrationbox").dialog("open");
}
break;
case 11:
var user = response.socialuser;
if (EVS.gigyaLoginFormCaller !== 'commentLogin') {
$("#completeregistration-form .email").val(user.email);
if (user.email !== "") {
$("#completeregistration-form .email").attr('readonly',true);
}
$("#completeregistration-form .firstname").val(user.firstname);
$("#completeregistration-form .lastname").val(user.lastname);
$("#completeregistration-form .username").val(user.username);
$("#completeregistration-form .postcode").val(user.postcode);
$("#completeregistration-form .mobile").val(user.mobile);
$("#completeregistration-form .gender").val(user.gender);
$("#completeregistration-form .yearofbirth").val(user.yearofbirth);
$("#completeregistration-form .country").val(user.country);
$("#completeregistration-form .suid").val(user.suid);
$("#gigya-regbox").dialog("close");
$("#gigya-loginbox").dialog("close");
$("#gigya-completeregistrationbox").dialog("open");
} else {
$("#lightregistration-form .email").val(user.email);
if (user.email !== "") {
$("#lightregistration-form .email").attr('readonly',true);
}
$("#lightregistration-form .firstname").val(user.firstname);
$("#lightregistration-form .lastname").val(user.lastname);
$("#lightregistration-form .username").val(user.username);
$("#lightregistration-form .suid").val(user.suid);
$("#gigya-regbox").dialog("close");
$("#gigya-loginbox").dialog("close");
$("#gigya-lightregistrationbox").dialog("open");
}
break;
default:
alert("default, Login error ");
}
}
});
pUserObject = eventObj;
} catch(e){
alert("Error encountered: "+e);
}
}