- Handle the case when the user is not logged in on the oath form

- Have the sign in form properly redirect back to the current page for GitHub login
This commit is contained in:
Joseph Schorr 2014-03-19 14:27:33 -04:00
parent 8ac67e3061
commit 8f3b87c866
2 changed files with 33 additions and 8 deletions

View file

@ -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;

View file

@ -5,7 +5,13 @@
{% endblock %}
{% block body_content %}
<div class="container auth-container">
<div class="container" ng-if="user.anonymous">
<div class="col-sm-6 col-sm-offset-3">
<div class="user-setup"></div>
</div>
</div>
<div class="container auth-container" ng-if="!user.anonymous">
<div class="auth-header">
<img src="//www.gravatar.com/avatar/{{ application.organization.gravatar }}?s=48&d=identicon">
<h2><a href="{{ application.url }}" target="_blank">{{ application.name }}</a></h2>