diff --git a/static/js/app.js b/static/js/app.js index 3f29b2f73..33c0dca94 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -353,7 +353,8 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu return cookieService; }]); - $provide.factory('UserService', ['ApiService', 'CookieService', function(ApiService, CookieService) { + $provide.factory('UserService', ['ApiService', 'CookieService', '$rootScope', + function(ApiService, CookieService, $rootScope) { var userResponse = { verified: false, anonymous: true, @@ -457,6 +458,9 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu return userResponse; }; + // Update the user in the root scope. + userService.updateUserIn($rootScope); + // Load the user the first time. userService.load(); @@ -536,7 +540,7 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu planService.handleNotedPlan = function() { var planId = planService.getAndResetNotedPlan(); - if (!planId) { return; } + if (!planId) { return false; } UserService.load(function() { if (UserService.currentUser().anonymous) { @@ -551,6 +555,8 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu } }); }); + + return true; }; planService.getAndResetNotedPlan = function() { @@ -1121,7 +1127,7 @@ quayApp.directive('signinForm', function () { 'signInStarted': '&signInStarted', 'signedIn': '&signedIn' }, - controller: function($scope, $location, $timeout, ApiService, KeyService, UserService) { + controller: function($scope, $location, $timeout, ApiService, KeyService, UserService, CookieService) { $scope.showGithub = function() { $scope.markStarted(); @@ -1130,6 +1136,10 @@ quayApp.directive('signinForm', function () { $scope.mixpanelDistinctIdClause = "&state=" + encodeURIComponent(mixpanel.get_distinct_id()); } + // Save the redirect URL in a cookie so that we can redirect back after GitHub returns to us. + var redirectURL = $scope.redirectUrl || window.location.toString(); + CookieService.putPermanent('quay.redirectAfterLoad', redirectURL); + // Needed to ensure that UI work done by the started callback is finished before the location // changes. $timeout(function() { @@ -1162,7 +1172,7 @@ quayApp.directive('signinForm', function () { // Note: The timeout of 500ms is needed to ensure dialogs containing sign in // forms get removed before the location changes. $timeout(function() { - if ($scope.redirectUrl == $location.path()) { + if (!$scope.redirectUrl || $scope.redirectUrl == $location.path()) { return; } $location.path($scope.redirectUrl ? $scope.redirectUrl : '/'); @@ -3569,8 +3579,8 @@ quayApp.directive('ngVisible', function () { }; }); -quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanService', '$http', '$timeout', - function($location, $rootScope, Restangular, UserService, PlanService, $http, $timeout) { +quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanService', '$http', '$timeout', 'CookieService', + function($location, $rootScope, Restangular, UserService, PlanService, $http, $timeout, CookieService) { // Handle session security. Restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'], {'_csrf_token': window.__token || ''}); @@ -3588,7 +3598,16 @@ quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanServi }); // Check if we need to redirect based on a previously chosen plan. - PlanService.handleNotedPlan(); + var result = PlanService.handleNotedPlan(); + + // Check to see if we need to show a redirection page. + var redirectUrl = CookieService.get('quay.redirectAfterLoad'); + CookieService.clear('quay.redirectAfterLoad'); + + if (!result && redirectUrl && redirectUrl.indexOf(window.location.href) == 0) { + window.location = redirectUrl; + return; + } var changeTab = function(activeTab, opt_timeout) { var checkCount = 0; diff --git a/templates/oauthorize.html b/templates/oauthorize.html index ca97324c5..1346bd297 100644 --- a/templates/oauthorize.html +++ b/templates/oauthorize.html @@ -5,7 +5,13 @@ {% endblock %} {% block body_content %} -