|
0
|
1 |
(function(){ |
|
91
|
2 |
'use strict'; |
|
0
|
3 |
|
|
100
|
4 |
angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoMyvisit', 'ammicoBooks', 'ammicoVisites', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'ammicoCommon', 'templates' ]) |
|
|
5 |
.config(function($routeProvider, $httpProvider) { |
|
|
6 |
$httpProvider.interceptors.push(function($q, $location) { |
|
|
7 |
return { |
|
|
8 |
responseError: function(rejection) { |
|
|
9 |
if (rejection.status == 401) { |
|
|
10 |
localStorage.removeItem('token'); |
|
|
11 |
} |
|
|
12 |
return $q.reject(rejection); |
|
|
13 |
} |
|
|
14 |
}; |
|
|
15 |
}); |
|
|
16 |
|
|
91
|
17 |
$routeProvider. |
|
|
18 |
when('/', { |
|
|
19 |
controller: 'homeCtrl', |
|
|
20 |
templateUrl: 'home/home.html', |
|
|
21 |
authRequired: false |
|
|
22 |
}). |
|
|
23 |
when('/my_visit', { |
|
|
24 |
controller: 'my_visitCtrl', |
|
|
25 |
templateUrl: 'my_visit/my_visit.html', |
|
|
26 |
authRequired: true |
|
|
27 |
}). |
|
|
28 |
when('/books', { |
|
|
29 |
controller: 'booksCtrl', |
|
100
|
30 |
templateUrl: 'books/books.html', |
|
|
31 |
authRequired: true |
|
91
|
32 |
}). |
|
|
33 |
when('/books/:idBook', { |
|
|
34 |
controller: 'bookCtrl', |
|
|
35 |
templateUrl: 'books/book.html', |
|
|
36 |
authRequired: true |
|
|
37 |
}). |
|
|
38 |
when('/visites', { |
|
|
39 |
controller: 'visitesCtrl', |
|
|
40 |
templateUrl: 'visites/visites.html', |
|
|
41 |
authRequired: true |
|
|
42 |
}). |
|
|
43 |
when('/visites/:idVisit', { |
|
|
44 |
controller: 'visiteCtrl', |
|
|
45 |
templateUrl: 'visites/visite.html', |
|
|
46 |
authRequired: true |
|
|
47 |
}). |
|
|
48 |
when('/slide/:idSlide', { |
|
|
49 |
controller: 'slidesCtrl', |
|
|
50 |
templateUrl: 'slides/slides.html', |
|
|
51 |
authRequired: true |
|
|
52 |
}). |
|
|
53 |
when('/slideshow/', { |
|
|
54 |
controller: 'slideshowCtrl', |
|
|
55 |
templateUrl: 'slideshow/slideshow.html', |
|
|
56 |
authRequired: true |
|
|
57 |
}). |
|
|
58 |
when('/slideshow/:iSlide', { |
|
|
59 |
controller: 'slideshowCtrl', |
|
|
60 |
templateUrl: 'slideshow/slideshow.html', |
|
|
61 |
authRequired: true |
|
|
62 |
}). |
|
|
63 |
when('/search/:q', { |
|
|
64 |
controller: 'searchCtrl', |
|
|
65 |
templateUrl: 'search/search.html', |
|
|
66 |
authRequired: true |
|
|
67 |
}). |
|
|
68 |
when('/auth/:action', { |
|
|
69 |
controller: 'authCtrl', |
|
|
70 |
templateUrl: 'home/home.html', |
|
|
71 |
authRequired: false |
|
|
72 |
}). |
|
|
73 |
otherwise({ |
|
|
74 |
redirectTo: '/' |
|
|
75 |
}); |
|
|
76 |
}) |
|
100
|
77 |
.run( function($rootScope, $location, $window, $http, authApi) { |
|
91
|
78 |
$rootScope.globals = {}; |
|
100
|
79 |
if (localStorage.getItem('token')) { |
|
91
|
80 |
$rootScope.globals.userLogged = true; |
|
100
|
81 |
$http.defaults.headers.common.Authorization = 'Token ' + localStorage.getItem('token'); |
|
91
|
82 |
} |
|
|
83 |
$rootScope.$on( '$routeChangeStart', function(event, next) { |
|
|
84 |
if (next.authRequired && !$rootScope.globals.userLogged) { |
|
|
85 |
$location.path( '/auth/login' ); |
|
|
86 |
} |
|
|
87 |
}); |
|
|
88 |
}) |
|
0
|
89 |
})(); |