Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 35 additions & 40 deletions Lesson3/step3/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
<html>
<head>

<!--LOAD PRE-REQUISITES FOR GOOGLE SIGN IN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
<!-- BEGIN Pre-requisites -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
</script>

<script src="//apis.google.com/js/platform.js?onload=start"> </script>

<!-- END PRE-REQUISITES FOR GOOGLE SIGN IN -->
<script>
function start() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'CLIENT ID',
// Scopes to request in addition to 'profile' and 'email'
//scope: 'additional_scope'
});
});
}
</script>

<!-- END Pre-requisites -->

</head>


<body>


<!-- GOOGLE PLUS SIGN IN-->


<div id="signinButton">
<span class="g-signin"
data-scope="openid email"
data-clientid="13140951618-15nik769cellkubaqnjk5facdib2dh4d.apps.googleusercontent.com"
data-redirecturi="postmessage"
data-accesstype="offline"
data-cookiepolicy="single_host_origin"
data-callback="signInCallback"
data-approvalprompt="force">
</span>
</div>
<button id="signinButton">Sign in with Google</button>
<script>
$('#signinButton').click(function() {
auth2.grantOfflineAccess().then(signInCallback);
});
</script>

<div id="result"></div>


<script>
function signInCallback(authResult) {
if (authResult['code']) {

// Hide the sign-in button now that the user is authorized
$('#signinButton').attr('style', 'display: none');

// Send the one-time-use code to the server, if the server responds, write a 'login successful' message to the web page and then redirect back to the main restaurants page
$.ajax({
type: 'POST',
Expand All @@ -49,27 +50,21 @@
success: function(result) {
// Handle or verify the server response if necessary.
if (result) {
$('#result').html('Login Successful!</br>'+ result + '</br>Redirecting...');
setTimeout(function() {
window.location.href = "/restaurant";
}, 4000);
} else if (authResult['error']) {
console.log('There was an error: ' + authResult['error']);
} else {
$('#result').html('Failed to make a server-side call. Check your configuration and console.');
}
},
error: function(result) {
console.log('There was an error: ' + result);
$('#result').html('Login Successful!</br>'+ result + '</br>Redirecting...')
setTimeout(function() {
window.location.href = "/restaurant";
}, 4000);

} else if (authResult['error']) {
console.log('There was an error: ' + authResult['error']);
} else {
$('#result').html('Failed to make a server-side call. Check your configuration and console.');
}
}

}); } }
</script>



<!--END GOOGLE PLUS SIGN IN -->

</body>

</html>
</html>