diff --git a/refstack-ui/app/app.js b/refstack-ui/app/app.js index db76ea8c..3cc859b2 100644 --- a/refstack-ui/app/app.js +++ b/refstack-ui/app/app.js @@ -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(); } ]); diff --git a/refstack-ui/app/components/profile/profile.html b/refstack-ui/app/components/profile/profile.html index e5223482..3d1e275f 100644 --- a/refstack-ui/app/components/profile/profile.html +++ b/refstack-ui/app/components/profile/profile.html @@ -1,5 +1,5 @@

User profile

- +
@@ -9,27 +9,29 @@
-
-
-
-

User public keys

-
-
- +
+
+
+
+

User public keys

+
+
+ +
-
-
- - - - - - - - -
{{pubKey.format}}{{pubKey.shortKey}}{{pubKey.comment}}
-
+
+ + + + + + + + +
{{pubKey.format}}{{pubKey.shortKey}}{{pubKey.comment}}
+
+
\ No newline at end of file diff --git a/refstack-ui/app/components/profile/profileController.js b/refstack-ui/app/components/profile/profileController.js index f0ba3840..6d3c4105 100644 --- a/refstack-ui/app/components/profile/profileController.js +++ b/refstack-ui/app/components/profile/profileController.js @@ -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); } ]); diff --git a/refstack-ui/app/components/results/results.html b/refstack-ui/app/components/results/results.html index a0f3242b..c4b98bd8 100644 --- a/refstack-ui/app/components/results/results.html +++ b/refstack-ui/app/components/results/results.html @@ -40,7 +40,7 @@
- +
diff --git a/refstack-ui/app/components/results/resultsController.js b/refstack-ui/app/components/results/resultsController.js index 40a08207..e79402a7 100644 --- a/refstack-ui/app/components/results/resultsController.js +++ b/refstack-ui/app/components/results/resultsController.js @@ -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 diff --git a/refstack-ui/tests/unit/AuthSpec.js b/refstack-ui/tests/unit/AuthSpec.js index c02709be..86c9b870 100644 --- a/refstack-ui/tests/unit/AuthSpec.js +++ b/refstack-ui/tests/unit/AuthSpec.js @@ -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('
mock template
'); }); - - 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',