From 156f06bc200aa2b98813db2efd02962a187e8af6 Mon Sep 17 00:00:00 2001 From: Philippe Vienne Date: Sun, 17 Apr 2016 21:19:01 +0200 Subject: [PATCH] Refresh the token --- public/index.html | 4 ++-- public/script.js | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/public/index.html b/public/index.html index 34cf236..309bd75 100644 --- a/public/index.html +++ b/public/index.html @@ -28,10 +28,10 @@ diff --git a/public/script.js b/public/script.js index b4662bc..8b195b7 100644 --- a/public/script.js +++ b/public/script.js @@ -58,7 +58,7 @@ }]); - app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', function($scope, $rootScope, $interval){ + app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', '$http', function($scope, $rootScope, $interval, $http){ $scope.login = function(){ var openUrl = '/login'; window.$windowScope = $scope; @@ -71,16 +71,20 @@ $rootScope.refresh_token = $scope.popup.token.refresh_token; $scope.popup.close(); $interval.cancel(checker); - } else if ($scope.popup.token == null){ - $scope.popup.close(); - $interval.cancel(checker); } }, 500); + return false; }; $scope.refresh = function(){ - var openUrl = '/refresh_token'; - window.$windowScope = $scope; - window.open(openUrl, "Authenticate Account", "width=500, height=500"); + if($rootScope.refresh_token) + $http.get('/refresh_token',{params: {refresh_token: $rootScope.refresh_token}}) + .then(function(result){ + $rootScope.access_token = result.data.access_token || ""; + }, function(failResult){ + $rootScope.access_token = ""; + $rootScope.refresh_token = ""; + }); + return false; } }])