/
template_body.html
46 lines (41 loc) · 1.78 KB
/
template_body.html
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
<div id="top">
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<div id="header-links">
<a href="#" onclick="signOut();">Sign Out</a>
<a href="/need_upload.html">Post your own need</a>
<a href="/index.html">Home</a>
</div>
</div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
var id_token = googleUser.getAuthResponse().id_token;
//console.log("ID Token: " + id_token);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:8080/tokensignin');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// xhr.setRequestHeader('Content-Length', id_token.length + '');
xhr.onload = function() {
//document.getElementById('uid').innerHTML = xhr.responseText;
console.log('sign out ok');
};
xhr.send('id_token=' + id_token);
};
function signOut(){
var auth2 = gapi.auth2.getAuthInstance();
var id_token = auth2.currentUser.get().getBasicProfile().getId();
//var id_token = document.getElementById('uid').value;
auth2.signOut().then(function(){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:8080/tokensignout');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// xhr.setRequestHeader('Content-Length', id_token.length + '');
xhr.onload = function() {
//document.getElementById('uid').innerHTML = xhr.responseText;
console.log('sign out OK!');
};
xhr.send('id_token=' + id_token);
});
}
</script>