| author | rougeronj |
| Thu, 11 Jun 2015 16:23:34 +0200 | |
| changeset 174 | fd166770bcee |
| parent 172 | ffdfe491869c |
| child 176 | a8231241f50d |
| permissions | -rw-r--r-- |
| 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) { |
|
| 172 | 6 |
$httpProvider.interceptors.push(function($q) { |
| 100 | 7 |
return { |
8 |
responseError: function(rejection) { |
|
| 172 | 9 |
if (rejection.status === 401) { |
| 100 | 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 |
}) |
|
|
114
e4ffc4e13a8e
add a token field to the initialisation of the ammico app so the server can pass it and auto login with jwt
rougeronj
parents:
100
diff
changeset
|
77 |
.run( function($rootScope, $location, $window, $http, authApi, context) { |
| 91 | 78 |
$rootScope.globals = {}; |
| 172 | 79 |
if (localStorage.getItem('token') || context.token) { |
| 91 | 80 |
$rootScope.globals.userLogged = true; |
| 172 | 81 |
localStorage.setItem('token', (localStorage.getItem('token') || context.token)); |
82 |
$http.defaults.headers.common.Authorization = 'Token ' + (localStorage.getItem('token') || context.token); |
|
| 91 | 83 |
} |
84 |
$rootScope.$on( '$routeChangeStart', function(event, next) { |
|
85 |
if (next.authRequired && !$rootScope.globals.userLogged) { |
|
86 |
$location.path( '/auth/login' ); |
|
87 |
} |
|
88 |
}); |
|
| 172 | 89 |
}); |
| 0 | 90 |
})(); |