Handle signout properly

RefStack UI should properly handle user signout.
How to check:
Open two RefStack in two browser tabs and signin in both. Then signout in first
tab. Then try to open 'Profile' or 'My Results' in second tab. If everything is
ok you will be redirected to RefStack home tab.

Change-Id: Ifc14ba953b269ce8940f82e61d7f3634682fe0da
This commit is contained in:
sslypushenko 2015-08-28 17:07:50 +03:00
parent 4b29aec3b6
commit 8f8bf6dce3
6 changed files with 57 additions and 47 deletions

View File

@ -53,8 +53,8 @@ refstackApp.config([
* Injections in $rootscope
*/
refstackApp.run(['$http', '$rootScope', '$window', 'refstackApiUrl',
function($http, $rootScope, $window, refstackApiUrl) {
refstackApp.run(['$http', '$rootScope', '$window', '$state', 'refstackApiUrl',
function($http, $rootScope, $window, $state, refstackApiUrl) {
'use strict';
/**
@ -82,15 +82,19 @@ refstackApp.run(['$http', '$rootScope', '$window', 'refstackApiUrl',
* This block tries to authenticate user
*/
var profile_url = refstackApiUrl + '/profile';
$http.get(profile_url, {withCredentials: true}).
success(function(data) {
$rootScope.auth.currentUser = data;
$rootScope.auth.isAuthenticated = true;
}).
error(function() {
$rootScope.auth.currentUser = null;
$rootScope.auth.isAuthenticated = false;
});
$rootScope.auth.doSignCheck = function () {
return $http.get(profile_url, {withCredentials: true}).
success(function (data) {
$rootScope.auth.currentUser = data;
$rootScope.auth.isAuthenticated = true;
}).
error(function () {
$rootScope.auth.currentUser = null;
$rootScope.auth.isAuthenticated = false;
$state.go('home');
});
};
$rootScope.auth.doSignCheck();
}
]);

View File

@ -1,5 +1,5 @@
<h3>User profile</h3>
<div cg-busy="{promise:authRequest,message:'Loading'}"></div>
<div>
<table class="table table-striped table-hover">
<tbody>
@ -9,27 +9,29 @@
</tbody>
</table>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<h4>User public keys</h4>
</div>
<div class="col-md-2 pull-right">
<button type="button" class="btn btn-default btn-sm" ng-click="openImportPubKeyModal()">
<span class="glyphicon glyphicon-plus"></span> Import public key
</button>
<div ng-show="pubkeys">
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<h4>User public keys</h4>
</div>
<div class="col-md-2 pull-right">
<button type="button" class="btn btn-default btn-sm" ng-click="openImportPubKeyModal()">
<span class="glyphicon glyphicon-plus"></span> Import public key
</button>
</div>
</div>
</div>
</div>
<div>
<table class="table table-striped table-hover">
<tbody>
<tr ng-repeat="pubKey in pubkeys" ng-click="openShowPubKeyModal(pubKey)">
<td>{{pubKey.format}}</td>
<td>{{pubKey.shortKey}}</td>
<td>{{pubKey.comment}}</td>
</tr>
</tbody>
</table>
</div>
<div>
<table class="table table-striped table-hover">
<tbody>
<tr ng-repeat="pubKey in pubkeys" ng-click="openShowPubKeyModal(pubKey)">
<td>{{pubKey.format}}</td>
<td>{{pubKey.shortKey}}</td>
<td>{{pubKey.comment}}</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@ -14,9 +14,9 @@ refstackApp.factory('PubKeys',
refstackApp.controller('profileController',
[
'$scope', '$http', 'refstackApiUrl', '$state', 'PubKeys',
'$scope', '$http', 'refstackApiUrl', 'PubKeys',
'$modal', 'raiseAlert',
function($scope, $http, refstackApiUrl, $state,
function($scope, $http, refstackApiUrl,
PubKeys, $modal, raiseAlert) {
'use strict';
@ -67,7 +67,8 @@ refstackApp.controller('profileController',
$scope.showRes = function(pubKey){
raiseAlert('success', '', pubKey.pubkey);
};
$scope.updatePubKeys();
$scope.authRequest = $scope.auth.doSignCheck()
.then($scope.updatePubKeys);
}
]);

View File

@ -40,7 +40,7 @@
</div>
</div>
</div>
<div cg-busy="{promise:authRequest,message:'Loading'}"></div>
<div cg-busy="{promise:resultsRequest,message:'Loading'}"></div>
<div ng-show="data" class="results-table">
<table ng-show="data" class="table table-striped table-hover">

View File

@ -72,8 +72,12 @@ refstackApp.controller('resultsController',
JSON.stringify(error);
});
};
$scope.update();
if ($scope.isUserResults) {
$scope.authRequest = $scope.auth.doSignCheck()
.then($scope.update);
} else {
$scope.update();
}
/**
* This is called when the date filter calendar is opened. It

View File

@ -2,7 +2,7 @@ describe('Auth', function () {
'use strict';
var fakeApiUrl = 'http://foo.bar/v1';
var $window;
var $window, $rootScope, $httpBackend;
beforeEach(function () {
$window = {location: { href: jasmine.createSpy()} };
module(function ($provide) {
@ -10,14 +10,13 @@ describe('Auth', function () {
$provide.value('$window', $window);
});
module('refstackApp');
inject(function (_$httpBackend_, _$rootScope_) {
$httpBackend = _$httpBackend_;
$rootScope = _$rootScope_;
});
$httpBackend.whenGET('/components/home/home.html')
.respond('<div>mock template</div>');
});
var $rootScope, $httpBackend;
beforeEach(inject(function (_$httpBackend_, _$rootScope_) {
$httpBackend = _$httpBackend_;
$rootScope = _$rootScope_;
}));
it('should show signin url for signed user', function () {
$httpBackend.expectGET(fakeApiUrl +
'/profile').respond({'openid': 'foo@bar.com',