BAEL - 1916 (#4705)
* BAEL - 1916 * BAEL - 1916 Added JUnit tests * BAEL-1916 Renamed the project * Renamed the project
This commit is contained in:
committed by
maibin
parent
1f26ae85e7
commit
66b0ce2d03
40
spring-security-angular/client/anguarjs/app.js
Normal file
40
spring-security-angular/client/anguarjs/app.js
Normal file
@@ -0,0 +1,40 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('app', ['ngRoute'])
|
||||
.config(config)
|
||||
.run(run);
|
||||
|
||||
config.$inject = ['$routeProvider', '$locationProvider'];
|
||||
function config($routeProvider, $locationProvider) {
|
||||
$routeProvider
|
||||
.when('/', {
|
||||
controller: 'HomeController',
|
||||
templateUrl: 'home/home.view.html',
|
||||
controllerAs: 'vm'
|
||||
})
|
||||
.when('/login', {
|
||||
controller: 'LoginController',
|
||||
templateUrl: 'login/login.view.html',
|
||||
controllerAs: 'vm'
|
||||
})
|
||||
.otherwise({ redirectTo: '/login' });
|
||||
}
|
||||
|
||||
run.$inject = ['$rootScope', '$location', '$http', '$window'];
|
||||
function run($rootScope, $location, $http, $window) {
|
||||
var userData = $window.sessionStorage.getItem('userData');
|
||||
if (userData) {
|
||||
$http.defaults.headers.common['Authorization'] = 'Basic ' + JSON.parse(userData).authData;
|
||||
}
|
||||
|
||||
$rootScope.$on('$locationChangeStart', function (event, next, current) {
|
||||
var restrictedPage = $.inArray($location.path(), ['/login']) === -1;
|
||||
var loggedIn = $window.sessionStorage.getItem('userData');;
|
||||
if (restrictedPage && !loggedIn) {
|
||||
$location.path('/login');
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user