From 148a2f6df4ba6cff2c54ee884c47ef059ae923b9 Mon Sep 17 00:00:00 2001 From: Philippe Vienne Date: Sun, 17 Apr 2016 20:54:06 +0200 Subject: [PATCH] Popup Login --- app.js | 11 ++--------- public/script.js | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 4cb22b7..434b9c0 100644 --- a/app.js +++ b/app.js @@ -91,16 +91,9 @@ app.get('/callback', function (req, res) { refresh_token = body.refresh_token; // we can also pass the token to the browser to make requests from there - res.redirect('/#' + - querystring.stringify({ - access_token: access_token, - refresh_token: refresh_token - })); + res.send('') } else { - res.redirect('/#' + - querystring.stringify({ - error: 'invalid_token' - })); + res.send('') } }); } diff --git a/public/script.js b/public/script.js index c8e3f9a..b4662bc 100644 --- a/public/script.js +++ b/public/script.js @@ -58,11 +58,24 @@ }]); - app.controller('AuthCtrl',['$scope', '$rootScope', function($scope, $rootScope){ + app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', function($scope, $rootScope, $interval){ $scope.login = function(){ var openUrl = '/login'; window.$windowScope = $scope; - window.open(openUrl, "Authenticate Account", "width=500, height=500"); + $scope.popup = window.open(openUrl, "Authenticate Account", "width=500, height=500"); + var checker = $interval(function(){ + if($scope.popup.closed){ + $interval.cancel(checker); + } else if ($scope.popup.token != undefined && $scope.popup.token != null) { + $rootScope.access_token = $scope.popup.token.access_token; + $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); }; $scope.refresh = function(){ var openUrl = '/refresh_token';