-
-
Save ackuser/280dfe615fe57fb0938be24959e56e8e to your computer and use it in GitHub Desktop.
Document // source http://jsbin.com/qelerogevi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" ng-app="app" ng-controller="MainController"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<meta name="google-signin-client_id" content="397577174832-p3q2lm8i45jnud4k259qu7du2l0biega.apps.googleusercontent.com"> | |
</head> | |
<body> | |
<button ng-show="!isSignedIn" ng-click="signIn()">Sign in</button> | |
<button ng-show="isSignedIn" ng-click="signOut()">Sign out</button> | |
<script src="https://apis.google.com/js/platform.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.min.js"></script> | |
<script id="jsbin-javascript"> | |
angular.module('app', []) | |
.controller('MainController', ['$scope','googleService', | |
function($scope, googleService) { | |
$scope.isSignedIn = false; | |
googleService.load().then(function(){ | |
$scope.signIn = function(){ | |
googleService.signIn().then(function(){ | |
$scope.isSignedIn = googleService.isSignedIn(); | |
}); | |
}; | |
$scope.signOut = function(){ | |
googleService.signOut().then(function(){ | |
$scope.isSignedIn = googleService.isSignedIn(); | |
}); | |
}; | |
}); | |
} | |
]) | |
.service('googleService', ['$q', function ($q) { | |
var self = this; | |
this.load = function(){ | |
var deferred = $q.defer(); | |
gapi.load('auth2', function(){ | |
var auth2 = gapi.auth2.init(); | |
//normally I'd just pass resolve and reject, but page keeps crashing (probably gapi bug) | |
auth2.then(function(){ | |
deferred.resolve(); | |
}); | |
addAuth2Functions(auth2); | |
}); | |
return deferred.promise; | |
}; | |
function addAuth2Functions(auth2){ | |
self.signIn = function() { | |
var deferred = $q.defer(); | |
auth2.signIn().then(deferred.resolve, deferred.reject); | |
return deferred.promise; | |
}; | |
self.isSignedIn = function(){ | |
return auth2.isSignedIn.get(); | |
} | |
self.signOut = function(){ | |
var deferred = $q.defer(); | |
auth2.signOut().then(deferred.resolve, deferred.reject); | |
return deferred.promise; | |
}; | |
} | |
}]); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">angular.module('app', []) | |
.controller('MainController', ['$scope','googleService', | |
function($scope, googleService) { | |
$scope.isSignedIn = false; | |
googleService.load().then(function(){ | |
$scope.signIn = function(){ | |
googleService.signIn().then(function(){ | |
$scope.isSignedIn = googleService.isSignedIn(); | |
}); | |
}; | |
$scope.signOut = function(){ | |
googleService.signOut().then(function(){ | |
$scope.isSignedIn = googleService.isSignedIn(); | |
}); | |
}; | |
}); | |
} | |
]) | |
.service('googleService', ['$q', function ($q) { | |
var self = this; | |
this.load = function(){ | |
var deferred = $q.defer(); | |
gapi.load('auth2', function(){ | |
var auth2 = gapi.auth2.init(); | |
//normally I'd just pass resolve and reject, but page keeps crashing (probably gapi bug) | |
auth2.then(function(){ | |
deferred.resolve(); | |
}); | |
addAuth2Functions(auth2); | |
}); | |
return deferred.promise; | |
}; | |
function addAuth2Functions(auth2){ | |
self.signIn = function() { | |
var deferred = $q.defer(); | |
auth2.signIn().then(deferred.resolve, deferred.reject); | |
return deferred.promise; | |
}; | |
self.isSignedIn = function(){ | |
return auth2.isSignedIn.get(); | |
} | |
self.signOut = function(){ | |
var deferred = $q.defer(); | |
auth2.signOut().then(deferred.resolve, deferred.reject); | |
return deferred.promise; | |
}; | |
} | |
}]); | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app', []) | |
.controller('MainController', ['$scope','googleService', | |
function($scope, googleService) { | |
$scope.isSignedIn = false; | |
googleService.load().then(function(){ | |
$scope.signIn = function(){ | |
googleService.signIn().then(function(){ | |
$scope.isSignedIn = googleService.isSignedIn(); | |
}); | |
}; | |
$scope.signOut = function(){ | |
googleService.signOut().then(function(){ | |
$scope.isSignedIn = googleService.isSignedIn(); | |
}); | |
}; | |
}); | |
} | |
]) | |
.service('googleService', ['$q', function ($q) { | |
var self = this; | |
this.load = function(){ | |
var deferred = $q.defer(); | |
gapi.load('auth2', function(){ | |
var auth2 = gapi.auth2.init(); | |
//normally I'd just pass resolve and reject, but page keeps crashing (probably gapi bug) | |
auth2.then(function(){ | |
deferred.resolve(); | |
}); | |
addAuth2Functions(auth2); | |
}); | |
return deferred.promise; | |
}; | |
function addAuth2Functions(auth2){ | |
self.signIn = function() { | |
var deferred = $q.defer(); | |
auth2.signIn().then(deferred.resolve, deferred.reject); | |
return deferred.promise; | |
}; | |
self.isSignedIn = function(){ | |
return auth2.isSignedIn.get(); | |
} | |
self.signOut = function(){ | |
var deferred = $q.defer(); | |
auth2.signOut().then(deferred.resolve, deferred.reject); | |
return deferred.promise; | |
}; | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment