From 887919cd3393de520949f852a1bc33df766ca0ab Mon Sep 17 00:00:00 2001 From: Aleksandar Dukleski Date: Thu, 5 Jun 2014 16:59:52 +0200 Subject: [PATCH] If the user is authenticated, proceed to login and fill the calendar list --- controllers.js | 18 ++++++++++++++++++ example.html | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/controllers.js b/controllers.js index ee6a84e..534ff78 100644 --- a/controllers.js +++ b/controllers.js @@ -7,6 +7,24 @@ angular.module('demo', ["googleApi"]) }) .controller('DemoCtrl', ['$scope', 'googleLogin', 'googleCalendar', 'googlePlus', function ($scope, googleLogin, googleCalendar, googlePlus) { + $scope.authenticated = false; + + $scope.$on("google:authenticated", function(){ + $scope.authenticated = true; + $scope.$on('googleCalendar:loaded', function(){ + $scope.calendars = googleCalendar.listCalendars(); + $scope.$apply(); + }); + }); + + function checkAuth() { + setTimeout(function(){ + gapi.auth === undefined ? checkAuth() : googleLogin.checkAuth(); + }, 20); + } + checkAuth(); + + $scope.login = function () { googleLogin.login(); }; diff --git a/example.html b/example.html index af7f5a1..23efdf1 100644 --- a/example.html +++ b/example.html @@ -8,16 +8,16 @@
- - - - + + + +
-
+

You're authenticated!

Logged in as {{currentUser.displayName}}