'use strict'; angular .module('sloDialectsAdmin') .config(function($routeProvider) { $routeProvider .when("/", { template: "" // list items }) .when("/edit/:id", { template: "" // edit item }) .when("/new/:id", { template: "" // edit item }) .when('/login', { template: '' }) .when('/users', { template: '' }) .when('/user', { template: '' }) .when('/password', { template: '' }) .otherwise('/login'); }) .run(['$rootScope', '$location', '$cookieStore', '$http', function ($rootScope, $location, $cookieStore, $http) { // keep user logged in after page refresh $rootScope.globals = $cookieStore.get('globals') || {}; if ($rootScope.globals.currentUser) { $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line } $rootScope.$on('$locationChangeStart', function (event, next, current) { // redirect to login page if not logged in if ($location.path() !== '/login' && !$rootScope.globals.currentUser) { $location.path('/login'); } }); }]);