client/app/app.js
changeset 114 e4ffc4e13a8e
parent 100 537d330ad7f0
child 172 ffdfe491869c
equal deleted inserted replaced
113:b8400d8efac8 114:e4ffc4e13a8e
    72         }).
    72         }).
    73         otherwise({
    73         otherwise({
    74             redirectTo: '/'
    74             redirectTo: '/'
    75         });
    75         });
    76     })
    76     })
    77     .run( function($rootScope, $location, $window, $http, authApi) {
    77     .run( function($rootScope, $location, $window, $http, authApi, context) {
    78         $rootScope.globals = {};
    78         $rootScope.globals = {};
    79         if (localStorage.getItem('token')) {
    79         if (localStorage.getItem('token') || context['token']) {
    80             $rootScope.globals.userLogged = true;
    80             $rootScope.globals.userLogged = true;
    81             $http.defaults.headers.common.Authorization = 'Token ' + localStorage.getItem('token');
    81             localStorage.setItem('token', (localStorage.getItem('token') || context['token']));
       
    82             $http.defaults.headers.common.Authorization = 'Token ' + (localStorage.getItem('token') || context['token']);
    82         }
    83         }
    83         $rootScope.$on( '$routeChangeStart', function(event, next) {
    84         $rootScope.$on( '$routeChangeStart', function(event, next) {
    84             if (next.authRequired && !$rootScope.globals.userLogged) {
    85             if (next.authRequired && !$rootScope.globals.userLogged) {
    85                 $location.path( '/auth/login' );
    86                 $location.path( '/auth/login' );
    86             }
    87             }