Rev 24383 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
var googleProfile;$(document).ajaxComplete(function(){});var startApp = function() {gapi.load('auth2', function(){// Retrieve the singleton for the GoogleAuth library and set up the client.auth2 = gapi.auth2.init({client_id: googleApiKey,cookiepolicy: 'single_host_origin',// Request scopes in addition to 'profile' and 'email'//scope: 'additional_scope'});attachSignin(document.getElementById('customBtn'));});};function attachSignin(element) {console.log(element.id);auth2.attachClickHandler(element, {},function(googleUser) {googleProfile = googleUser.getBasicProfile();console.log(googleProfile.getImageUrl());submitUser(googleUser);}, function(error) {console.log(JSON.stringify(error, undefined, 2));});}function submitUser(googleUser){var params = {"token" : googleUser.getAuthResponse().id_token};//var response = doPostAjaxRequestWithParams(context+"/login", params);doAjaxRequestWithParamsHandler(context+"/login", "POST", params, function(response){response = JSON.parse(response);if(response.status){addProfileInLocalDb();window.location.href= response.redirectUrl;}else{alert("Retailer not found, Please login");}});}function addProfileInLocalDb(){var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};localStorage.setItem("profile",JSON.stringify(profile));}