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:
parent
4b29aec3b6
commit
8f8bf6dce3
@ -53,8 +53,8 @@ refstackApp.config([
|
|||||||
* Injections in $rootscope
|
* Injections in $rootscope
|
||||||
*/
|
*/
|
||||||
|
|
||||||
refstackApp.run(['$http', '$rootScope', '$window', 'refstackApiUrl',
|
refstackApp.run(['$http', '$rootScope', '$window', '$state', 'refstackApiUrl',
|
||||||
function($http, $rootScope, $window, refstackApiUrl) {
|
function($http, $rootScope, $window, $state, refstackApiUrl) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +82,8 @@ refstackApp.run(['$http', '$rootScope', '$window', 'refstackApiUrl',
|
|||||||
* This block tries to authenticate user
|
* This block tries to authenticate user
|
||||||
*/
|
*/
|
||||||
var profile_url = refstackApiUrl + '/profile';
|
var profile_url = refstackApiUrl + '/profile';
|
||||||
$http.get(profile_url, {withCredentials: true}).
|
$rootScope.auth.doSignCheck = function () {
|
||||||
|
return $http.get(profile_url, {withCredentials: true}).
|
||||||
success(function (data) {
|
success(function (data) {
|
||||||
$rootScope.auth.currentUser = data;
|
$rootScope.auth.currentUser = data;
|
||||||
$rootScope.auth.isAuthenticated = true;
|
$rootScope.auth.isAuthenticated = true;
|
||||||
@ -90,7 +91,10 @@ refstackApp.run(['$http', '$rootScope', '$window', 'refstackApiUrl',
|
|||||||
error(function () {
|
error(function () {
|
||||||
$rootScope.auth.currentUser = null;
|
$rootScope.auth.currentUser = null;
|
||||||
$rootScope.auth.isAuthenticated = false;
|
$rootScope.auth.isAuthenticated = false;
|
||||||
|
$state.go('home');
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
$rootScope.auth.doSignCheck();
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<h3>User profile</h3>
|
<h3>User profile</h3>
|
||||||
|
<div cg-busy="{promise:authRequest,message:'Loading'}"></div>
|
||||||
<div>
|
<div>
|
||||||
<table class="table table-striped table-hover">
|
<table class="table table-striped table-hover">
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -9,6 +9,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div ng-show="pubkeys">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
@ -33,3 +34,4 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
@ -14,9 +14,9 @@ refstackApp.factory('PubKeys',
|
|||||||
|
|
||||||
refstackApp.controller('profileController',
|
refstackApp.controller('profileController',
|
||||||
[
|
[
|
||||||
'$scope', '$http', 'refstackApiUrl', '$state', 'PubKeys',
|
'$scope', '$http', 'refstackApiUrl', 'PubKeys',
|
||||||
'$modal', 'raiseAlert',
|
'$modal', 'raiseAlert',
|
||||||
function($scope, $http, refstackApiUrl, $state,
|
function($scope, $http, refstackApiUrl,
|
||||||
PubKeys, $modal, raiseAlert) {
|
PubKeys, $modal, raiseAlert) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -67,7 +67,8 @@ refstackApp.controller('profileController',
|
|||||||
$scope.showRes = function(pubKey){
|
$scope.showRes = function(pubKey){
|
||||||
raiseAlert('success', '', pubKey.pubkey);
|
raiseAlert('success', '', pubKey.pubkey);
|
||||||
};
|
};
|
||||||
$scope.updatePubKeys();
|
$scope.authRequest = $scope.auth.doSignCheck()
|
||||||
|
.then($scope.updatePubKeys);
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div cg-busy="{promise:authRequest,message:'Loading'}"></div>
|
||||||
<div cg-busy="{promise:resultsRequest,message:'Loading'}"></div>
|
<div cg-busy="{promise:resultsRequest,message:'Loading'}"></div>
|
||||||
<div ng-show="data" class="results-table">
|
<div ng-show="data" class="results-table">
|
||||||
<table ng-show="data" class="table table-striped table-hover">
|
<table ng-show="data" class="table table-striped table-hover">
|
||||||
|
@ -72,8 +72,12 @@ refstackApp.controller('resultsController',
|
|||||||
JSON.stringify(error);
|
JSON.stringify(error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
if ($scope.isUserResults) {
|
||||||
|
$scope.authRequest = $scope.auth.doSignCheck()
|
||||||
|
.then($scope.update);
|
||||||
|
} else {
|
||||||
$scope.update();
|
$scope.update();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called when the date filter calendar is opened. It
|
* This is called when the date filter calendar is opened. It
|
||||||
|
@ -2,7 +2,7 @@ describe('Auth', function () {
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fakeApiUrl = 'http://foo.bar/v1';
|
var fakeApiUrl = 'http://foo.bar/v1';
|
||||||
var $window;
|
var $window, $rootScope, $httpBackend;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$window = {location: { href: jasmine.createSpy()} };
|
$window = {location: { href: jasmine.createSpy()} };
|
||||||
module(function ($provide) {
|
module(function ($provide) {
|
||||||
@ -10,14 +10,13 @@ describe('Auth', function () {
|
|||||||
$provide.value('$window', $window);
|
$provide.value('$window', $window);
|
||||||
});
|
});
|
||||||
module('refstackApp');
|
module('refstackApp');
|
||||||
});
|
inject(function (_$httpBackend_, _$rootScope_) {
|
||||||
|
|
||||||
var $rootScope, $httpBackend;
|
|
||||||
beforeEach(inject(function (_$httpBackend_, _$rootScope_) {
|
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$rootScope = _$rootScope_;
|
$rootScope = _$rootScope_;
|
||||||
}));
|
});
|
||||||
|
$httpBackend.whenGET('/components/home/home.html')
|
||||||
|
.respond('<div>mock template</div>');
|
||||||
|
});
|
||||||
it('should show signin url for signed user', function () {
|
it('should show signin url for signed user', function () {
|
||||||
$httpBackend.expectGET(fakeApiUrl +
|
$httpBackend.expectGET(fakeApiUrl +
|
||||||
'/profile').respond({'openid': 'foo@bar.com',
|
'/profile').respond({'openid': 'foo@bar.com',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user