| 23343 |
ashik.ali |
1 |
var googleProfile;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
$(document).ajaxComplete(
|
|
|
5 |
function(){
|
|
|
6 |
}
|
|
|
7 |
);
|
|
|
8 |
var startApp = function() {
|
|
|
9 |
gapi.load('auth2', function(){
|
|
|
10 |
// Retrieve the singleton for the GoogleAuth library and set up the client.
|
|
|
11 |
auth2 = gapi.auth2.init({
|
|
|
12 |
client_id: googleApiKey,
|
|
|
13 |
cookiepolicy: 'single_host_origin',
|
|
|
14 |
// Request scopes in addition to 'profile' and 'email'
|
|
|
15 |
//scope: 'additional_scope'
|
|
|
16 |
});
|
|
|
17 |
attachSignin(document.getElementById('customBtn'));
|
|
|
18 |
});
|
|
|
19 |
};
|
|
|
20 |
|
|
|
21 |
function attachSignin(element) {
|
|
|
22 |
console.log(element.id);
|
|
|
23 |
auth2.attachClickHandler(element, {},
|
|
|
24 |
function(googleUser) {
|
|
|
25 |
googleProfile = googleUser.getBasicProfile();
|
|
|
26 |
console.log(googleProfile.getImageUrl());
|
|
|
27 |
submitUser(googleUser);
|
|
|
28 |
}, function(error) {
|
|
|
29 |
console.log(JSON.stringify(error, undefined, 2));
|
|
|
30 |
});
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
function submitUser(googleUser){
|
|
|
34 |
var params = {
|
|
|
35 |
"token" : googleUser.getAuthResponse().id_token
|
|
|
36 |
};
|
|
|
37 |
//var response = doPostAjaxRequestWithParams(context+"/login", params);
|
|
|
38 |
doAjaxRequestWithParamsHandler(context+"/login", "POST", params, function(response){
|
|
|
39 |
response = JSON.parse(response);
|
|
|
40 |
if(response.status){
|
|
|
41 |
addProfileInLocalDb();
|
|
|
42 |
window.location.href= response.redirectUrl;
|
|
|
43 |
}else{
|
|
|
44 |
alert("Retailer not found, Please login");
|
|
|
45 |
}
|
|
|
46 |
});
|
|
|
47 |
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
function addProfileInLocalDb(){
|
|
|
51 |
var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
|
|
|
52 |
localStorage.setItem("profile",JSON.stringify(profile));
|
|
|
53 |
}
|