diff -r c7c424e9eed5 -r 537d330ad7f0 client/app/app.js --- a/client/app/app.js Wed May 27 19:02:43 2015 +0200 +++ b/client/app/app.js Wed May 27 19:03:08 2015 +0200 @@ -1,8 +1,19 @@ (function(){ 'use strict'; - angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoMyvisit', 'ammicoBooks', 'ammicoVisites', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'ammicoModels', 'templates' ]) - .config(function($routeProvider) { + angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoMyvisit', 'ammicoBooks', 'ammicoVisites', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'ammicoCommon', 'templates' ]) + .config(function($routeProvider, $httpProvider) { + $httpProvider.interceptors.push(function($q, $location) { + return { + responseError: function(rejection) { + if (rejection.status == 401) { + localStorage.removeItem('token'); + } + return $q.reject(rejection); + } + }; + }); + $routeProvider. when('/', { controller: 'homeCtrl', @@ -16,7 +27,8 @@ }). when('/books', { controller: 'booksCtrl', - templateUrl: 'books/books.html' + templateUrl: 'books/books.html', + authRequired: true }). when('/books/:idBook', { controller: 'bookCtrl', @@ -62,11 +74,11 @@ redirectTo: '/' }); }) - .run( function($rootScope, $location, $window, $http) { + .run( function($rootScope, $location, $window, $http, authApi) { $rootScope.globals = {}; - if ($window.sessionStorage.token) { + if (localStorage.getItem('token')) { $rootScope.globals.userLogged = true; - $http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token; + $http.defaults.headers.common.Authorization = 'Token ' + localStorage.getItem('token'); } $rootScope.$on( '$routeChangeStart', function(event, next) { if (next.authRequired && !$rootScope.globals.userLogged) { @@ -74,57 +86,4 @@ } }); }) - .service('searchApi', function($resource, context) { - this.searchResource = function(params){ - return $resource(context.urls.searchUrl, - { - callback: 'JSON_CALLBACK' - }, - { - getJsonp: { - method: 'JSONP', - params: params, - isArray: false, - transformResponse: function(data){ - // Transform meta list into meta dict - var nb = data.hits.length; - for(var i=0;i