Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit df889c9

Browse files
committed
CAS example using http-auth-interceptor
1 parent 27eae71 commit df889c9

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

app/app.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
// Declare app level module which depends on views, and components
44
angular.module('myApp', [
55
'ngRoute',
6+
'http-auth-interceptor',
67
'myApp.view1',
78
'myApp.view2',
89
'myApp.logout',
910
'myApp.version'
1011
]).
1112
config(['$routeProvider', function($routeProvider) {
1213
$routeProvider.otherwise({redirectTo: '/view1'});
13-
}]);
14+
}]).run(function ($rootScope, $window) {
15+
16+
// Call when the 401 response is returned by the server
17+
$rootScope.$on('event:auth-loginRequired', function(rejection) {
18+
$window.alert("Session timeout, will restart...");
19+
$window.location.reload();
20+
});
21+
22+
});
23+

app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
-->
3535
<script src="bower_components/angular/angular.js"></script>
3636
<script src="bower_components/angular-route/angular-route.js"></script>
37+
<script src="bower_components/angular-http-auth/src/http-auth-interceptor.js"></script>
3738
<script src="app.js"></script>
3839
<script src="view1/view1.js"></script>
3940
<script src="view2/view2.js"></script>

app/view1/view1.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
<div ng-if="user">
21
<p>User id: {{user.id}}</p>
3-
</div>
4-
5-
<div ng-if="!user">
6-
Session timeout! Please <a href="index.php">re-start application</a>
7-
</div>

app/view1/view1.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ angular.module('myApp.view1', ['ngRoute'])
99
});
1010
}])
1111

12-
.controller('View1Ctrl', function($http, $scope, $window) {
12+
.controller('View1Ctrl', function($http, $scope) {
1313
$http.get('backend/user.php').success(function (user) {
1414
$scope.user = user;
1515
});
16-
17-
$scope.restart = function() {
18-
$window.location.reload();
19-
}
2016
});

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"angular-route": "1.2.x",
1111
"angular-loader": "1.2.x",
1212
"angular-mocks": "~1.2.x",
13+
"angular-http-auth": "1.2.x",
1314
"html5-boilerplate": "~4.3.0"
1415
}
1516
}

0 commit comments

Comments
 (0)