-
-
Save robwormald/4be48978d9906160abde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.config(['$stateProvider', '$provide', '$httpProvider', '$tooltipProvider', '$urlRouterProvider', '$locationProvider', function ($stateProvider, $provide, $httpProvider, $tooltipProvider, $urlRouterProvider, $locationProvider){ | |
//$locationProvider.html5Mode(true); | |
delete $httpProvider.defaults.headers.common['X-Requested-With']; | |
$httpProvider.interceptors.push('AuthInterceptor'); | |
$stateProvider | |
.state('applist', { | |
url: '/applist', | |
templateUrl: 'app/partials/appList.html', | |
controller: 'AppList', | |
controllerAs: "vm", | |
authenticate: true, | |
resolve: { | |
validate: ['JWT', '$state', function(JWT, $state){ | |
console.log('applist resolve fired'); | |
//console.log('$state', $state); | |
//var allowed = JWT.getToken(); | |
$state.go('login'); | |
//if(allowed === null){ | |
// //console.log('allowed', allowed); | |
// $state.go('login'); | |
//} | |
}] | |
} | |
}) | |
.state('login', { | |
url: '/login', | |
templateUrl: 'app/partials/login.html', | |
controller: 'Login', | |
controllerAs: "vm" | |
}); | |
$urlRouterProvider.otherwise('applist'); | |
$tooltipProvider.options( {appendToBody: true} ); | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
app.factory('JWT', JWT); | |
function JWT($window, $q){ | |
var store = $window.localStorage; | |
var key = 'AXC_API_Storage.Token'; | |
var service = { | |
getToken: getToken, | |
setToken: setToken | |
}; | |
return service; | |
//function getToken() { | |
// var deferred = $q.defer(); | |
// deferred.resolve(store.getItem(key)); | |
// return deferred.promise; | |
//}; | |
function getToken() { | |
console.log('store.getItem(key)', store.getItem(key)); | |
var token = store.getItem(key); | |
if(token){ | |
return $q.when(token); | |
} | |
return $q.reject('NO_TOKEN_FOUND'); | |
}; | |
function setToken(token) { | |
if(token) { | |
store.setItem(key, token); | |
console.log('token', token); | |
} | |
else { | |
store.removeItem(key); | |
console.log('no token works!'); | |
} | |
}; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment